Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mix the formatting of ConsoleLogger with FileLogger #60

Open
HumpyBlumpy opened this issue Mar 30, 2022 · 4 comments
Open

Mix the formatting of ConsoleLogger with FileLogger #60

HumpyBlumpy opened this issue Mar 30, 2022 · 4 comments

Comments

@HumpyBlumpy
Copy link

Hello,

I want to output ConsoleLogger to a file. Is it possible?
From the documentation, I first tried using FileLogger. This worked, but outputted too much information (a whole line with the source code location). So next I tried the example from the documentation :

logger = FormatLogger(open("logfile.txt", "w")) do io, args
    println(io, args._module, " | ", "[", args.level, "] ", args.message)
end;

This was better, but not as nice as ConsoleLogger (and was missing some information in some cases).
So basically, I think ConsoleLogger is perfect and I just want to output the same information with the same formatting to a file.

@fredrikekre
Copy link
Member

You can pass an open file handle to the ConsoleLogger.

@HumpyBlumpy
Copy link
Author

How do I make use of LoggingExtras in such a case?
The main thing I want out of it is the automatic flushing. I want the log to be continuously updated, not only at the end of the execution of the file.

@oxinabox
Copy link
Member

This is not currently possible.
I guess we could make a forced flushing wrapper logger.
I kind a feel like that should be handled at the stream level though.
Or the OS level?

@fredrikekre
Copy link
Member

It would be nice to have FormatLogger (and SimpleLogger) formatting available in https://github.com/JuliaLogging/LoggingFormats.jl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants