Skip to content

Commit f889744

Browse files
authored
Merge pull request #1 from tanmaykm/tan/misc
add license and readme, configure CI
2 parents 4a04639 + 1a93c38 commit f889744

File tree

5 files changed

+164
-2
lines changed

5 files changed

+164
-2
lines changed

.travis.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Documentation: http://docs.travis-ci.com/user/languages/julia/
2+
language: julia
3+
os:
4+
- linux
5+
- osx
6+
julia:
7+
- 1.0
8+
- 1.1
9+
- 1.2
10+
- 1.3
11+
- 1.4
12+
- nightly
13+
matrix:
14+
allow_failures:
15+
- julia: nightly
16+
notifications:
17+
email: false
18+
# uncomment the following lines to override the default test script
19+
script:
20+
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
21+
- julia --project -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/tanmaykm/SyslogLogging.jl", rev="master")); Pkg.build(); Pkg.test(; coverage=true)';
22+
after_success:
23+
# push coverage results to Coveralls
24+
- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())';
25+
# push coverage results to Codecov
26+
#- julia -e 'using Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The LogCompose.jl package is licensed under the MIT "Expat" License:
2+
3+
> Copyright (c) 2019-2020: Tanmay Mohapatra, Julia Computing
4+
>
5+
> Permission is hereby granted, free of charge, to any person obtaining
6+
> a copy of this software and associated documentation files (the
7+
> "Software"), to deal in the Software without restriction, including
8+
> without limitation the rights to use, copy, modify, merge, publish,
9+
> distribute, sublicense, and/or sell copies of the Software, and to
10+
> permit persons to whom the Software is furnished to do so, subject to
11+
> the following conditions:
12+
>
13+
> The above copyright notice and this permission notice shall be
14+
> included in all copies or substantial portions of the Software.
15+
>
16+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
> EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
> MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
> IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20+
> CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21+
> TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22+
> SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,114 @@
11
# LogCompose
2+
3+
[![Build Status](https://travis-ci.org/tanmaykm/LogCompose.jl.png)](https://travis-ci.org/tanmaykm/LogCompose.jl)
4+
[![Coverage Status](https://coveralls.io/repos/github/tanmaykm/LogCompose.jl/badge.svg?branch=master)](https://coveralls.io/github/tanmaykm/LogCompose.jl?branch=master)
5+
6+
Provides a way to specify hierarchical logging configuration in a file.
7+
8+
Configuration file is in the form of a TOML file. Configuration sections are named,
9+
with each section specifying a logger type and parameters needed for its construction.
10+
Sections inherit parameter values from preceeding sectiona and can override them as well.
11+
Loggers can be constructed by providing the name of a section.
12+
13+
### Example configuration
14+
15+
```toml
16+
[file]
17+
type = "LogRoller.RollingLogger"
18+
min_level = "Info"
19+
nfiles = 5
20+
21+
[syslog]
22+
type = "SyslogLogging.SyslogLogger"
23+
facility = "user"
24+
25+
[file.testapp1]
26+
filename = "/tmp/testapp1.log"
27+
28+
[file.testapp2]
29+
filename = "/tmp/testapp2.log"
30+
min_level = "Debug" # overrides min_level to Debug for testapp2
31+
nfiles = 10 # overrides nfiles to 10 for testapp2
32+
33+
[syslog.testapp1]
34+
identity = "testapp1"
35+
facility = "daemon" # facility set to daemon instead of default user
36+
37+
[syslog.testapp2]
38+
identity = "testapp2"
39+
40+
[testapp1]
41+
type = "LoggingExtras.TeeLogger"
42+
destinations = ["file.testapp1", "syslog.testapp1"]
43+
44+
[testapp2]
45+
type = "LoggingExtras.TeeLogger"
46+
destinations = ["file.testapp2", "syslog.testapp2"]
47+
```
48+
49+
### Example usage
50+
51+
```julia
52+
julia> using LogCompose, Logging, LogRoller, SyslogLogging, LoggingExtras
53+
54+
julia> logger1 = LogCompose.logger("testconfig.toml", "testapp1");
55+
56+
julia> typeof(logger1)
57+
TeeLogger{Tuple{RollingLogger,SyslogLogger}}
58+
59+
julia> logger2 = LogCompose.logger("testconfig.toml", "testapp2");
60+
61+
julia> typeof(logger2)
62+
TeeLogger{Tuple{RollingLogger,SyslogLogger}}
63+
64+
julia> first(logger1.loggers).stream.filename
65+
"/tmp/testapp1.log"
66+
67+
julia> first(logger2.loggers).stream.filename
68+
"/tmp/testapp2.log"
69+
70+
julia> first(logger2.loggers).stream.nfiles
71+
10
72+
73+
julia> with_logger(logger1) do
74+
@info("hello from app1")
75+
end
76+
77+
shell> cat /tmp/testapp1.log
78+
┌ Info: 2020-04-02T12:03:03.588: hello from app1
79+
└ @ Main REPL[13]:2
80+
81+
julia> with_logger(logger2) do
82+
@info("hello from app2")
83+
end
84+
85+
shell> cat /tmp/testapp2.log
86+
┌ Info: 2020-04-02T12:04:13.156: hello from app2
87+
└ @ Main REPL[15]:2
88+
89+
```
90+
91+
### Loggers Supported
92+
93+
LogCompose supports the following types of loggers at the moment:
94+
95+
- Logging.SimpleLogger
96+
- LoggingExtras.TeeLogger
97+
- LogRoller.RollingLogger
98+
- SyslogLogging.SyslogLogger
99+
100+
### Plugging in other Loggers
101+
102+
Support for a new logger can be added by providing an implementation of `LogCompose.logcompose` for the target logger type.
103+
This can be done in user code or in a package other than LogCompose. The implementation needs to be of the following form:
104+
105+
```julia
106+
function LogCompose.logcompose(::Type{MyLoggerType},
107+
config::Dict{String,Any}, # config: the entire logging configuration file
108+
logger_config::Dict{String,Any}) # logger_config: configuration relevant for the
109+
# section specified to `LogCompose.logger`
110+
# with the hierarchy flattened out
111+
# provides support for MyLoggerType in LogCompose
112+
end
113+
```
114+

src/connectors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ function logcompose(::Type{LogRoller.RollingLogger}, config::Dict{String,Any}, l
5454
@assert !isempty(filename)
5555

5656
level = log_min_level(logger_config, "Info")
57-
sizelimit = parse(Int, get(logger_config, "sizelimit", "10240000"))
58-
nfiles = parse(Int, get(logger_config, "nfiles", "5"))
57+
sizelimit = get(logger_config, "sizelimit", 10240000)
58+
nfiles = get(logger_config, "nfiles", 5)
5959
timestamp_identifier = Symbol(get(logger_config, "timestamp_identifier", "time"))
6060

6161
LogRoller.RollingLogger(filename, sizelimit, nfiles, level; timestamp_identifier=timestamp_identifier)

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function test()
1212
@info("testdefault")
1313
end
1414
@test isfile(default_logfile)
15+
close(logger.stream)
1516
end
1617

1718
let logger = LogCompose.logger(config, "file.testapp"; section="loggers")

0 commit comments

Comments
 (0)