25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-12 17:01:52 +01:00

* src/ejabberd_logger_h.erl: reopen-log function now rename the log

file if it has not been already renamed by a logrotate process.  This
change allow ejabberd administrators to rotate log files on Windows
(EJAB-52).

SVN Revision: 514
This commit is contained in:
Mickaël Rémond 2006-03-04 17:33:23 +00:00
parent 17420e058b
commit 804c32c100
2 changed files with 22 additions and 0 deletions

View File

@ -1,3 +1,10 @@
2006-03-04 Mickael Remond <mickael.remond@process-one.net>
* src/ejabberd_logger_h.erl: reopen-log function now rename the log
file if it has not been already renamed by a logrotate process. This
change allow ejabberd administrators to rotate log files on Windows
(EJAB-52).
2006-02-27 Alexey Shchepin <alexey@sevcom.net>
* src/web/ejabberd_web_admin.erl: Added a interface for node

View File

@ -66,6 +66,7 @@ handle_info({'EXIT', _Fd, _Reason}, _State) ->
remove_handler;
handle_info({emulator, _GL, reopen}, State) ->
file:close(State#state.fd),
rotate_log(State#state.file),
case file:open(State#state.file, [append, raw]) of
{ok, Fd} ->
{ok, State#state{fd = Fd}};
@ -189,3 +190,17 @@ write_time({{Y,Mo,D},{H,Mi,S}}, Type) ->
io_lib:format("~n=~s==== ~w-~.2.0w-~.2.0w ~.2.0w:~.2.0w:~.2.0w ===~n",
[Type, Y, Mo, D, H, Mi, S]).
%% Rename the log file if it the filename exists
%% This is needed in systems when the file must be closed before rotation (Windows).
%% On most Unix-like system, the file can be renamed from the command line and
%%the log can directly be reopened.
rotate_log(Filename) ->
case file:read_file_info(Filename) of
{ok, _FileInfo} ->
RotationName = filename:rootname(Filename),
file:rename(Filename, [RotationName, "-old.log"]),
ok;
{error, _Reason} ->
ok
end.