summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHubert Plociniczak <hubert@lshift.net>2008-08-19 14:48:03 +0100
committerHubert Plociniczak <hubert@lshift.net>2008-08-19 14:48:03 +0100
commitd6a2ba61a838b604fad47286afa097d136095635 (patch)
treee8005f0be175dad6a6d07393b4ac32eeabe90eb4 /src
parent18c7a16507cde719f143213ed80663964a6e6c61 (diff)
downloadrabbitmq-server-git-d6a2ba61a838b604fad47286afa097d136095635.tar.gz
Used swap_handler mechanism provided in
error_logger to correctly reopen_logs. This creates another copy of the handler which has to be manually removed. Apparently the first one in the list is the old one. Updated man pages.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit.erl77
1 files changed, 37 insertions, 40 deletions
diff --git a/src/rabbit.erl b/src/rabbit.erl
index a5a74231bc..3de403789b 100644
--- a/src/rabbit.erl
+++ b/src/rabbit.erl
@@ -51,7 +51,7 @@
-spec(stop/0 :: () -> 'ok').
-spec(stop_and_halt/0 :: () -> 'ok').
-spec(reopen_logs/0 :: () -> 'ok').
--spec(reopen_logs/1 :: name() -> 'ok').
+-spec(reopen_logs/1 :: name() -> 'ok' | {'error', 'cannot_append_logfile'}).
-spec(status/0 :: () ->
[{running_applications, [{atom(), string(), string()}]} |
{nodes, [node()]} |
@@ -89,13 +89,15 @@ status() ->
rabbit_mnesia:status().
reopen_logs() ->
- ok = reopen_main_logs([]),
- ok = reopen_sasl_logs([]).
+ ok = reopen_logs(error_log_location(), [], main_log),
+ ok = reopen_logs(sasl_log_location(), [], sasl_log).
reopen_logs(Suffix) ->
LSuffix = binary_to_list(Suffix),
- ok = reopen_main_logs(LSuffix),
- ok = reopen_sasl_logs(LSuffix).
+ case reopen_logs(error_log_location(), LSuffix, main_log) of
+ ok -> reopen_logs(sasl_log_location(), LSuffix, sasl_log);
+ Error -> Error
+ end.
%%--------------------------------------------------------------------
@@ -273,46 +275,41 @@ sasl_log_location() ->
_ -> undefined
end.
-sasl_error_logger_type() ->
- case application:get_env(sasl, errlog_type) of
- {ok, error} -> error;
- {ok, progress} -> progress;
- {ok, all} -> all;
- {ok, Bad} -> throw({error, {wrong_errlog_type, Bad}});
- _ -> all
- end.
-
-reopen_main_logs(Suffix) ->
- case error_log_location() of
- tty -> ok;
- File -> error_logger:delete_report_handler(error_logger_file_h),
- rotate_log_file(File, Suffix),
- error_logger:add_report_handler(error_logger_file_h,File)
- end.
-
-reopen_sasl_logs(Suffix) ->
- case sasl_log_location() of
+reopen_logs(File, Suffix,Swap) ->
+ case File of
undefined -> ok;
tty -> ok;
- File -> error_logger:delete_report_handler(sasl_report_file_h),
- rotate_log_file(File,Suffix),
- error_logger:add_report_handler(sasl_report_file_h,
- {File, sasl_error_logger_type()})
+ _ -> case append_to_log_file(File, Suffix) of
+ omit -> swap_handler(Swap, File);
+ ok -> swap_handler(Swap, File);
+ Error -> Error
+ end
end.
-rotate_log_file(File, Suffix) ->
+swap_handler(main_log, File) ->
+ error_logger:swap_handler({logfile, File}),
+ error_logger:delete_report_handler(error_logger_file_h),
+ ok;
+swap_handler(sasl_log, File ) ->
+ gen_event:swap_handler(error_logger,
+ {error_logger, swap},
+ {sasl_report_file_h, File}),
+ gen_event:add_handler(error_logger, error_logger, []),
+ error_logger:delete_report_handler(sasl_report_file_h),
+ ok.
+
+append_to_log_file(File, Suffix) ->
case file:read_file_info(File) of
- {ok, FInfo} -> rename_log_file(File, FInfo#file_info.size, Suffix);
- {error, _} -> ok
+ {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix);
+ {error, _} -> ok
end.
-rename_log_file(_, 0, _) ->
- ok;
-rename_log_file(_, _, []) ->
- ok;
-rename_log_file(File, _, Suffix) ->
- case file:read_file_info([File,Suffix]) of
- {ok, _} -> ok;
- {error, enoent} -> file:rename(File, [File, Suffix]);
- {error, _} -> ok
+append_file(_, 0, _) ->
+ omit;
+append_file(_, _, []) ->
+ omit;
+append_file(File, _, Suffix) ->
+ case file:read_file(File) of
+ {ok, Data} -> file:write_file([File, Suffix], Data, [append]);
+ {error, _} -> {error, cannot_append_logfile}
end.