|
1 | 1 | using Dates
|
2 |
| -import Base: isless |
3 | 2 |
|
4 | 3 | raw"""
|
5 | 4 | DatetimeRotatingFileLogger(dir, file_pattern; always_flush=true, rotation_callback=identity)
|
6 | 5 | DatetimeRotatingFileLogger(f::Function, dir, file_pattern; always_flush=true, rotation_callback=identity)
|
7 | 6 |
|
8 | 7 | Construct a `DatetimeRotatingFileLogger` that rotates its file based on the current date.
|
9 |
| -The constructor takes a log output directory, `dir`, and a filename pattern. |
10 |
| -The filename pattern given is interpreted through the `Dates.format()` string formatter, |
11 |
| -allowing for yearly all the way down to minute-level log rotation. Note that if you |
12 |
| -wish to have a filename portion that is not interpreted as a format string, you may need |
13 |
| -to escape portions of the filename, as shown in the example below. |
| 8 | +The constructor takes a log output directory, `dir`, and a filename pattern. The smallest |
| 9 | +time resolution in the format string determines the frequency of log file rotation, |
| 10 | +allowing for yearly all the way down to minute-level log rotation. |
| 11 | +
|
| 12 | +The pattern can be given as a string or as a `Dates.DateFormat`. Note that if you |
| 13 | +wish to have a filename portion that should not be interpreted as a format string, you may |
| 14 | +need to escape portions of the filename, as shown in the example below. |
14 | 15 |
|
15 | 16 | It is possible to pass a formatter function as the first argument to control the output.
|
16 | 17 | The formatting function should be of the form `f(io::IOContext, log_args::NamedTuple)`
|
@@ -61,9 +62,10 @@ function DatetimeRotatingFileLogger(f::Union{Function,Nothing}, dir, filename_pa
|
61 | 62 | else # f isa Function
|
62 | 63 | FormatLogger(f, IOBuffer(); always_flush=false) # no need to flush twice
|
63 | 64 | end
|
| 65 | + filename_pattern isa DateFormat || (filename_pattern = DateFormat(filename_pattern)) |
64 | 66 | # abspath in case user constructs the logger with a relative path and later cd's.
|
65 | 67 | drfl = DatetimeRotatingFileLogger(logger, abspath(dir),
|
66 |
| - DateFormat(filename_pattern), now(), always_flush, ReentrantLock(), nothing, rotation_callback) |
| 68 | + filename_pattern, now(), always_flush, ReentrantLock(), nothing, rotation_callback) |
67 | 69 | reopen!(drfl)
|
68 | 70 | return drfl
|
69 | 71 | end
|
|
0 commit comments