Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add region and instance id to logger #142

Merged
merged 7 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.21
0.2.22
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config :supavisor, SupavisorWeb.Endpoint,
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:request_id, :project, :user]
metadata: [:request_id, :project, :user, :region, :instance_id]

# Use Jason for JSON parsing in Phoenix
config :phoenix, :json_library, Jason
Expand Down
11 changes: 11 additions & 0 deletions lib/supavisor/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ defmodule Supavisor.Application do

@impl true
def start(_type, _args) do
primary_config = :logger.get_primary_config()

:ok =
:logger.set_primary_config(
:metadata,
Enum.into(
[region: System.get_env("REGION"), instance_id: System.get_env("INSTANCE_ID")],
primary_config.metadata
)
)

:ok =
:gen_event.swap_sup_handler(
:erl_signal_server,
Expand Down
2 changes: 1 addition & 1 deletion test/supavisor/client_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Supavisor.ClientHandlerTest do
test "username consists only of username" do
username = "username"
{user, nil} = ClientHandler.parse_user_info(username)
assert username == "username"
assert username == user
end
end
end
Loading