Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Properly adhere to bytes and offset parameters for /_log

Closes COUCHDB-887
  • Loading branch information...
commit a0284a483f83d2fb98ff2755743053f3a3898454 1 parent 6dcd3a4
Jan Lehnardt janl authored

Showing 1 changed file with 19 additions and 2 deletions. Show diff stats Hide diff stats

  1. +19 2 src/couchdb/couch_log.erl
21 src/couchdb/couch_log.erl
@@ -172,6 +172,23 @@ get_log_messages(Pid, Level, Format, Args) ->
172 172 FileMsg = ["[", httpd_util:rfc1123_date(), "] ", ConsoleMsg],
173 173 {ConsoleMsg, iolist_to_binary(FileMsg)}.
174 174
  175 +
  176 +% Read Bytes bytes from the end of log file, jumping Offset bytes towards
  177 +% the beginning of the file first.
  178 +%
  179 +% Log File FilePos
  180 +% ----------
  181 +% | | 10
  182 +% | | 20
  183 +% | | 30
  184 +% | | 40
  185 +% | | 50
  186 +% | | 60
  187 +% | | 70 -- Bytes = 20 --
  188 +% | | 80 | Chunk
  189 +% | | 90 -- Offset = 10 --
  190 +% |__________| 100
  191 +
175 192 read(Bytes, Offset) ->
176 193 LogFileName = couch_config:get("log", "file"),
177 194 LogFileSize = filelib:file_size(LogFileName),
@@ -186,11 +203,11 @@ read(Bytes, Offset) ->
186 203 end,
187 204
188 205 {ok, Fd} = file:open(LogFileName, [read]),
189   - Start = lists:max([LogFileSize - Bytes, 0]) + Offset,
  206 + Start = lists:max([LogFileSize - Bytes - Offset, 0]),
190 207
191 208 % TODO: truncate chopped first line
192 209 % TODO: make streaming
193 210
194   - {ok, Chunk} = file:pread(Fd, Start, LogFileSize),
  211 + {ok, Chunk} = file:pread(Fd, Start, Bytes),
195 212 ok = file:close(Fd),
196 213 Chunk.

0 comments on commit a0284a4

Please sign in to comment.
Something went wrong with that request. Please try again.