Skip to content

Commit

Permalink
use file:read_file_info to detect missing access log
Browse files Browse the repository at this point in the history
  • Loading branch information
mojombo committed Feb 21, 2010
1 parent e1385d6 commit b137741
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ follows (with comments on the right side):
- delimiter
{call,nat,add,[1,2]} first 150 bytes of the request

To facilitate log rotation, the access log is automatically reopened every 10
seconds.
To facilitate log rotation, Ernie will create a new access log file if the
current log file is moved or deleted.


Native (Erlang) Handler
Expand Down
13 changes: 10 additions & 3 deletions elib/ernie_access_logger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,16 @@ handle_cast(reopen, State) ->
undefined ->
{noreply, State};
AccessFileName ->
ok = file:close(State#lstate.access_file),
{ok, AccessFile} = file:open(AccessFileName, [append]),
{noreply, State#lstate{access_file = AccessFile}}
case file:read_file_info(AccessFileName) of
{ok, _FileInfo} ->
{noreply, State};
{error, enoent} ->
ok = file:close(State#lstate.access_file),
{ok, AccessFile} = file:open(AccessFileName, [append]),
{noreply, State#lstate{access_file = AccessFile}};
_OtherError ->
{noreply, #lstate{}}
end
end;
handle_cast(_Msg, State) ->
{noreply, State}.
Expand Down

0 comments on commit b137741

Please sign in to comment.