Easy Django logging with Loguru
Project description
Django Easy Logging
Easy Django logging with Loguru
Loguru is an exceeding easy way to do logging in Python. django-easy-logging makes it exceedingly easy to use Loguru in Django. Once integrated you can using existings Python logging mechanisms which are then funneled into Loguru or you can use the Loguru logging methods.
Install
pip install django-easy-logging
Usage
In your settings.py
towards the end of the file add:
from dj_easy_log import load_loguru
load_loguru(globals())
In your other files, use Loguru methods for logging.
from loguru import logger
logger.debug("That's it, beautiful and simple logging!")
logger.info("If you're using Python {}, prefer {feature} of course!", 3.6, feature="f-strings")
Note: Any existing logging is funneled into loguru when using the defualt settings. Loguru is used as a sink as outlined in the docs.
Customization
Log Level
The default log level in DEBUG is INFO
. Otherwise the default level is ERROR
.
You can override the log level with the env LOGLEVEL
.
or
pass in a log level into load_loguru
.
Example: load_loguru(globals(), loglevel="WARNING")
Logging Config
The LOGGING
config dict is generated automatically or you can pass in your own. The default is created by generate_loggin_config
Example: load_loguru(globals(), logging_config=MY_LOGGING_CONFIG)
Configuring Loguru
You can pass in a function that configures Loguru.
Example:
def setup_loguru(logger, settings_dict):
if not settings_dict['DEBUG']:
logger.add("django.log", rotation="100 MB")
load_loguru(globals(), configure_func=setup_loguru)
Configuring the Default Format
export LOGURU_FORMAT="<blue>{time:HH:mm:ss}</blue> | <red>{name}:{line}</red> | {level} - {message}"
See the record dict documention for other available formatting options. And see color markups for more info on coloring and markups.
Shameless Plugs
I built this library originally for the NeutronSync Service. So if you would like to support this project please support the service with a subscription to NeutronSync or a donation to the open source libraries.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-easy-logging-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98fecde434797edc44f24ff3cfa4ee5e61fd568201dedc545d3bb7ae3140eda7 |
|
MD5 | cccea25c20b0cdf2baca4da3fc16e1ee |
|
BLAKE2b-256 | 7850c1c09c2316ef85a1c192b2ba891c6d5c562af6803d3d0e595a85f0d5c9e3 |
Hashes for django_easy_logging-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4adb84bd02dfd3d374d7daf00a07ad369c3dc543f08af3749da589ae0c45f6dd |
|
MD5 | 0a8f5afdc62959d16ab7c39fb41daaf3 |
|
BLAKE2b-256 | 2dd30863b9a540379ff362cd96835436bf823dbed972bf1a13e43e7c344b0480 |