Skip to content

Commit

Permalink
Configure log level (#197)
Browse files Browse the repository at this point in the history
* Fix logger in hls manager

* Add test

* Modify possible log levels

* Changes after review
  • Loading branch information
Rados13 authored May 20, 2024
1 parent 465ae81 commit 64f7e38
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 6 deletions.
2 changes: 0 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/jellyfish/component/hls/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/jellyfish/config_reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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", "")

Expand Down
17 changes: 17 additions & 0 deletions test/jellyfish/config_reader_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 64f7e38

Please sign in to comment.