Skip to content

Commit

Permalink
Use recommended dictConfig for logging configuration (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
glatterf42 authored Apr 19, 2024
1 parent 6895401 commit 1a9c05d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*jpg
*pdf
*zip
*json

# Apple file system
*.DS_STORE
Expand Down
30 changes: 0 additions & 30 deletions pyam/logging.conf

This file was deleted.

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

5 changes: 4 additions & 1 deletion pyam/logging.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import warnings
from contextlib import contextmanager
from logging import config, getLogger
Expand All @@ -11,7 +12,9 @@

def configure_logging():
"""Configure logging"""
config.fileConfig(here / "logging.conf", disable_existing_loggers=False)
logging_config = here / "logging.json"
with open(logging_config) as file:
config.dictConfig(json.load(file))


@contextmanager
Expand Down

0 comments on commit 1a9c05d

Please sign in to comment.