🐛 The extend_lock job spams the hell out of your logs #18
-
Bug DescriptionI want to use django-crontask, but the fact that I get these two logs every 5 seconds is infuriating. How do I make it stop? Also that name has a typo. Should start with "crontask", not "contask". That's defined on line 73 in the management command. Expected BehaviorNot getting my logs spammed with useless junk every 5 seconds. Version1.1.1 Stack traceNo response Steps to ReproduceNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
|
Hi @coredumperror 👋, Thank you for reaching out. Based on the information, the provided logger in question seems to be But fear not, Python has a built-in solution for that. You can configure how any logger is handled. In Django you can do this via the LOGGING setting. You'd need to set up something like this: # settings.py
LOGGING = {
"version": 1,
# other things like handlers
"loggers": {
"": {"handlers": ["console"], "level": "INFO"},
"apscheduler.executors.default": {"handlers": ["console"], "level": "WARNING"},
},
}Note how the level is increased to warning, therefore dropping all info logs. I hope this helps. Please let me know if you need any assistance. Best PS: Please be mindful of our code of conduct. I try to carefully respond to all questions in my spare time. You seem to be a native speaker (unlike me), and I am sure you can find ways to formulate your questions with a little more appreciation for open-source software. |
Beta Was this translation helpful? Give feedback.
-
|
Apologies for the harsh tone of my original issue post. I was dealing with a lot of frustrating stuff last Friday. Thanks for the idea of using the python logging config to quiet this down. That'll be much better than the hacky monkey patch I came up with. I'll share what I ultimately come up with here, in case it might be helpful to others. |
Beta Was this translation helpful? Give feedback.
-
|
OK, here's what I put into my Django def ignore_spammy_task_logs(record):
"""
Silences log messages for certain especially spammy tasks.
"""
# NOTE: If you need to debug this function by adding print statements, you MUST
# use print("message", flush=True), or your prints will never appear.
spammy_task_messages = [
# These get emitted every 5 seconds due to an implementation detail in django-crontask.
"crontask.utils.lock.extend",
# This hides all but the ﮩ٨ـﮩﮩ٨ـ♡ﮩ٨ـﮩﮩ٨ـ log from our custom heartbeat task.
"heartbeat_task",
]
return not any(message in record.getMessage() for message in spammy_task_messages)
LOGGING = {
...
"filters": {
"ignore_spammy_task_logs": {
"()": "django.utils.log.CallbackFilter",
"callback": ignore_spammy_task_logs,
},
...
},
...
"handlers": {
"structlog_console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "stdout",
"filters": ["ignore_spammy_task_logs"],
},
...
}
...
"root": {
# Set up the root logger to use our console handler.
"handlers": ["structlog_console"],
"level": "INFO",
},
"formatters": {
# This formatter writes human-readable logs using structlog.
"stdout": {
"()": structlog.stdlib.ProcessorFormatter,
"processor": structlog.dev.ConsoleRenderer(pad_level=False)
},
...
}
}
|
Beta Was this translation helpful? Give feedback.
OK, here's what I put into my Django
settings.pyto efficiently silence these spammy logs: