diff --git a/config/dev.exs b/config/dev.exs index 3e6e61f0..84a86de7 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -26,5 +26,3 @@ config :phoenix, :stacktrace_depth, 20 # Initialize plugs at runtime for faster development compilation config :phoenix, :plug_init_mode, :runtime - -config :logger, level: :info diff --git a/config/prod.exs b/config/prod.exs index 1499af52..3e571170 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -4,9 +4,6 @@ import Config # to something meaningful, Phoenix uses this information # when generating URLs. -# Do not print debug messages in production -config :logger, level: :info - config :fishjam, ip: {127, 0, 0, 1}, port: 8080 diff --git a/config/runtime.exs b/config/runtime.exs index 5608f942..00178356 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -13,6 +13,8 @@ config :ex_dtls, impl: :nif structured_logging? = ConfigReader.read_boolean("FJ_STRUCTURED_LOGGING") || false config :logger, backends: [if(structured_logging?, do: LoggerJSON, else: :console)] +config :logger, level: ConfigReader.read_logger_level() + prod? = config_env() == :prod ip = ConfigReader.read_ip("FJ_IP") || Application.fetch_env!(:fishjam, :ip) diff --git a/lib/jellyfish/component/hls/manager.ex b/lib/jellyfish/component/hls/manager.ex index f56f2ccf..06a000d5 100644 --- a/lib/jellyfish/component/hls/manager.ex +++ b/lib/jellyfish/component/hls/manager.ex @@ -75,7 +75,8 @@ defmodule Fishjam.Component.HLS.Manager do end) broadcast_notification(result, room_id) - Logger.info("Finished uploading to s3 with result: #{result}, room: #{room_id}") + + Logger.info("Finished uploading to s3 with result: #{inspect(result)}, room: #{room_id}") end defp upload_file_to_s3(content, s3_path, opts, config, credentials) do diff --git a/lib/jellyfish/config_reader.ex b/lib/jellyfish/config_reader.ex index f4a23671..07b5e519 100644 --- a/lib/jellyfish/config_reader.ex +++ b/lib/jellyfish/config_reader.ex @@ -250,6 +250,23 @@ defmodule Fishjam.ConfigReader do get_env(string, default) end + def read_logger_level() do + log_level = get_env("FJ_LOG_LEVEL", "info") + + log_levels_string = ["info", "debug", "warning", "error"] + + if log_level in log_levels_string do + String.to_existing_atom(log_level) + else + Logger.warning(""" + Provided unknown level of logs: #{log_level}. Valid values are #{Enum.join(log_levels_string, ", ")}. + Set value to default - info. + """) + + :info + end + end + defp do_read_nodes_list_config(node_name_value, cookie, mode) do nodes_value = get_env("FJ_DIST_NODES", "") diff --git a/test/jellyfish/config_reader_test.exs b/test/jellyfish/config_reader_test.exs index 4c94e254..aab6ac63 100644 --- a/test/jellyfish/config_reader_test.exs +++ b/test/jellyfish/config_reader_test.exs @@ -352,4 +352,21 @@ defmodule Fishjam.ConfigReaderTest do assert_raise RuntimeError, fn -> ConfigReader.read_dist_config() end end end + + test "read_logger_level/0" do + with_env ["FJ_LOG_LEVEL"] do + env_value_to_log_level = %{ + "info" => :info, + "debug" => :debug, + "warning" => :warning, + "error" => :error, + "other_env_value" => :info + } + + for {env_value, log_level} <- env_value_to_log_level do + System.put_env("FJ_LOG_LEVEL", env_value) + assert ConfigReader.read_logger_level() == log_level + end + end + end end