Skip to content

Commit 331ff8e

Browse files
lukebakkenmergify-bot
authored andcommitted
Update some logging timestamps
Uses the same format as the OTP logger Fixes #4276 (cherry picked from commit 455c01f)
1 parent 8acc634 commit 331ff8e

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

deps/rabbitmq_management_agent/src/rabbit_mgmt_format.erl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
-module(rabbit_mgmt_format).
99

1010
-export([format/2, ip/1, ipb/1, amqp_table/1, tuple/1]).
11-
-export([parameter/1, now_to_str/1, now_to_str_ms/1, strip_pids/1]).
11+
-export([parameter/1, now_to_str/0, now_to_str/1, strip_pids/1]).
1212
-export([protocol/1, resource/1, queue/1, queue_state/1, queue_info/1]).
1313
-export([exchange/1, user/1, internal_user/1, binding/1, url/2]).
1414
-export([pack_binding_props/2, tokenise/1]).
@@ -187,20 +187,16 @@ protocol_version({Major, Minor}) -> io_lib:format("~B-~B", [Major, Min
187187
protocol_version({Major, Minor, 0}) -> protocol_version({Major, Minor});
188188
protocol_version({Major, Minor, Revision}) -> io_lib:format("~B-~B-~B",
189189
[Major, Minor, Revision]).
190+
% Note:
191+
% Uses the same format as the OTP logger:
192+
% https://github.com/erlang/otp/blob/82e74303e715c7c64c1998bf034b12a48ce814b1/lib/kernel/src/logger_formatter.erl#L306-L311
193+
now_to_str() ->
194+
calendar:system_time_to_rfc3339(os:system_time(millisecond), [{unit, millisecond}]).
190195

191196
now_to_str(unknown) ->
192197
unknown;
193-
now_to_str(MilliSeconds) ->
194-
BaseDate = calendar:datetime_to_gregorian_seconds({{1970, 1, 1},
195-
{0, 0, 0}}),
196-
Seconds = BaseDate + (MilliSeconds div 1000),
197-
{{Y, M, D}, {H, Min, S}} = calendar:gregorian_seconds_to_datetime(Seconds),
198-
print("~w-~2.2.0w-~2.2.0w ~w:~2.2.0w:~2.2.0w", [Y, M, D, H, Min, S]).
199-
200-
now_to_str_ms(unknown) ->
201-
unknown;
202-
now_to_str_ms(MilliSeconds) ->
203-
print("~s:~3.3.0w", [now_to_str(MilliSeconds), MilliSeconds rem 1000]).
198+
now_to_str(MilliSeconds) when is_integer(MilliSeconds) ->
199+
calendar:system_time_to_rfc3339(MilliSeconds, [{unit, millisecond}]).
204200

205201
resource(unknown) -> unknown;
206202
resource(Res) -> resource(name, Res).

deps/rabbitmq_tracing/src/rabbit_tracing_consumer.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ delivery_to_log_record({#'basic.deliver'{routing_key = Key},
147147
{longstr, VHost} = table_lookup(H, <<"vhost">>),
148148
{longstr, User} = table_lookup(H, <<"user">>),
149149
{signedint, Chan} = table_lookup(H, <<"channel">>),
150-
#log_record{timestamp = rabbit_mgmt_format:now_to_str_ms(
151-
os:system_time(milli_seconds)),
150+
#log_record{timestamp = rabbit_mgmt_format:now_to_str(),
152151
type = Type,
153152
exchange = X,
154153
queue = Q,

0 commit comments

Comments
 (0)