Skip to content

Commit

Permalink
Allow json log through console and remove file handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
nas-tabchiche committed Feb 22, 2024
1 parent 1e26bca commit 2805fe8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ export DJANGO_SECRET_KEY=...

# Logging configuration
export LOG_LEVEL=INFO # optional, default value is INFO. Available options: DEBUG, INFO, WARNING, ERROR, CRITICAL
export LOG_OUTPUTS=console # optional, default value is console. Available options: console, json, flat
export JSON_LOG_FILE=logs/json.log # optional, default value is logs/json.log. Path to the JSON log file
export FLAT_LOG_FILE=logs/flat.log # optional, default value is logs/flat.log Path to the flat log file
export LOG_FORMAT=plain # optional, default value is plain. Available options: json, plain
```

3. Choose the tool of your choice, either python-venv or virtualenv. For example:
Expand Down
26 changes: 4 additions & 22 deletions backend/ciso_assistant/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent

LOG_OUTPUTS = os.environ.get("LOG_OUTPUTS", "console").split(",")
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
JSON_LOG_FILE = os.environ.get("JSON_LOG_FILE", "logs/json.log")
FLAT_LOG_FILE = os.environ.get("FLAT_LOG_FILE", "logs/flat.log")
LOG_FORMAT = os.environ.get("LOG_FORMAT", "plain")

CISO_ASSISTANT_URL = os.environ.get("CISO_ASSISTANT_URL", "http://localhost:5173")

Expand All @@ -40,35 +38,19 @@ def set_ciso_assistant_url(_, __, event_dict):
"()": structlog.stdlib.ProcessorFormatter,
"processor": structlog.processors.JSONRenderer(),
},
"plain_console": {
"plain": {
"()": structlog.stdlib.ProcessorFormatter,
"processor": structlog.dev.ConsoleRenderer(),
},
"key_value": {
"()": structlog.stdlib.ProcessorFormatter,
"processor": structlog.processors.KeyValueRenderer(
key_order=["timestamp", "level", "event", "logger"]
),
},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "plain_console",
},
"json": {
"class": "logging.handlers.WatchedFileHandler",
"filename": JSON_LOG_FILE,
"formatter": "json",
},
"flat": {
"class": "logging.handlers.WatchedFileHandler",
"filename": FLAT_LOG_FILE,
"formatter": "key_value",
"formatter": LOG_FORMAT,
},
},
"loggers": {
"": {"handlers": LOG_OUTPUTS, "level": LOG_LEVEL},
"": {"handlers": ["console"], "level": LOG_LEVEL},
},
}

Expand Down

0 comments on commit 2805fe8

Please sign in to comment.