Skip to content

Commit 89c6c59

Browse files
committed
rabbit_logger_std_h: Sync with Erlang/OTP 26.1.2
[Why] `rabbit_logger_std_h` is a fork of Erlang/OTP's `logger_std_h` to: * allow to mock the call to io:put_chars/2 * support date-based rotation [How] The initial fork was from Erlang/OTP 23.0. Here, we update it to Erlang/OTP 26.1.2.
1 parent 67fccf0 commit 89c6c59

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

deps/rabbitmq_prelaunch/src/rabbit_logger_std_h.erl

+28-10
Original file line numberDiff line numberDiff line change
@@ -524,20 +524,38 @@ ensure_file(#{inode:=INode0,file_name:=FileName,modes:=Modes}=State) ->
524524
State#{last_check=>timestamp()};
525525
_ ->
526526
close_log_file(State),
527-
case file:open(FileName,Modes) of
528-
{ok,Fd} ->
529-
{ok,#file_info{inode=INode}} =
530-
file:read_file_info(FileName,[raw]),
531-
State#{fd=>Fd,inode=>INode,
532-
last_check=>timestamp(),
533-
synced=>true,sync_res=>ok};
534-
Error ->
535-
exit({could_not_reopen_file,Error})
536-
end
527+
{ok, Fd} = ensure_open(FileName, Modes),
528+
{ok,#file_info{inode=INode}} =
529+
file:read_file_info(FileName,[raw]),
530+
State#{fd=>Fd,inode=>INode,
531+
last_check=>timestamp(),
532+
synced=>true,sync_res=>ok}
537533
end;
538534
ensure_file(State) ->
539535
State.
540536

537+
ensure_open(Filename, Modes) ->
538+
case filelib:ensure_dir(Filename) of
539+
ok ->
540+
case file:open(Filename, Modes) of
541+
{ok, Fd} ->
542+
{ok, Fd};
543+
Error ->
544+
exit({could_not_reopen_file,Error})
545+
end;
546+
Error ->
547+
exit({could_not_create_dir_for_file,Error})
548+
end.
549+
550+
write_to_dev(Bin,#{dev:=standard_io}=State) ->
551+
try
552+
io:put_chars(user, Bin)
553+
catch _E:_R ->
554+
io:put_chars(
555+
standard_error, "Failed to write log message to stdout, trying stderr\n"),
556+
io:put_chars(standard_error, Bin)
557+
end,
558+
State;
541559
write_to_dev(Bin,#{dev:=DevName}=State) ->
542560
?io_put_chars(DevName, Bin),
543561
State;

0 commit comments

Comments
 (0)