Skip to content
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
30 changes: 16 additions & 14 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ config :supavisor, SupavisorWeb.Endpoint,
pubsub_server: Supavisor.PubSub,
live_view: [signing_salt: "qf3AEZ7n"]

metadata = [
:request_id,
:project,
:user,
:region,
:instance_id,
:mode,
:type,
:app_name,
:peer_ip,
:local,
:proxy
]

# Configures Elixir's Logger
config :logger, :console,
config :logger, :default_formatter,
format: "$time $metadata[$level] $message\n",
metadata: [
:request_id,
:project,
:user,
:region,
:instance_id,
:mode,
:type,
:app_name,
:peer_ip,
:local,
:proxy
]
metadata: metadata

# Use built-in JSON module for JSON parsing
config :phoenix, :json_library, JSON
Expand Down
50 changes: 50 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,56 @@ if config_env() != :test do
]
end

if path = System.get_env("SUPAVISOR_LOG_FILE_PATH") do
config :logger, :default_handler,
config: [
file: to_charlist(path),
file_check: 1000,
max_no_files: 5,
# 8 MiB as a max file size
max_no_bytes: 8 * 1024 * 1024
]
end

if System.get_env("SUPAVISOR_LOG_FORMAT") == "json" do
config :logger, :default_handler,
formatter:
{Supavisor.Logger.LogflareFormatter,
%{
# metadata: metadata,
top_level: [:project],
context: [:nodehost, :instance_id, :location, :region]
}}
end

if path = System.get_env("SUPAVISOR_ACCESS_LOG_FILE_PATH") do
config :supavisor, :logger, [
{:handler, :access_log, :logger_std_h,
%{
level: :error,
formatter:
Logger.Formatter.new(
format: "$dateT$timeZ $metadata[$level] $message\n",
color: false,
metadata: [:peer_ip],
utc_log: true
),
filter_default: :stop,
filters: [
exchange: {&Supavisor.Logger.Filters.filter_client_handler/2, :exchange}
],
config: %{
file: to_charlist(path),
# Keep the file clean on each startup
modes: [:write]
}
}}
]
end

config :logger,
backends: [:console]

if System.get_env("LOGS_ENGINE") == "logflare" do
if !System.get_env("LOGFLARE_API_KEY") or !System.get_env("LOGFLARE_SOURCE_ID") do
raise """
Expand Down
5 changes: 3 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ config :supavisor, Supavisor.Vault,
]

# Print only warnings and errors during test
config :logger, :console,
level: String.to_atom(System.get_env("LOGGER_LEVEL", "none")),
config :logger, :default_handler, level: String.to_atom(System.get_env("LOGGER_LEVEL", "none"))

config :logger, :default_formatter,
metadata: [:error_code, :file, :line, :pid, :project, :user, :mode]

# Initialize plugs at runtime for faster test compilation
Expand Down
3 changes: 3 additions & 0 deletions contrib/fail2ban/filter.d/supavisor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[Definition]
prefregex = peer_ip=<HOST> .*\[error\] <F-CONTENT>.*</F-CONTENT>
failregex = ^ClientHandler: (Exchange error|User not found):
2 changes: 2 additions & 0 deletions lib/supavisor/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ defmodule Supavisor.Application do
Map.merge(primary_config.metadata, global_metadata)
)

:ok = Logger.add_handlers(:supavisor)

:ok =
:gen_event.swap_sup_handler(
:erl_signal_server,
Expand Down
Loading
Loading