Skip to content

Commit

Permalink
Use logging-config instead of basicConfig (#476)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhuppmann authored Feb 19, 2025
1 parent 37979d6 commit e3541cc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
12 changes: 6 additions & 6 deletions nomenclature/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from importlib.metadata import version
from pathlib import Path

import json
import yaml

from nomenclature.cli import cli # noqa
Expand All @@ -13,12 +13,12 @@
from nomenclature.processor import RegionAggregationMapping # noqa
from nomenclature.processor import RegionProcessor, RequiredDataValidator # noqa


here = Path(__file__).parent

# set up logging
logging.basicConfig(
format="%(asctime)s %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
level=logging.INFO,
)
with open(here / "logging.json") as file:
logging.config.dictConfig(json.load(file))

logger = logging.getLogger(__name__)

Expand Down
25 changes: 25 additions & 0 deletions nomenclature/logging.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"version": 1,
"disable_existing_loggers": false,
"formatters": {
"generic": {
"format": "[%(levelname)s] %(asctime)s - %(name)s: %(message)s",
"datefmt": "%H:%M:%S"
}
},
"loggers": {
"nomenclature": {
"level": "INFO",
"handlers": [
"console"
]
}
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"level": "NOTSET",
"formatter": "generic"
}
}
}

0 comments on commit e3541cc

Please sign in to comment.