Skip to content

Commit 4e5afab

Browse files
authored
feat: enhancing loki logging capture (#1310)
1 parent e10c578 commit 4e5afab

File tree

6 files changed

+42
-5
lines changed

6 files changed

+42
-5
lines changed

Diff for: Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,26 @@ test-iex:
166166
checkpoint-sync: compile-all
167167
iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics
168168

169+
#▶️ checkpoint-sync.logfile: @ Run an interactive terminal using checkpoint sync with a log file.
170+
checkpoint-sync.logfile: compile-all
171+
iex -S mix run -- --checkpoint-sync-url https://mainnet-checkpoint-sync.stakely.io/ --metrics --log-file ./logs/mainnet.log
172+
169173
#▶️ sepolia: @ Run an interactive terminal using sepolia network
170174
sepolia: compile-all
171175
iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics
172176

177+
#▶️ sepolia.logfile: @ Run an interactive terminal using sepolia network with a log file
178+
sepolia.logfile: compile-all
179+
iex -S mix run -- --checkpoint-sync-url https://sepolia.beaconstate.info --network sepolia --metrics --log-file ./logs/sepolia.log
180+
173181
#▶️ holesky: @ Run an interactive terminal using holesky network
174182
holesky: compile-all
175183
iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky
176184

185+
#▶️ holesky.logfile: @ Run an interactive terminal using holesky network with a log file
186+
holesky.logfile: compile-all
187+
iex -S mix run -- --checkpoint-sync-url https://checkpoint-sync.holesky.ethpandaops.io --network holesky --log-file ./logs/holesky.log
188+
177189
#▶️ gnosis: @ Run an interactive terminal using gnosis network
178190
gnosis: compile-all
179191
iex -S mix run -- --checkpoint-sync-url https://checkpoint.gnosischain.com --network gnosis

Diff for: config/runtime.exs

+3-3
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ case Keyword.get(args, :log_file) do
219219
nil ->
220220
# Use custom formatter for prettier logs
221221
config :logger, :default_formatter,
222-
format: {ConsoleLogger, :format},
222+
format: {CustomConsoleLogger, :format},
223223
metadata: [:slot, :root, :bits]
224224

225225
log_file ->
@@ -241,9 +241,9 @@ case Keyword.get(args, :log_file) do
241241
config :logger, utc_log: true
242242

243243
config :logger, :default_formatter,
244-
format: {LogfmtEx, :format},
244+
format: {CustomLogfmtEx, :format},
245245
colors: [enabled: false],
246-
metadata: [:mfa, :slot]
246+
metadata: [:mfa, :pid, :slot, :root]
247247

248248
config :logfmt_ex, :opts,
249249
message_key: "msg",

Diff for: lib/lambda_ethereum_consensus/logger/console_logger.ex renamed to lib/lambda_ethereum_consensus/logger/custom_console_logger.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
defmodule ConsoleLogger do
1+
defmodule CustomConsoleLogger do
22
@moduledoc """
33
Custom logger formatter for console output.
44
"""
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule CustomLogfmtEx do
2+
@moduledoc """
3+
Custom logger formatter for logfmt output.
4+
"""
5+
6+
alias LambdaEthereumConsensus.Utils
7+
8+
def format(level, message, timestamp, metadata) do
9+
formatted_metadata = format_metadata(metadata)
10+
11+
LogfmtEx.format(level, message, timestamp, formatted_metadata)
12+
end
13+
14+
defp format_metadata(metadata) do
15+
metadata
16+
|> Keyword.replace_lazy(:root, &Utils.format_shorten_binary(&1))
17+
|> Keyword.replace_lazy(:bits, &Utils.format_bitstring(&1))
18+
end
19+
end

Diff for: metrics/loki/loki.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ schema_config:
3434
period: 24h
3535

3636
ruler:
37-
alertmanager_url: http://localhost:9093
37+
alertmanager_url: http://localhost:9093/alertmanager
3838
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
3939
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
4040
#

Diff for: metrics/promtail/promtail.yml

+6
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,18 @@ scrape_configs:
2424
msg:
2525
mfa:
2626
process: registered_name
27+
pid:
28+
slot:
29+
root:
2730
- timestamp:
2831
format: "2006-01-02T15:04:05.000"
2932
source: ts
3033
- labels:
3134
level:
3235
mfa:
3336
process:
37+
pid:
38+
slot:
39+
root:
3440
- output:
3541
source: msg

0 commit comments

Comments
 (0)