Skip to content

Commit e8bf2ac

Browse files
authored
drop tee logger, update Julia dep (#18)
- dropping tee logger functionality - updating Julia dependency to v1.8+
1 parent af9befa commit e8bf2ac

File tree

5 files changed

+8
-159
lines changed

5 files changed

+8
-159
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
version:
15-
- '1.2'
15+
- '1.8'
1616
- '1' # automatically expands to the latest stable 1.x release of Julia
1717
- nightly
1818
os:

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ uuid = "c41e01d8-14e5-11ea-185b-e7eabed7be4b"
33
keywords = ["log", "rotate", "roller", "logrotate"]
44
license = "MIT"
55
authors = ["Tanmay Mohapatra <[email protected]>"]
6-
version = "0.4.4"
6+
version = "0.5.0"
77

88
[compat]
9-
julia = "1.2"
9+
julia = "1.8"
1010
CodecZlib = "0.6,0.7"
1111
JSON = "0.21"
1212

README.md

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# LogRoller.jl
22

3-
[![Build Status](https://travis-ci.org/tanmaykm/LogRoller.jl.png)](https://travis-ci.org/tanmaykm/LogRoller.jl)
4-
[![Build Status](https://ci.appveyor.com/api/projects/status/github/tanmaykm/LogRoller.jl?branch=master&svg=true)](https://ci.appveyor.com/project/tanmaykm/logroller-jl/branch/master)
5-
[![Coverage Status](https://coveralls.io/repos/github/tanmaykm/LogRoller.jl/badge.svg?branch=master)](https://coveralls.io/github/tanmaykm/LogRoller.jl?branch=master)
3+
[![Build Status](https://github.com/JuliaLogging/LogRoller.jl/workflows/CI/badge.svg)](https://github.com/JuliaLogging/LogRoller.jl/actions/?query=workflow%3ACI+branch%3Amaster)
4+
[![codecov.io](http://codecov.io/github/JuliaLogging/LogRoller.jl/coverage.svg?branch=main)](http://codecov.io/github/JuliaLogging/LogRoller.jl?branch=main)
65

76
Provides:
87
- `RollingFileWriter` - `IO` implementation to a file writer that rotates files based on file size.
@@ -28,23 +27,6 @@ Rotates files as below:
2827
- ...
2928
- `<filename>_n.gz` : last rotated file is discarded when rotated
3029

31-
32-
## `RollingFileWriterTee`
33-
34-
Tees raw log entries made a RollingFileWriter on to a Julia `AbstractLogger`.
35-
36-
Each line of text is taken as a single log message.
37-
38-
All log entries are made with the same log level, which can be provided during construction. It leaves
39-
further examination/parsing of log messages (to extract parameters, or detect exact log levels) to the
40-
downstream logger.
41-
42-
Constructor parameters in addition to those for `RollingFileWriter`:
43-
- `logger`: instance of AbstractLogger to tee log entries to
44-
- `assumed_level`: level of the log messages to assume (default Info)
45-
46-
Note: `RollingFileWriterTee` is supported only until Julia 1.7.
47-
4830
## `RollingLogger`
4931

5032
A logger that implements `AbstractLogger` interface and uses a `RollingFileWriter` to provide log rotation.
@@ -88,16 +70,6 @@ julia> io = RollingFileWriter("/tmp/mylog.log", 1000, 3);
8870
julia> run(pipeline(`myshellscript.sh`; stdout=io, stderr=io));
8971
```
9072

91-
Using `RollingFileWriterTee`
92-
93-
```julia
94-
julia> using LogRoller, Logging
95-
96-
julia> io = RollingFileWriterTee("/tmp/mylog.log", 1000, 3, ConsoleLogger(stderr));
97-
98-
julia> run(pipeline(`myshellscript.sh`; stdout=io, stderr=io));
99-
```
100-
10173
Using `RollingLogger`
10274

10375
```julia

src/LogRoller.jl

Lines changed: 2 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import JSON: show_json
1111

1212
import Logging: shouldlog, min_enabled_level, catch_exceptions, handle_message
1313
import Base: write, close, rawhandle
14-
export RollingLogger, RollingFileWriter, RollingFileWriterTee, postrotate
14+
export RollingLogger, RollingFileWriter, postrotate
1515

1616
const BUFFSIZE = 1024*16 # try and read 16K pages when possible
1717
const DEFAULT_MAX_LOG_ENTRY_SIZE = 256*1024
@@ -34,16 +34,12 @@ mutable struct RollingFileWriter <: IO
3434
filesize::Int
3535
stream::IO
3636
lck::ReentrantLock
37-
procstream::Union{Nothing,Pipe}
38-
procstreamer::Union{Nothing,Task}
39-
procstreamteelogger::Union{Nothing,AbstractLogger}
40-
assumed_level::LogLevel
4137
postrotate::Union{Nothing,Function}
4238

4339
function RollingFileWriter(filename::String, sizelimit::Int, nfiles::Int; rotate_on_init=false)
4440
stream = open(filename, "a")
4541
filesize = stat(stream).size
46-
io = new(filename, sizelimit, nfiles, filesize, stream, ReentrantLock(), nothing, nothing, nothing, Logging.Info, nothing)
42+
io = new(filename, sizelimit, nfiles, filesize, stream, ReentrantLock(), nothing)
4743
if rotate_on_init && filesize > 0
4844
rotate_file(io)
4945
end
@@ -61,28 +57,11 @@ function postrotate(fn::Function, io::RollingFileWriter)
6157
nothing
6258
end
6359

64-
"""
65-
Tee all lines to the provided logger
66-
"""
67-
function tee(io::RollingFileWriter, logger::AbstractLogger, level::LogLevel)
68-
io.procstreamteelogger = logger
69-
io.assumed_level = level
70-
io
71-
end
72-
7360
"""
7461
Close any open file handle and streams.
7562
A closed object must not be used again.
7663
"""
7764
function close(io::RollingFileWriter)
78-
if io.procstream !== nothing
79-
close(io.procstream)
80-
lock(io.lck) do
81-
io.procstream = nothing
82-
io.procstreamer = nothing
83-
io.procstreamteelogger = nothing
84-
end
85-
end
8665
close(io.stream)
8766
end
8867

@@ -155,24 +134,6 @@ function rotate_file(io::RollingFileWriter)
155134
nothing
156135
end
157136

158-
"""
159-
Tees raw log entries made a RollingFileWriter on to a provided Julia AbstractLogger.
160-
161-
Each line of text is taken as a single log message.
162-
163-
All log entries are made with the same log level, which can be provided during construction. It leaves
164-
further examination/parsing of log messages (to extract parameters, or detect exact log levels) to the
165-
downstream logger.
166-
"""
167-
function RollingFileWriterTee(filename::String, sizelimit::Int, nfiles::Int, logger::AbstractLogger, assumed_level::LogLevel=Logging.Info)
168-
io = RollingFileWriter(filename, sizelimit, nfiles)
169-
RollingFileWriterTee(io, logger, assumed_level)
170-
end
171-
172-
function RollingFileWriterTee(io::RollingFileWriter, logger::AbstractLogger, assumed_level::LogLevel=Logging.Info)
173-
tee(io, logger, assumed_level)
174-
end
175-
176137
"""
177138
RollingLogger(filename, sizelimit, nfiles, min_level=Info; timestamp_identifier::Symbol=:time, format::Symbol=:console)
178139
Log into a log file. Rotate log file based on file size. Compress rotated logs.
@@ -277,44 +238,4 @@ function handle_message(logger::RollingLogger, level, message, _module, group, i
277238
nothing
278239
end
279240

280-
function stream_process_logs(writer::RollingFileWriter)
281-
try
282-
while true
283-
logline = readline(writer.procstream; keep=true)
284-
if !isempty(logline)
285-
write(writer, logline)
286-
if writer.procstreamteelogger !== nothing
287-
@logmsg(writer.assumed_level, strip(logline))
288-
end
289-
end
290-
eof(writer.procstream) && break
291-
end
292-
finally
293-
close(writer.procstream)
294-
lock(writer.lck) do
295-
writer.procstream = nothing
296-
writer.procstreamer = nothing
297-
end
298-
end
299-
end
300-
301-
function rawhandle(writer::RollingFileWriter)
302-
lock(writer.lck) do
303-
if (writer.procstream === nothing) || !isopen(Base.pipe_writer(writer.procstream))
304-
writer.procstream = Pipe()
305-
Base.link_pipe!(writer.procstream)
306-
writer.procstreamer = @async begin
307-
if writer.procstreamteelogger !== nothing
308-
with_logger(writer.procstreamteelogger) do
309-
stream_process_logs(writer)
310-
end
311-
else
312-
stream_process_logs(writer)
313-
end
314-
end
315-
end
316-
return rawhandle(Base.pipe_writer(writer.procstream))
317-
end
318-
end
319-
320241
end # module

test/runtests.jl

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,6 @@ function test_filewriter()
7373
end
7474
end
7575

76-
function test_pipelined_tee()
77-
mktempdir() do logdir
78-
filename1 = "test1.log"
79-
filename2 = "test2.log"
80-
filepath1 = joinpath(logdir, filename1)
81-
filepath2 = joinpath(logdir, filename2)
82-
@test !isfile(filepath1)
83-
@test !isfile(filepath2)
84-
85-
logger1io = open(filepath1, "w+")
86-
logger1 = SimpleLogger(logger1io)
87-
logger2 = RollingFileWriterTee(filepath2, 1000, 3, logger1, Logging.Info)
88-
89-
julia = joinpath(Sys.BINDIR, "julia")
90-
cmd = pipeline(`$julia -e 'for i in 1:5 println(string("hello",i)) end; flush(stdout)'`; stdout=logger2, stderr=logger2)
91-
run(cmd)
92-
93-
close(logger2)
94-
close(logger1io)
95-
96-
@test isfile(filepath1)
97-
@test isfile(filepath2)
98-
@test (2*length(readlines(filepath2))) == length(readlines(filepath1)) # Julia logger entry will be two lines for every raw message
99-
if !Sys.iswindows() # streams do not seem to be flushed cleanly on Windows
100-
@test length(readlines(filepath2)) == 5
101-
end
102-
end
103-
end
104-
10576
function test_logger()
10677
mktempdir() do logdir
10778
filename = "test.log"
@@ -192,16 +163,7 @@ function test_process_streams()
192163
@test isfile(rolledfile(filepath, 1))
193164
@test !isfile(rolledfile(filepath, 2))
194165

195-
if VERSION < v"1.8"
196-
# pipelined processes are handled differently in Julia 1.8 and later
197-
@test io.procstream !== nothing
198-
@test io.procstreamer !== nothing
199-
@test !istaskdone(io.procstreamer)
200-
end
201-
202166
close(io)
203-
@test io.procstream === nothing
204-
@test io.procstreamer === nothing
205167
end
206168
end
207169

@@ -479,16 +441,10 @@ end
479441
test_filewriter()
480442
end
481443

482-
if VERSION < v"1.8"
483-
# pipelined tee logger is available only on Julia 1.7 and earlier
484-
@testset "pipelined tee" begin
485-
test_pipelined_tee()
486-
end
487-
end
488-
489444
@testset "process streams" begin
490445
test_process_streams()
491446
end
447+
492448
@testset "logger" begin
493449
test_logger()
494450
test_timestamp_handling()

0 commit comments

Comments
 (0)