Skip to content

Commit 83228a6

Browse files
authored
Merge pull request #2 from tanmaykm/tan/misc
add connector for LogRoler.RollingFileWriterTee
2 parents f889744 + 31b712b commit 83228a6

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The LogCompose.jl package is licensed under the MIT "Expat" License:
22

3-
> Copyright (c) 2019-2020: Tanmay Mohapatra, Julia Computing
3+
> Copyright (c) 2020-2021: Tanmay Mohapatra, Julia Computing
44
>
55
> Permission is hereby granted, free of charge, to any person obtaining
66
> a copy of this software and associated documentation files (the

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["configure", "compose", "logging", "logger"]
44
authors = ["tan <[email protected]>"]
55
license = "MIT"
66
desc = "Compose loggers and logger ensembles declaratively using configuration files"
7-
version = "0.1.0"
7+
version = "0.1.1"
88

99
[deps]
1010
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
@@ -18,7 +18,7 @@ LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
1818
julia = "1"
1919
SyslogLogging = "0.1"
2020
LoggingExtras = "0.4"
21-
LogRoller = "0.2"
21+
LogRoller = "0.3"
2222

2323
[extras]
2424
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ LogCompose supports the following types of loggers at the moment:
9595
- Logging.SimpleLogger
9696
- LoggingExtras.TeeLogger
9797
- LogRoller.RollingLogger
98+
- LogRoler.RollingFileWriterTee
9899
- SyslogLogging.SyslogLogger
99100

100101
### Plugging in other Loggers

src/compose.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,4 @@ end
5454
logcompose(::Type{T}, config::Dict{String,Any}, logger_config::Dict{String,Any}) where {T} = @error("logcompose not implemented for type $T")
5555

5656
log_min_level(logger_config::Dict{String,Any}, default::String="Info") = getproperty(Logging, Symbol(get(logger_config, "min_level", default)))
57+
log_assumed_level(logger_config::Dict{String,Any}, default::String="Info") = getproperty(Logging, Symbol(get(logger_config, "assumed_level", default)))

src/connectors.jl

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Connectors
22

33
using ..LogCompose
4-
import ..LogCompose: logcompose, log_min_level
4+
import ..LogCompose: logcompose, log_min_level, log_assumed_level
55

66
using Logging, LogRoller, SyslogLogging, LoggingExtras, Sockets
77

@@ -40,10 +40,10 @@ function logcompose(::Type{SyslogLogging.SyslogLogger}, config::Dict{String,Any}
4040
if (server_type == "tcp") || (server_type == "udp")
4141
kwargs[:tcp] = (server_type == "tcp")
4242
if haskey(logger_config, "server_host")
43-
kwargs[:host] = Sockets.IPv4(logger_config["server_host"])
43+
kwargs[:host] = logger_config["server_host"]
4444
end
4545
if haskey(logger_config, "server_port")
46-
kwargs[:port] = parse(Int, logger_config["server_port"])
46+
kwargs[:port] = logger_config["server_port"]
4747
end
4848
end
4949
SyslogLogging.SyslogLogger(ident, level; kwargs...)
@@ -61,6 +61,18 @@ function logcompose(::Type{LogRoller.RollingLogger}, config::Dict{String,Any}, l
6161
LogRoller.RollingLogger(filename, sizelimit, nfiles, level; timestamp_identifier=timestamp_identifier)
6262
end
6363

64+
function logcompose(::typeof(LogRoller.RollingFileWriterTee), config::Dict{String,Any}, logger_config::Dict{String,Any})
65+
filename = String(strip(logger_config["filename"]))
66+
@assert !isempty(filename)
67+
68+
level = log_assumed_level(logger_config, "Info")
69+
sizelimit = get(logger_config, "sizelimit", 10240000)
70+
nfiles = get(logger_config, "nfiles", 5)
71+
destination_name = logger_config["destination"]
72+
destination = LogCompose.logger(config, destination_name)
73+
LogRoller.RollingFileWriterTee(filename, sizelimit, nfiles, destination, level)
74+
end
75+
6476
function logcompose(::Type{LoggingExtras.TeeLogger}, config::Dict{String,Any}, logger_config::Dict{String,Any})
6577
destinations = [LogCompose.logger(config, dest) for dest in logger_config["destinations"]]
6678
LoggingExtras.TeeLogger(destinations...)

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ function test()
44
config = joinpath(@__DIR__, "testapp.toml")
55
default_logfile = "/tmp/default.log"
66
rotated_logfile = "/tmp/testapp.log"
7+
rotated_tee_logfile = "/tmp/testapptee.log"
78
rm(rotated_logfile; force=true)
9+
rm(rotated_tee_logfile; force=true)
810
rm(default_logfile; force=true)
911

1012
let logger = LogCompose.logger(config, "default"; section="loggers")
@@ -34,12 +36,22 @@ function test()
3436
end
3537
end
3638

39+
let logger = LogCompose.logger(config, "testapptee"; section="loggers")
40+
julia = joinpath(Sys.BINDIR, "julia")
41+
cmd = pipeline(`$julia -e 'println("testteefilewriter"); flush(stdout)'`; stdout=logger, stderr=logger)
42+
run(cmd)
43+
end
44+
3745
log_file_contents = readlines(default_logfile)
3846
@test findfirst("testdefault", log_file_contents[1]) !== nothing
3947

4048
log_file_contents = readlines(rotated_logfile)
4149
@test findfirst("testroller", log_file_contents[1]) !== nothing
4250
@test findfirst("testtee", log_file_contents[3]) !== nothing
51+
@test findfirst("testteefilewriter", log_file_contents[5]) !== nothing
52+
53+
log_file_contents = readlines(rotated_tee_logfile)
54+
@test "testteefilewriter" == log_file_contents[1]
4355
end
4456

4557
test()

test/testapp.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,11 @@ log_name = "testapp"
3939
[loggers.testapp]
4040
type = "LoggingExtras.TeeLogger"
4141
destinations = ["file.testapp", "syslog.testapp"]
42+
43+
[loggers.testapptee]
44+
type = "LogRoller.RollingFileWriterTee"
45+
destination = "file.testapp"
46+
filename = "/tmp/testapptee.log"
47+
# sizelimit = 10240000
48+
# nfiles = 5
49+
# assumed_level = "Debug" # Debug, Info (default) or Error

0 commit comments

Comments
 (0)