diff options
author | Jan Lehnardt <jan@apache.org> | 2009-05-12 19:36:15 +0000 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2009-05-12 19:36:15 +0000 |
commit | 7c76d131110e4641114e3066844e7195efb2f33b (patch) | |
tree | fc7e7f4af83b58adeb2b3eba11ad3876fc2a788d /src/couchdb/couch_log.erl | |
parent | b37ce2b377cff6c3e358adf4963ae6290942fae7 (diff) |
Add non-streaming log-file handler. A GET request to /_log will show the last 1000 bytes of the logflie. More bytes can be requested with GET /_log?bytes=10000.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@774045 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_log.erl')
-rw-r--r-- | src/couchdb/couch_log.erl | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl index 3d99ae1e..693eed9b 100644 --- a/src/couchdb/couch_log.erl +++ b/src/couchdb/couch_log.erl @@ -16,6 +16,7 @@ -export([start_link/0,stop/0]). -export([debug_on/0,info_on/0,get_level/0,get_level_integer/0, set_level/1]). -export([init/1, handle_event/2, terminate/2, code_change/3, handle_info/2, handle_call/2]). +-export([read/1]). -define(LEVEL_ERROR, 3). -define(LEVEL_INFO, 2). @@ -120,3 +121,16 @@ log(Fd, Pid, Level, Format, Args) -> ok = io:format("[~s] [~p] ~s~n", [Level, Pid, Msg]), % dump to console too {ok, Msg2, _} = regexp:gsub(lists:flatten(Msg),"\\r\\n|\\r|\\n", "\r\n"), ok = io:format(Fd, "[~s] [~s] [~p] ~s\r~n\r~n", [httpd_util:rfc1123_date(), Level, Pid, Msg2]). + +read(LastBytes) -> + LogFileName = couch_config:get("log", "file"), + LogFileSize = couch_util:file_read_size(LogFileName), + + {ok, Fd} = file:open(LogFileName, [binary]), + Start = lists:max([LogFileSize - LastBytes, 0]), + + % TODO: truncate chopped first line + % TODO: make streaming + + {ok, Chunk} = file:pread(Fd, Start, LogFileSize), + Chunk. |