-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
I have this config:
# Logging
LOGGING_USE_JSON = values.BooleanValue(True)
LOGGING_DEFAULT_LEVEL = values.Value("INFO")
@property
def LOGGING(self):
return {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"json": {
"()": "dockerflow.logging.JsonLogFormatter",
"logger_name": "buildhub",
},
"verbose": {"format": "%(levelname)s %(asctime)s %(name)s %(message)s"},
},
"handlers": {
"console": {
"level": self.LOGGING_DEFAULT_LEVEL,
"class": "logging.StreamHandler",
"formatter": ("json" if self.LOGGING_USE_JSON else "verbose"),
},
"sentry": {
"level": "ERROR",
"class": (
"raven.contrib.django.raven_compat.handlers" ".SentryHandler"
),
},
"null": {"class": "logging.NullHandler"},
},
"root": {"level": "INFO", "handlers": ["sentry", "console"]},
...When I do:
In [1]: import logging
In [2]: logger = logging.getLogger("myproject")
In [3]: logger.info("Hi!")
{"Timestamp": 1541787363833421056, "Type": "myproject", "Logger": "buildhub", "Hostname": "MacBook-Pro-131.local", "EnvVersion": "2.0", "Severity": 6, "Pid": 68488, "Fields": {"msg": "Hi!"}}
In [4]: logger.info("Hi %s", "peter")
{"Timestamp": 1541787379742094080, "Type": "myproject", "Logger": "buildhub", "Hostname": "MacBook-Pro-131.local", "EnvVersion": "2.0", "Severity": 6, "Pid": 68488, "Fields": {"msg": "Hi peter"}}
In [5]: logger.info("Hi %s", {'name': 'Peter'})
{"Timestamp": 1541787416647823104, "Type": "myproject", "Logger": "buildhub", "Hostname": "MacBook-Pro-131.local", "EnvVersion": "2.0", "Severity": 6, "Pid": 68488, "Fields": {}}Notice that when the param to logger.debug(template, THIS) isn't a string the final "msg" becomes empty ("Fields": {}).
Metadata
Metadata
Assignees
Labels
No labels