Handbook
Glossary
log-file-tail ( path limit -- lines omitted-bytes )
Vocabulary
logging
.
parser
Inputs
path
a log file path
limit
a positive byte count
Outputs
lines
a sequence of strings
omitted-bytes
the number of omitted bytes
Word description
Reads at most the last
limit
bytes of a log file, discarding a partial first line before decoding UTF-8. The file is closed on both success and failure.
Definition
USING:
io
io.encodings.binary
io.encodings.string
io.encodings.utf8
io.files
kernel
math
math.order
namespaces
sequences
splitting
;
IN:
logging.parser
::
log-file-tail
( path limit -- lines omitted-bytes )
limit
integer?
[
limit 0
>
]
[
f
]
if
[
limit
invalid-log-tail-limit
]
unless
path
binary
[
input-stream
get
stream-length
0
or
limit
-
0
max
:>
start start 0
>
[
start 1
-
seek-absolute
seek-input
read1
10
=
]
[
t
]
if
:>
line-boundary? limit
read
B{
}
or
:>
bytes line-boundary?
[
0
]
[
10 bytes
index
[
1
+
]
[
bytes
length
]
if*
]
if
:>
partial bytes partial
tail
utf8
decode
split-lines
start partial
+
]
with-file-reader
;