Skip to content

Commit

Permalink
restructured logging
Browse files Browse the repository at this point in the history
  • Loading branch information
P-T-I committed Oct 31, 2023
1 parent 6cbe624 commit 00e805e
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CveXplore/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.3.9
0.3.11
6 changes: 3 additions & 3 deletions CveXplore/api/nvd_nist/nvd_nist_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(

self.config = Configuration()

self.logger = logging.getLogger("NvdNistApi")
self.logger = logging.getLogger(__name__)

if self.config.NVD_NIST_API_KEY is not None:
self.api_key = self.config.NVD_NIST_API_KEY
Expand Down Expand Up @@ -264,7 +264,7 @@ def retry_policy(info: RetryInfo) -> RetryPolicyStrategy:
"""
max_retries = 5
backoff_in_ms = 0.2 * 2**info.fails + random.uniform(0, 1) * 4
logger = logging.getLogger("RetryPolicy")
logger = logging.getLogger(__name__)

if info.fails != max_retries:
logger.debug(f"Current backoff: {backoff_in_ms}")
Expand All @@ -279,7 +279,7 @@ def retry_policy(info: RetryInfo) -> RetryPolicyStrategy:

class ApiDataIterator(object):
def __init__(self, api_data: ApiData):
self.logger = logging.getLogger("ApiDataIterator")
self.logger = logging.getLogger(__name__)

self._page_length = api_data.results_per_page
self._total_results = api_data.total_results
Expand Down
2 changes: 1 addition & 1 deletion CveXplore/database/helpers/generic_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _field_list(self, doc_id: str) -> list:
)
)

def field_list(self, *doc_ids: str) -> list | dict:
def field_list(self, *doc_ids: str) -> list:
"""
Method to fetch all field names from a specific collection
"""
Expand Down
2 changes: 1 addition & 1 deletion CveXplore/database/maintenance/DatabaseSchemaChecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self):

self.dbh = database._dbclient["schema"]

self.logger = logging.getLogger("SchemaChecker")
self.logger = logging.getLogger(__name__)

def validate_schema(self):
try:
Expand Down
2 changes: 1 addition & 1 deletion CveXplore/database/maintenance/DownloadHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, feed_type: str, prefix: str = None):

self.database = database._dbclient

self.logger = logging.getLogger("DownloadHandler")
self.logger = logging.getLogger(__name__)

self.config = Configuration()

Expand Down
2 changes: 1 addition & 1 deletion CveXplore/database/maintenance/IJSONHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class IJSONHandler(object):
def __init__(self):
self.logger = logging.getLogger("IJSONHandler")
self.logger = logging.getLogger(__name__)

def fetch(self, filename: str, prefix: str):
x = 0
Expand Down
9 changes: 8 additions & 1 deletion CveXplore/database/maintenance/LogHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class HelperLogger(logging.Logger):

logDict = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"sysLogFormatter": {
"format": "%(asctime)s - %(name)-8s - %(levelname)-8s - %(message)s"
Expand All @@ -46,7 +47,13 @@ class HelperLogger(logging.Logger):
"formatter": "simpleFormatter",
}
},
"root": {"level": "DEBUG", "handlers": ["consoleHandler"]},
"loggers": {
"CveXplore": {
"handlers": ["consoleHandler"],
"level": "DEBUG",
"propagate": True,
},
},
}

dictConfig(logDict)
Expand Down
12 changes: 6 additions & 6 deletions CveXplore/database/maintenance/Sources_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(self):

super().__init__(self.feed_type)

self.logger = logging.getLogger("CPEDownloads")
self.logger = logging.getLogger(__name__)

def file_to_queue(self, *args):
pass
Expand Down Expand Up @@ -251,7 +251,7 @@ def __init__(self):

super().__init__(self.feed_type)

self.logger = logging.getLogger("CVEDownloads")
self.logger = logging.getLogger(__name__)

@staticmethod
def get_cve_year_range():
Expand Down Expand Up @@ -892,7 +892,7 @@ def __init__(self):

self.feed_url = Configuration.getFeedURL(self.feed_type.lower())

self.logger = logging.getLogger("VIADownloads")
self.logger = logging.getLogger(__name__)

def file_to_queue(self, file_tuple: Tuple[str, str]):
working_dir, filename = file_tuple
Expand Down Expand Up @@ -976,7 +976,7 @@ def __init__(self):

self.feed_url = Configuration.getFeedURL(self.feed_type.lower())

self.logger = logging.getLogger("CAPECDownloads")
self.logger = logging.getLogger(__name__)

# make parser
self.parser = make_parser()
Expand Down Expand Up @@ -1037,7 +1037,7 @@ def __init__(self):

self.feed_url = Configuration.getFeedURL(self.feed_type.lower())

self.logger = logging.getLogger("CWEDownloads")
self.logger = logging.getLogger(__name__)

# make parser
self.parser = make_parser()
Expand Down Expand Up @@ -1159,7 +1159,7 @@ def __init__(self):
],
}

self.logger = logging.getLogger("DatabaseIndexer")
self.logger = logging.getLogger(__name__)

def getInfo(self, collection: str):
return sanitize(self.database["info"].find_one({"db": collection}))
Expand Down
4 changes: 2 additions & 2 deletions CveXplore/database/maintenance/main_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class MainUpdater(object):
"""
The MainUpdater class is the main class for performing database maintenaince tasks
The MainUpdater class is the main class for performing database maintenance tasks
"""

def __init__(self, datasource):
Expand All @@ -47,7 +47,7 @@ def __init__(self, datasource):

self.schema_checker = SchemaChecker()

self.logger = logging.getLogger("MainUpdater")
self.logger = logging.getLogger(__name__)

def validate_schema(self):
return self.schema_checker.validate_schema()
Expand Down

0 comments on commit 00e805e

Please sign in to comment.