@@ -281,6 +281,9 @@ It is really simple.
281
281
The resulting file format is similar to that which is shown in the REPL.
282
282
(Not identical, but similar)
283
283
284
+ **NOTE**: To print to the file in a specific format, e.g. to create a JSON log, use
285
+ `FormatLogger` instead.
286
+
284
287
### Demo: `TeeLogger` and `FileLogger`
285
288
We are going to log info and above to one file,
286
289
and warnings and above to another.
@@ -349,13 +352,20 @@ in the constructor. See `FormatLogger` for the requirements on the formatter fun
349
352
The `FormatLogger` is a sink that formats the message and prints to a wrapped IO.
350
353
Formatting is done by providing a function `f(io::IO, log_args::NamedTuple)`.
351
354
355
+ `FormatLogger` can take as its second argument either a writeable `IO` or a filepath. The `append::Bool` keyword
356
+ argument determines whether the file is opened in append mode (`"a"`) or truncate mode (`"w"`).
357
+
352
358
``` julia
353
359
julia> using LoggingExtras
354
360
355
361
julia> logger = FormatLogger () do io, args
356
362
println (io, args. _module, " | " , " [" , args. level, " ] " , args. message)
357
363
end ;
358
364
365
+ julia> logger = FormatLogger (" out.log" ; append= true ) do io, args
366
+ println (io, args. _module, " | " , " [" , args. level, " ] " , args. message)
367
+ end ;
368
+
359
369
julia> with_logger (logger) do
360
370
@info " This is an informational message."
361
371
@warn " This is a warning, should take a look."
0 commit comments