Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging is hard to configure #249

Open
stockh0lm opened this issue Jun 21, 2021 · 0 comments
Open

logging is hard to configure #249

stockh0lm opened this issue Jun 21, 2021 · 0 comments

Comments

@stockh0lm
Copy link

I needed to switch logging to syslog, and added code to do that:

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)s %(module)s P%(process)d T%(thread)d %(message)s'
},
},
'handlers': {
'stdout': {
'class': 'logging.StreamHandler',
'stream': sys.stdout,
'formatter': 'verbose',
},
'sys-logger6': {
'class': 'logging.handlers.SysLogHandler',
"address": ["127.0.0.1", 514],
'facility': "local6",
'formatter': 'verbose',
},
},
'loggers': {
'my-logger': {
'handlers': ['sys-logger6', 'stdout'],
'level': logging.DEBUG,
'propagate': True,
},
}
}

logging.config.dictConfig(LOGGING)
my_logger = logging.getLogger('my-logger')

def _logger(name, level, msg, exc_info=None):
elapsed = time.monotonic() - start_time
hours = int(elapsed // 60)
seconds = elapsed - (hours * 60)
my_logger.log(level, f'{os.getpid()} - {hours:3}:{seconds:06.3f} {name:20} {msg}', exc_info=exc_info)

this could easily be put into a json config file.

is that a desired feature? i could provide a patch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant