Skip to content

Commit

Permalink
new: per-feeder logging config
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Sep 12, 2023
1 parent c437b43 commit e487c91
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vulnerabilitylookup/feeders/advisory-database
9 changes: 9 additions & 0 deletions vulnerabilitylookup/feeders/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class GithubAdvisoryDatabase():
def __init__(self):
self._load_logging_config()
self.logger = logging.getLogger(f'{self.__class__.__name__}')
self.config = get_config_feeder('gad')

Expand All @@ -33,6 +34,14 @@ def __init__(self):
self.path_to_repo = get_homedir() / 'vulnerabilitylookup' / 'feeders' / 'advisory-database'
self.gad_git = Repo(self.path_to_repo)

def _load_logging_config(self):
cur_path = Path(__file__)
if not (cur_path.parent / f'{cur_path.stem}_logging.json').exists():
return
with (cur_path.parent / f'{cur_path.stem}_logging.json').open() as f:
log_config = json.load(f)
logging.config.dictConfig(log_config)

def gad_update(self) -> bool:

self.gad_git.remotes.origin.pull('main')
Expand Down
33 changes: 33 additions & 0 deletions vulnerabilitylookup/feeders/github_logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s %(name)s %(levelname)s:%(message)s"
}
},
"handlers": {
"stdout": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "WARNING",
"formatter": "simple",
"filename": "logs/github_warning.log",
"mode": "a",
"maxBytes": 1000000,
"backupCount": 5
}
},
"root": {
"level": "DEBUG",
"handlers": [
"stdout",
"file"
]
}
}
2 changes: 1 addition & 1 deletion vulnerabilitylookup/feeders/gsd-database
Submodule gsd-database updated 1818 files
10 changes: 10 additions & 0 deletions vulnerabilitylookup/feeders/gsd.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import logging
import logging.config

from datetime import datetime
from pathlib import Path
Expand All @@ -14,6 +15,7 @@

class GSD():
def __init__(self):
self._load_logging_config()
self.logger = logging.getLogger(f'{self.__class__.__name__}')
self.config = get_config_feeder('gsd')

Expand All @@ -31,6 +33,14 @@ def __init__(self):
self.path_to_repo = get_homedir() / 'vulnerabilitylookup' / 'feeders' / 'gsd-database'
self.gsd_git = Repo(self.path_to_repo)

def _load_logging_config(self):
cur_path = Path(__file__)
if not (cur_path.parent / f'{cur_path.stem}_logging.json').exists():
return
with (cur_path.parent / f'{cur_path.stem}_logging.json').open() as f:
log_config = json.load(f)
logging.config.dictConfig(log_config)

def gsd_update(self) -> bool:

self.gsd_git.remotes.origin.pull('main')
Expand Down
33 changes: 33 additions & 0 deletions vulnerabilitylookup/feeders/gsd_logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s %(name)s %(levelname)s:%(message)s"
}
},
"handlers": {
"stdout": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "WARNING",
"formatter": "simple",
"filename": "logs/gsd_warning.log",
"mode": "a",
"maxBytes": 1000000,
"backupCount": 5
}
},
"root": {
"level": "DEBUG",
"handlers": [
"stdout",
"file"
]
}
}
10 changes: 10 additions & 0 deletions vulnerabilitylookup/feeders/nvd_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import requests

from datetime import datetime, timedelta
from pathlib import Path
from redis import Redis
from typing import Optional, Dict, Union

Expand All @@ -12,6 +13,7 @@

class NVDFetcher():
def __init__(self):
self._load_logging_config()
self.logger = logging.getLogger(f'{self.__class__.__name__}')
self.config = get_config_feeder('nvd')
if 'apikey' in self.config:
Expand All @@ -29,6 +31,14 @@ def __init__(self):

self.url_api = "https://services.nvd.nist.gov/rest/json/cves/2.0/?"

def _load_logging_config(self):
cur_path = Path(__file__)
if not (cur_path.parent / f'{cur_path.stem}_logging.json').exists():
return
with (cur_path.parent / f'{cur_path.stem}_logging.json').open() as f:
log_config = json.load(f)
logging.config.dictConfig(log_config)

def nvd_update(self) -> bool:
query: Dict[str, Union[int, str]]
last_update: Optional[datetime]
Expand Down
33 changes: 33 additions & 0 deletions vulnerabilitylookup/feeders/nvd_fetch_logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"simple": {
"format": "%(asctime)s %(name)s %(levelname)s:%(message)s"
}
},
"handlers": {
"stdout": {
"class": "logging.StreamHandler",
"level": "INFO",
"formatter": "simple",
"stream": "ext://sys.stdout"
},
"file": {
"class": "logging.handlers.RotatingFileHandler",
"level": "WARNING",
"formatter": "simple",
"filename": "logs/nvd_warning.log",
"mode": "a",
"maxBytes": 1000000,
"backupCount": 5
}
},
"root": {
"level": "DEBUG",
"handlers": [
"stdout",
"file"
]
}
}

0 comments on commit e487c91

Please sign in to comment.