- I want to configure a json logger, and use the logging config file.
- I can achieve the equivalent programmatically (without a config file)
- When I use a config file, I have problems with imported package
jsonlogger
- Note that this is not a duplicate of this
import logging
import logging.config
from pythonjsonlogger import jsonlogger # <----- where should I put this import ?
logging.config.fileConfig("logging.cfg")
logging.info("where is my stuff ?")
And here is my config file:
[loggers]
keys=root
[handlers]
keys=simple
[formatters]
keys=simple
[logger_root]
level=INFO
handlers=simple
[handler_simple]
class=StreamHandler
formatter=simple
[formatter_simple]
format="[ %(asctime)s %(levelname)s ] %(message)s"
datefmt="%d/%m/%y ( %H:%M:%S )"
class=jsonlogger.JsonFormatter # <----- how to let module know this class ?
When I run my program this is the error I get:
Traceback (most recent call last):
File "main.py", line 5, in <module>
logging.config.fileConfig("logging.cfg")
File "/usr/lib/python3.10/logging/config.py", line 72, in fileConfig
formatters = _create_formatters(cp)
File "/usr/lib/python3.10/logging/config.py", line 119, in _create_formatters
c = _resolve(class_name)
File "/usr/lib/python3.10/logging/config.py", line 90, in _resolve
found = __import__(used)
ModuleNotFoundError: No module named 'jsonlogger'