]> granicus.if.org Git - ejabberd/commitdiff
* src/ejabberd_logger_h.erl: reopen-log function now rename the log
authorMickaël Rémond <mickael.remond@process-one.net>
Sat, 4 Mar 2006 17:33:23 +0000 (17:33 +0000)
committerMickaël Rémond <mickael.remond@process-one.net>
Sat, 4 Mar 2006 17:33:23 +0000 (17:33 +0000)
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

ChangeLog
src/ejabberd_logger_h.erl

index c4b573b6c2041affe8854655d56e2caeb958acbc..9306353a45ead1d74bc4e9da6e424b1c82ab430a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
index 462f408d427684c37ee590b42ef530fc4b443215..975a9b25f392ad840c67082fe4252d1382007dfd 100644 (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.
+