Skip to content

Commit

Permalink
Add logging
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Dec 25, 2019
1 parent b6cb429 commit d734d5c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/matyan/fetchers/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

from atlassian import Jira

from ..logger import LOGGER
from .base import BaseFetcher

LOGGER = logging.getLogger(__name__)

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later'
Expand All @@ -31,7 +30,7 @@ def get_instance(self) -> Jira:

def fetch_issue_data(self, issue_id: str) -> Dict[str, str]:
if not self.should_continue():
LOGGER.debug("Skip after number of retries reached")
LOGGER.error("Skip after number of retries reached")
return {}

try:
Expand All @@ -42,4 +41,5 @@ def fetch_issue_data(self, issue_id: str) -> Dict[str, str]:
}
except (TypeError, KeyError, IOError) as err:
self.register_error()
LOGGER.exception(f"Problems getting the issue {issue_id}")
return {}
68 changes: 68 additions & 0 deletions src/matyan/logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import json
import os
from logging import config, getLogger

from .helpers import project_dir

__author__ = 'Artur Barseghyan'
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later'
__all__ = (
'LOGGER',
)

DEFAULT_LOGGING_CONFIG = {
'version': 1,
'disable_existing_loggers': False,
'root': {
'level': 'WARNING',
'handlers': ['file'],
},
'formatters': {
'verbose': {
'format': '{levelname} {asctime} {module} {process:d} {thread:d} '
'{message}',
'style': '{',
},
'simple': {
'format': '{levelname} {message}',
'style': '{',
},
},
'handlers': {
'console': {
'level': 'WARNING',
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'file': {
'level': 'WARNING',
'class': 'logging.handlers.RotatingFileHandler',
'filename': project_dir("matyan.log"),
'maxBytes': 1048576,
'backupCount': 99,
'formatter': 'verbose',
},
},
'loggers': {
'matyan': {
'handlers': ['file'],
'propagate': True,
},
}
}

LOGGING_CONFIG_STR = os.environ.get('MATYAN_LOGGING_CONFIG', "")

if LOGGING_CONFIG_STR:
try:
config_dict = json.loads(LOGGING_CONFIG_STR)
except Exception:
config_dict = DEFAULT_LOGGING_CONFIG
else:
config_dict = DEFAULT_LOGGING_CONFIG


config.dictConfig(config_dict)

LOGGER = getLogger(__name__)
6 changes: 3 additions & 3 deletions src/matyan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
REGEX_PATTERN_MERGED_BRANCH_NAME,
REGEX_PATTERN_TAG,
)
from .logger import LOGGER

LOGGER = logging.getLogger(__name__)
DEBUG = os.environ.get('DEBUG', False)

__author__ = 'Artur Barseghyan'
Expand Down Expand Up @@ -235,7 +235,7 @@ def prepare_changelog(
settings.get('fetchDataFrom')
and settings.get('fetchDataFrom') not in FetcherRegistry.REGISTRY
):
LOGGER.debug(
LOGGER.warning(
f"settings.get('fetchDataFrom') is not found in the registry!"
)

Expand Down Expand Up @@ -466,7 +466,7 @@ def prepare_releases_changelog(
settings.get('fetchDataFrom')
and settings.get('fetchDataFrom') not in FetcherRegistry.REGISTRY
):
LOGGER.debug(
LOGGER.warning(
f"settings.get('fetchDataFrom') is not found in the registry!"
)

Expand Down

0 comments on commit d734d5c

Please sign in to comment.