You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2011/10/31 10:13:27 UTC
git commit: Properly adhere to bytes and offset parameters for /_log
Updated Branches:
refs/heads/master 6dcd3a4b6 -> a0284a483
Properly adhere to bytes and offset parameters for /_log
Closes COUCHDB-887
Project: http://git-wip-us.apache.org/repos/asf/couchdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb/commit/a0284a48
Tree: http://git-wip-us.apache.org/repos/asf/couchdb/tree/a0284a48
Diff: http://git-wip-us.apache.org/repos/asf/couchdb/diff/a0284a48
Branch: refs/heads/master
Commit: a0284a483f83d2fb98ff2755743053f3a3898454
Parents: 6dcd3a4
Author: Jan Lehnardt <ja...@apache.org>
Authored: Mon Oct 31 10:11:42 2011 +0100
Committer: Jan Lehnardt <ja...@apache.org>
Committed: Mon Oct 31 10:11:42 2011 +0100
----------------------------------------------------------------------
src/couchdb/couch_log.erl | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb/blob/a0284a48/src/couchdb/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index 0befe7a..1b05f4d 100644
--- a/src/couchdb/couch_log.erl
+++ b/src/couchdb/couch_log.erl
@@ -172,6 +172,23 @@ get_log_messages(Pid, Level, Format, Args) ->
FileMsg = ["[", httpd_util:rfc1123_date(), "] ", ConsoleMsg],
{ConsoleMsg, iolist_to_binary(FileMsg)}.
+
+% Read Bytes bytes from the end of log file, jumping Offset bytes towards
+% the beginning of the file first.
+%
+% Log File FilePos
+% ----------
+% | | 10
+% | | 20
+% | | 30
+% | | 40
+% | | 50
+% | | 60
+% | | 70 -- Bytes = 20 --
+% | | 80 | Chunk
+% | | 90 -- Offset = 10 --
+% |__________| 100
+
read(Bytes, Offset) ->
LogFileName = couch_config:get("log", "file"),
LogFileSize = filelib:file_size(LogFileName),
@@ -186,11 +203,11 @@ read(Bytes, Offset) ->
end,
{ok, Fd} = file:open(LogFileName, [read]),
- Start = lists:max([LogFileSize - Bytes, 0]) + Offset,
+ Start = lists:max([LogFileSize - Bytes - Offset, 0]),
% TODO: truncate chopped first line
% TODO: make streaming
- {ok, Chunk} = file:pread(Fd, Start, LogFileSize),
+ {ok, Chunk} = file:pread(Fd, Start, Bytes),
ok = file:close(Fd),
Chunk.