Skip to content

Commit 9f91e2d

Browse files
committed
Show timestamps when printing events logs to stdout.
1 parent a0b9e65 commit 9f91e2d

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

backend/apps/automate_logging/src/automate_logging.erl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,26 @@ log_program_error(LogEntry=#user_program_log_entry{ severity=Severity, program_i
153153

154154
-spec log_platform(log_severity(), _, _, _) -> ok.
155155
log_platform(warning, ErrorNS, Error, _StackTrace) ->
156-
io:fwrite("[~p] ~p:~p~n", [warning, ErrorNS, Error]);
156+
io:fwrite("~s [~p] ~p:~p~n", [get_time_string(), warning, ErrorNS, Error]);
157157
log_platform(debug, _ErrorNS, _Error, _StackTrace) ->
158158
ok; %% Ignored for now
159159

160160
log_platform(Severity, ErrorNS, Error, StackTrace) ->
161-
io:fwrite("[~p] ~p:~p || ~p~n", [Severity, ErrorNS, Error, StackTrace]).
161+
io:fwrite("~s [~p] ~p:~p || ~p~n", [get_time_string(), Severity, ErrorNS, Error, StackTrace]).
162162

163163
-spec log_platform(atom(), _) -> ok.
164164
log_platform(Severity, Msg) when is_list(Msg) ->
165-
io:fwrite("[~p] ~s~n", [Severity, binary:list_to_bin(lists:flatten(Msg))]);
165+
io:fwrite("~s [~p] ~s~n", [get_time_string(), Severity, binary:list_to_bin(lists:flatten(Msg))]);
166166
log_platform(Severity, Msg) ->
167-
io:fwrite("[~p] ~p~n", [Severity, Msg]).
167+
io:fwrite("~s [~p] ~p~n", [get_time_string(), Severity, Msg]).
168168

169169
-spec log_api(log_severity(), _, _) -> ok.
170170
log_api(debug, _, _) ->
171171
ok; %% Ignored for now
172172
log_api(Severity, Endpoint, Error) when is_binary(Error) ->
173-
io:fwrite("[~p@~p] ~s~n", [Severity, Endpoint, Error]);
173+
io:fwrite("~s [~p@~p] ~s~n", [get_time_string(), Severity, Endpoint, Error]);
174174
log_api(Severity, Endpoint, Error) ->
175-
io:fwrite("[~p@~p] ~p~n", [Severity, Endpoint, Error]).
175+
io:fwrite("~s [~p@~p] ~p~n", [get_time_string(), Severity, Endpoint, Error]).
176176

177177

178178
%%====================================================================
@@ -196,3 +196,7 @@ get_signal_storage_config() ->
196196

197197
get_timestamp() ->
198198
erlang:system_time(millisecond).
199+
200+
get_time_string() ->
201+
{{Year,Month,Day},{Hour,Min,Sec}} = erlang:localtime(),
202+
io_lib:format("~4..0B/~2..0B/~2..0B ~2..0B:~2..0B:~2..0B", [Year, Month, Day, Hour, Min, Sec]).

0 commit comments

Comments
 (0)