@@ -81,7 +81,7 @@ logger = global_logger()
81
81
82
82
83
83
# Loggers introduced by this package:
84
- This package introduces 6 new loggers.
84
+ This package introduces 7 new loggers.
85
85
The ` TeeLogger ` , the ` TransformerLogger ` , 3 types of filtered logger, and the ` FileLogger ` .
86
86
All of them just wrap existing loggers.
87
87
- The ` TeeLogger ` sends the logs to multiple different loggers.
@@ -91,6 +91,7 @@ All of them just wrap existing loggers.
91
91
- The ` EarlyFilteredLogger ` lets you write filter rules based on the ` level ` , ` module ` , ` group ` and ` id ` of the log message
92
92
- The ` ActiveFilteredLogger ` lets you filter based on the full content
93
93
- The ` FileLogger ` is a simple logger sink that writes to file.
94
+ - The ` DatetimeRotatingFileLogger ` is a logger sink that writes to file, rotating logs based upon a user-provided ` DateFormat ` .
94
95
95
96
By combining ` TeeLogger ` with filter loggers you can arbitrarily route log messages, wherever you want.
96
97
@@ -290,6 +291,30 @@ It can also be used to do things such as change the log level of messages from a
290
291
Or to set common properties for all log messages within the `with_logger` block,
291
292
for example to set them all to the same `group`.
292
293
294
+ ## `DatetimeRotatingFileLogger`
295
+ Use this sink to rotate your logs based upon a given `DateFormat`, automatically closing one file and opening another
296
+ when the `DateFormat` would change the filename. Note that if you wish to have static portions of your filename, you must
297
+ escape them so they are not interpreted by the `DateFormat` code. Example:
298
+
299
+ ``` julia
300
+ julia> using Logging, LoggingExtras
301
+
302
+ julia> rotating_logger = DatetimeRotatingFileLogger (pwd (), raw " \a\c\c\e\s\s -YYYY-mm-dd-HH-MM-SS.\l\o\g " );
303
+
304
+ julia> with_logger (rotating_logger) do
305
+ @info (" This goes in one file" )
306
+ sleep (1.1 )
307
+ @info (" This goes in another file" )
308
+ end
309
+
310
+ julia> filter (f -> endswith (f, " .log" ), readdir (pwd ()))
311
+ 2 - element Array{String,1 }:
312
+ " access-2020-07-13-13-24-13.log"
313
+ " access-2020-07-13-13-24-14.log"
314
+ ```
315
+
316
+ The user implicitly controls when the files will be rolled over based on the `DateFormat` given.
317
+
293
318
# More Examples
294
319
295
320
## Filter out any overly long messages
0 commit comments