From 610acb15f1bfffb01294232b77f5725c2d1f4498 Mon Sep 17 00:00:00 2001 From: Kieran Date: Wed, 21 Feb 2024 18:01:18 -0800 Subject: [PATCH] Added log rotation for prod config (#32) --- config/runtime.exs | 17 +++++++++++++++++ lib/pinchflat/application.ex | 1 + selfhosted.Dockerfile | 5 ++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 496ca87..4086fc0 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -29,6 +29,8 @@ if config_env() == :prod do For example: /etc/pinchflat/pinchflat.db """ + log_path = System.get_env("LOG_PATH", "log/pinchflat.log") + config :pinchflat, yt_dlp_executable: System.find_executable("yt-dlp") config :pinchflat, Pinchflat.Repo, @@ -74,6 +76,21 @@ if config_env() == :prod do ], secret_key_base: secret_key_base + config :pinchflat, :logger, [ + {:handler, :file_log, :logger_std_h, + %{ + config: %{ + type: :file, + file: String.to_charlist(log_path), + filesync_repeat_interval: 5000, + file_check: 5000, + max_no_files: 5, + max_no_bytes: 10_000_000 + }, + formatter: Logger.Formatter.new() + }} + ] + # ## SSL Support # # To get SSL working, you will need to add the `https` key diff --git a/lib/pinchflat/application.ex b/lib/pinchflat/application.ex index 6846c2f..81ba2f0 100644 --- a/lib/pinchflat/application.ex +++ b/lib/pinchflat/application.ex @@ -22,6 +22,7 @@ defmodule Pinchflat.Application do ] :ok = Oban.Telemetry.attach_default_logger() + Logger.add_handlers(:pinchflat) # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options diff --git a/selfhosted.Dockerfile b/selfhosted.Dockerfile index 1a1508d..ded2309 100644 --- a/selfhosted.Dockerfile +++ b/selfhosted.Dockerfile @@ -96,12 +96,11 @@ RUN chown nobody /app # Set up data volumes RUN mkdir /config /downloads RUN chown nobody /config /downloads -VOLUME /config -VOLUME /downloads # set runner ENV ENV MIX_ENV="prod" -ENV DATABASE_PATH="/config/pinchflat.db" +ENV DATABASE_PATH="/config/db/pinchflat.db" +ENV LOG_PATH="/config/logs/pinchflat.log" ENV PORT=8945 ENV RUN_CONTEXT="selfhosted"