Skip to content

Commit 2ee741e

Browse files
committed
Add README documenting DatetimeRotatingFileLogger
1 parent 8f81a52 commit 2ee741e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ logger = global_logger()
8181

8282

8383
# Loggers introduced by this package:
84-
This package introduces 6 new loggers.
84+
This package introduces 7 new loggers.
8585
The `TeeLogger`, the `TransformerLogger`, 3 types of filtered logger, and the `FileLogger`.
8686
All of them just wrap existing loggers.
8787
- The `TeeLogger` sends the logs to multiple different loggers.
@@ -91,6 +91,7 @@ All of them just wrap existing loggers.
9191
- The `EarlyFilteredLogger` lets you write filter rules based on the `level`, `module`, `group` and `id` of the log message
9292
- The `ActiveFilteredLogger` lets you filter based on the full content
9393
- 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`.
9495

9596
By combining `TeeLogger` with filter loggers you can arbitrarily route log messages, wherever you want.
9697

@@ -290,6 +291,30 @@ It can also be used to do things such as change the log level of messages from a
290291
Or to set common properties for all log messages within the `with_logger` block,
291292
for example to set them all to the same `group`.
292293
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+
293318
# More Examples
294319
295320
## Filter out any overly long messages

0 commit comments

Comments
 (0)