Skip to content

Commit

Permalink
add globally region and instance id to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
abc3 committed Jul 31, 2023
1 parent 741a7f9 commit 9868ae0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
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
7 changes: 1 addition & 6 deletions lib/supavisor/client_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,7 @@ defmodule Supavisor.ClientHandler do
Logger.debug("Client startup message: #{inspect(hello)}")
{user, external_id} = parse_user_info(hello.payload["user"])

Logger.metadata(
project: external_id,
user: user,
region: System.get_env("REGION"),
instance_id: System.get_env("INSTANCE_ID")
)
Logger.metadata(project: external_id, user: user)

sni_hostname = try_get_sni(sock)

Expand Down
7 changes: 1 addition & 6 deletions lib/supavisor/db_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,7 @@ defmodule Supavisor.DbHandler do
def init(args) do
Process.flag(:trap_exit, true)

Logger.metadata(
project: args.tenant,
user: args.user_alias,
region: System.get_env("REGION"),
instance_id: System.get_env("INSTANCE_ID")
)
Logger.metadata(project: args.tenant, user: args.user_alias)

data = %{
id: args.id,
Expand Down
7 changes: 1 addition & 6 deletions lib/supavisor/manager.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,7 @@ defmodule Supavisor.Manager do
default_parameter_status: args.default_parameter_status
}

Logger.metadata(
project: args.tenant,
user: args.user_alias,
region: System.get_env("REGION"),
instance_id: System.get_env("INSTANCE_ID")
)
Logger.metadata(project: args.tenant, user: args.user_alias)

Registry.register(Supavisor.Registry.ManagerTables, {args.tenant, args.user_alias}, tid)

Expand Down

0 comments on commit 9868ae0

Please sign in to comment.