diff --git a/.gitignore b/.gitignore index 7aa68143..53f806b1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ result* *screenshot.png output todo +log/ diff --git a/panel/default.nix b/panel/default.nix index 06d1a487..6c214660 100644 --- a/panel/default.nix +++ b/panel/default.nix @@ -31,6 +31,7 @@ in DATABASE_URL = "sqlite:///${toString ./src}/db.sqlite3"; # locally: use a fixed relative reference, so we can use our newest files without copying to the store REPO_DIR = toString ../.; + LOGGING_DIR = "../log"; }; shellHook = '' ln -sf ${sources.htmx}/dist/htmx.js src/panel/static/htmx.min.js diff --git a/panel/nix/configuration.nix b/panel/nix/configuration.nix index 6061e559..4cc4e9ea 100644 --- a/panel/nix/configuration.nix +++ b/panel/nix/configuration.nix @@ -30,6 +30,7 @@ let (builtins.toFile "extra-settings.py" cfg.extra-settings) ]; REPO_DIR = import ../../launch/tf-env.nix { inherit lib pkgs; }; + LOGGING_DIR = "/var/log/${name}"; SSH_PRIVATE_KEY_FILE = config.age.secrets.panel-ssh-key.path; }; diff --git a/panel/src/panel/settings.py b/panel/src/panel/settings.py index 27398b47..52761d60 100644 --- a/panel/src/panel/settings.py +++ b/panel/src/panel/settings.py @@ -176,6 +176,9 @@ COMPRESS_PRECOMPILERS = [ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' +logging_dir = env["LOGGING_DIR"] +os.makedirs(logging_dir, mode=0o700, exist_ok=True) + LOGGING = { "version": 1, "disable_existing_loggers": False, @@ -214,10 +217,15 @@ LOGGING = { "filters": ["require_debug_false"], "class": "django.utils.log.AdminEmailHandler", }, + "file": { + "level": "INFO", + "class": "logging.FileHandler", + "filename": f"{logging_dir}/info.log", + }, }, "loggers": { "": { - "handlers": ["console"], + "handlers": ["console", "file"], "level": "DEBUG" if DEBUG else "INFO", }, },