Skip to content

Commit

Permalink
Created a CustomLogfmtEx to aprse root and bits metadate and be able …
Browse files Browse the repository at this point in the history
…to adde the root to the logs
  • Loading branch information
rodrigo-o committed Sep 27, 2024
1 parent b186d5a commit 386c39d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,9 @@ case Keyword.get(args, :log_file) do
config :logger, utc_log: true

config :logger, :default_formatter,
format: {LogfmtEx, :format},
format: {CustomLogfmtEx, :format},
colors: [enabled: false],
metadata: [:mfa, :pid, :slot]
metadata: [:mfa, :pid, :slot, :root]

config :logfmt_ex, :opts,
message_key: "msg",
Expand Down
19 changes: 19 additions & 0 deletions lib/lambda_ethereum_consensus/logger/custom_logfmt_ex.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule CustomLogfmtEx do
@moduledoc """
Custom logger formatter for logfmt output.
"""

alias LambdaEthereumConsensus.Utils

def format(level, message, timestamp, metadata) do
formatted_metadata = format_metadata(metadata)

LogfmtEx.format(level, message, timestamp, formatted_metadata)
end

defp format_metadata(metadata) do
metadata
|> Keyword.replace_lazy(:root, &Utils.format_shorten_binary(&1))
|> Keyword.replace_lazy(:bits, &Utils.format_bitstring(&1))
end
end
2 changes: 2 additions & 0 deletions metrics/promtail/promtail.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ scrape_configs:
process: registered_name
pid:
slot:
root:
- timestamp:
format: "2006-01-02T15:04:05.000"
source: ts
Expand All @@ -35,5 +36,6 @@ scrape_configs:
process:
pid:
slot:
root:
- output:
source: msg

0 comments on commit 386c39d

Please sign in to comment.