Permalink
Browse files

fix log rotation on Windows, where fsync() is required to get the act…

…ual file size

Signed-off-by: Garret Smith <garret.smith@gmail.com>
  • Loading branch information...
1 parent 51c5e03 commit 317008a49b945b8cb534463fbb3a8cfb8fe69a9c @garret-smith garret-smith committed Dec 7, 2011
Showing with 13 additions and 6 deletions.
  1. +4 −6 src/yaws_log.erl
  2. +9 −0 src/yaws_log_file_h.erl
View
@@ -349,14 +349,12 @@ handle_info(secs3, State) ->
handle_info(minute10, State) ->
yaws_logger:rotate(State#state.log_wrap_size),
- Dir = State#state.dir,
- E = filename:join([Dir, "report.log"]),
- case file:read_file_info(E) of
- {ok, FI} when State#state.log_wrap_size > 0,
- FI#file_info.size > State#state.log_wrap_size,
+ case gen_event:call(error_logger, yaws_log_file_h, size, infinity) of
+ {ok, Size} when State#state.log_wrap_size > 0,
+ Size > State#state.log_wrap_size,
State#state.copy_errlog == true ->
gen_event:call(error_logger, yaws_log_file_h, wrap, infinity);
- {error,enoent} ->
+ {error, enoent} ->
gen_event:call(error_logger, yaws_log_file_h, reopen, infinity);
_ ->
ok
View
@@ -14,6 +14,7 @@
-module(yaws_log_file_h).
-behaviour(gen_event).
+-include_lib("kernel/include/file.hrl").
-export([init/1,
handle_event/2, handle_call/2, handle_info/2,
@@ -47,6 +48,14 @@ handle_call(wrap, {Fd, File, Prev}) ->
{ok, Fd2} = file:open(File, [write,append]),
{ok, ok, {Fd2, File, Prev}};
+handle_call(size, {Fd, File, Prev}) ->
+ file:sync(Fd),
+ Return = case file:read_file_info(File) of
+ {ok, FI} -> {ok, FI#file_info.size};
+ Error -> Error
+ end,
+ {ok, Return, {Fd, File, Prev}};
+
handle_call(X, S) ->
error_logger_file_h:handle_call(X,S).

0 comments on commit 317008a

Please sign in to comment.