|
1 | 1 | # LogCompose |
2 | 2 |
|
3 | 3 | [](https://travis-ci.org/tanmaykm/LogCompose.jl) |
| 4 | +[](https://ci.appveyor.com/project/tanmaykm/logroller-jl/branch/master) |
4 | 5 | [](https://coveralls.io/github/tanmaykm/LogCompose.jl?branch=master) |
5 | 6 |
|
6 | 7 | Provides a way to specify hierarchical logging configuration in a file. |
7 | 8 |
|
8 | 9 | Configuration file is in the form of a TOML file. Configuration sections are named, |
9 | 10 | 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 | +Sections inherit parameter values from preceeding sections and can override them as well. |
11 | 12 | Loggers can be constructed by providing the name of a section. |
12 | 13 |
|
13 | | -### Example configuration |
| 14 | +[Here](example.toml) is what a configuration that allows logging to several types of loggers may look like. |
| 15 | + |
| 16 | +## Plugging in a Logger |
| 17 | + |
| 18 | +Support for a logger can be added by providing an implementation of `LogCompose.logcompose` for the target logger type. |
| 19 | +The implementation needs to be of the following form: |
| 20 | + |
| 21 | +```julia |
| 22 | +function LogCompose.logcompose(::Type{MyLoggerType}, |
| 23 | + config::Dict{String,Any}, # config: the entire logging configuration file |
| 24 | + logger_config::Dict{String,Any}) # logger_config: configuration relevant for the |
| 25 | + # section specified to `LogCompose.logger` |
| 26 | + # with the hierarchy flattened out |
| 27 | + # provides support for MyLoggerType in LogCompose |
| 28 | +end |
| 29 | +``` |
| 30 | + |
| 31 | +For complete examples, refer to any of the existing implementations listed below. |
| 32 | + |
| 33 | +## Loggers Supported |
| 34 | + |
| 35 | +LogCompose has in-built support for the loggers provided in the stdlib logging package. |
| 36 | +They are listed below with example configuration sections illustrating parameters they accept. |
| 37 | + |
| 38 | +- Logging.SimpleLogger |
| 39 | + ``` |
| 40 | + [loggers.simple] |
| 41 | + type = "Logging.SimpleLogger" |
| 42 | + # min_level = "Debug" # Debug, Info (default) or Error |
| 43 | + stream = "simple.log" # file to log to |
| 44 | + ``` |
| 45 | +- Logging.ConsoleLogger |
| 46 | + ``` |
| 47 | + [loggers.console] |
| 48 | + type = "Logging.ConsoleLogger" |
| 49 | + # min_level = "Debug" # Debug, Info (default) or Error |
| 50 | + stream = "stdout" # stdout (default), stderr or a filepath |
| 51 | + ``` |
| 52 | +- Logging.NullLogger |
| 53 | + ``` |
| 54 | + [loggers.null] |
| 55 | + type = "Logging.NullLogger" |
| 56 | + ``` |
| 57 | +
|
| 58 | +There are external packages that provide support for a few other types of loggers as well: |
| 59 | +
|
| 60 | +- LoggingExtras: [LoggingExtrasCompose.jl](https://github.com/tanmaykm/LoggingExtrasCompose.jl) |
| 61 | +- LogRoller: [LogRollerCompose.jl](https://github.com/tanmaykm/LogRollerCompose.jl) |
| 62 | +- SyslogLogging: [SyslogLoggingCompose.jl](https://github.com/tanmaykm/SyslogLoggingCompose.jl) |
| 63 | +
|
| 64 | +
|
| 65 | +## Examples |
| 66 | +
|
| 67 | +Here is an example configuration using multiple logger types, from different logging packages. |
14 | 68 |
|
15 | 69 | ```toml |
16 | 70 | [file] |
@@ -46,10 +100,16 @@ type = "LoggingExtras.TeeLogger" |
46 | 100 | destinations = ["file.testapp2", "syslog.testapp2"] |
47 | 101 | ``` |
48 | 102 |
|
49 | | -### Example usage |
| 103 | +And below is a snippet of Julia code that make use of this configuration: |
50 | 104 |
|
51 | 105 | ```julia |
52 | | -julia> using LogCompose, Logging, LogRoller, SyslogLogging, LoggingExtras |
| 106 | +julia> using LogCompose, Logging |
| 107 | + |
| 108 | +julia> using LogRoller, LogRollerCompose |
| 109 | + |
| 110 | +julia> using SyslogLogging, SyslogLoggingCompose |
| 111 | + |
| 112 | +julia> using LoggingExtras, LoggingExtrasCompose |
53 | 113 |
|
54 | 114 | julia> logger1 = LogCompose.logger("testconfig.toml", "testapp1"); |
55 | 115 |
|
@@ -87,30 +147,3 @@ shell> cat /tmp/testapp2.log |
87 | 147 | └ @ Main REPL[15]:2 |
88 | 148 |
|
89 | 149 | ``` |
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 | | -- LogRoler.RollingFileWriterTee |
99 | | -- LogRoller.RollingFileWriter |
100 | | -- SyslogLogging.SyslogLogger |
101 | | - |
102 | | -### Plugging in other Loggers |
103 | | - |
104 | | -Support for a new logger can be added by providing an implementation of `LogCompose.logcompose` for the target logger type. |
105 | | -This can be done in user code or in a package other than LogCompose. The implementation needs to be of the following form: |
106 | | - |
107 | | -```julia |
108 | | -function LogCompose.logcompose(::Type{MyLoggerType}, |
109 | | - config::Dict{String,Any}, # config: the entire logging configuration file |
110 | | - logger_config::Dict{String,Any}) # logger_config: configuration relevant for the |
111 | | - # section specified to `LogCompose.logger` |
112 | | - # with the hierarchy flattened out |
113 | | - # provides support for MyLoggerType in LogCompose |
114 | | -end |
115 | | -``` |
116 | | - |
|
0 commit comments