LoggingExtras.jl icon indicating copy to clipboard operation
LoggingExtras.jl copied to clipboard

Add an example mixing FileLogger and FormatLogger ?

Open BambOoxX opened this issue 4 years ago • 2 comments

I just asked a question on the julia discource about this here, but this may be considered for a documentation improvement too, probably in the "More examples" section. Otherwise, this is very nice work.

BambOoxX avatar May 06 '21 19:05 BambOoxX

I think you probably just want an example of using FormatLogger on a file?

That would indeed be a reasonable example.

It is just FormatLogger(fmt, open("myfile.log", "w"))

We could add that example to the docs. Would be good. Probably also worth documenting that the FileLogger is nothing more than a thin logging sink around a stream.

oxinabox avatar May 06 '21 22:05 oxinabox

It would be possible to define

function FormatLogger(f::Function, file::AbstractString; append=false, kwargs...)
    io = open(file, append ? "a" : "w")
    return FormatLogger(f, io; kwargs...)
end

but perhaps that puts "too much" functionality into the FormatLogger, and might be clearer to just open the file yourself.

fredrikekre avatar May 06 '21 23:05 fredrikekre