diff --git a/.gitignore b/.gitignore index ca87b86..e5070c9 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,6 @@ npm-debug.log # elixir ls .elixir_ls + +# log files +/*.log \ No newline at end of file diff --git a/config/config.exs b/config/config.exs index 92945a5..007e316 100644 --- a/config/config.exs +++ b/config/config.exs @@ -43,9 +43,30 @@ config :tailwind, ] # Configures Elixir's Logger -config :logger, :console, - format: "$time $metadata[$level] $message\n", - metadata: [:request_id] +config :logger, :default_handler, + level: :debug + +config :logger, :default_formatter, + format: "$time $metadata[$level] $message\n" + +config :chiya, :logger, [ + {:handler, :file_log, :logger_std_h, %{ + level: :info, + config: %{ + file: ~c"chiya.log", + filesync_repeat_interval: 5000, + file_check: 5000, + max_no_bytes: 10_000_000, + max_no_files: 5, + compress_on_rotate: true + }, + formatter: Logger.Formatter.new() + }} +] + +# config :logger, :console, +# format: "$time $metadata[$level] $message\n", +# metadata: [:request_id] # Use Jason for JSON parsing in Phoenix config :phoenix, :json_library, Jason diff --git a/config/dev.exs b/config/dev.exs index 3b316d7..401f1d3 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -66,7 +66,9 @@ config :chiya, ChiyaWeb.Endpoint, config :chiya, dev_routes: true # Do not include metadata nor timestamps in development logs -config :logger, :console, format: "[$level] $message\n" +# config :logger, :console, format: "[$level] $message\n" +config :logger, :default_formatter, + format: "[$level] $message\n" # Set a higher stacktrace during development. Avoid configuring such # in production as building large stacktraces may be expensive. diff --git a/config/prod.exs b/config/prod.exs index 467f09b..b10f6b1 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -15,7 +15,9 @@ config :chiya, ChiyaWeb.Endpoint, cache_static_manifest: "priv/static/cache_mani config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Chiya.Finch # Do not print debug messages in production -config :logger, level: :debug +# config :logger, level: :debug +config :logger, :default_handler, + level: :info config :cors_plug, origin: ["app://obsidian.md"], diff --git a/config/test.exs b/config/test.exs index 28fcc40..2408037 100644 --- a/config/test.exs +++ b/config/test.exs @@ -30,7 +30,9 @@ config :chiya, Chiya.Mailer, adapter: Swoosh.Adapters.Test config :swoosh, :api_client, false # Print only warnings and errors during test -config :logger, level: :warning +# config :logger, level: :warning +config :logger, :default_handler, + level: :warning # Initialize plugs at runtime for faster test compilation config :phoenix, :plug_init_mode, :runtime diff --git a/lib/chiya/application.ex b/lib/chiya/application.ex index 13fa5df..e600da2 100644 --- a/lib/chiya/application.ex +++ b/lib/chiya/application.ex @@ -24,6 +24,8 @@ defmodule Chiya.Application do # {Chiya.Worker, arg} ] + Logger.add_handlers(:chiya) + # See https://hexdocs.pm/elixir/Supervisor.html # for other strategies and supported options opts = [strategy: :one_for_one, name: Chiya.Supervisor]