Skip to content

Commit

Permalink
refactor: avoids repeated current timestamp impl
Browse files Browse the repository at this point in the history
  • Loading branch information
grzuy committed Jul 30, 2024
1 parent f86ee7a commit cd05bfc
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/tower/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule Tower.Event do

def from_exception(exception, stacktrace, log_event_meta) do
%__MODULE__{
time: Map.get(log_event_meta, :time, :logger.timestamp()),
time: Map.get(log_event_meta, :time, now()),
level: :error,
kind: :error,
reason: exception,
Expand All @@ -23,7 +23,7 @@ defmodule Tower.Event do

def from_exit(reason, stacktrace, log_event_meta) do
%__MODULE__{
time: Map.get(log_event_meta, :time, :logger.timestamp()),
time: Map.get(log_event_meta, :time, now()),
level: :error,
kind: :exit,
reason: reason,
Expand All @@ -34,7 +34,7 @@ defmodule Tower.Event do

def from_throw(reason, stacktrace, log_event_meta) do
%__MODULE__{
time: Map.get(log_event_meta, :time, :logger.timestamp()),
time: Map.get(log_event_meta, :time, now()),
level: :error,
kind: :throw,
reason: reason,
Expand All @@ -45,11 +45,15 @@ defmodule Tower.Event do

def from_message(level, message, log_event_meta) do
%__MODULE__{
time: Map.get(log_event_meta, :time, :logger.timestamp()),
time: Map.get(log_event_meta, :time, now()),
level: level,
kind: :message,
reason: message,
log_event_meta: log_event_meta
}
end

defp now do
:logger.timestamp()
end
end

0 comments on commit cd05bfc

Please sign in to comment.