From 5ccd804b9bf6b8f8785ab8803dc844ef3c587ce3 Mon Sep 17 00:00:00 2001 From: Kristofers Solo Date: Thu, 12 Sep 2024 15:59:04 +0300 Subject: [PATCH] docs: add django usage example --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index 69ce56f..0aaca43 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - [Description](#description) - [Installation](#installation) - [Usage](#usage) + * [Django](#django) - [Examples](#examples) * [Basic Logging](#basic-logging) * [Error Logging with Exception](#error-logging-with-exception) @@ -66,6 +67,42 @@ logger.error("This is an error message") logger.critical("This is a critical message") ``` +### Django + +In your Django project's `settings.py` file, add the following logging configuration: + +```python +LOGGING = { + "version": 1, + "disable_existing_loggers": False, + "formatters": { + "bunyan": { + "()": BunyanFormatter, + "project_name": "cashflow", + "project_root": BASE_DIR, + }, + }, + "handlers": { + "console": { + "level": "DEBUG", + "class": "logging.StreamHandler", + "formatter": "bunyan", + "stream": "ext://sys.stdout", + }, + "file": { + "level": "DEBUG", + "class": "logging.FileHandler", + "filename": BASE_DIR / "logs" / "django.log", + "formatter": "bunyan", + }, + }, + "root": { + "level": "DEBUG", + "handlers": ["console", "file"], + }, +} +``` + ## Examples ### Basic Logging