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

buffer is not flushed when removing handler #13

Open
kalmarek opened this issue Mar 16, 2017 · 3 comments
Open

buffer is not flushed when removing handler #13

kalmarek opened this issue Mar 16, 2017 · 3 comments

Comments

@kalmarek
Copy link

I have the following usecase:

logger = basic_config("info")
add_handler(logger, DefaultHandler("temp.log"), "file-log")
info(logger, "some message")
out = STDOUT
err = STDERR
redirect_stdout(logger.handlers["file-log"].io)
redirect_stderr(logger.handlers["file-log"].io)
# run some calls to c libs which produce stuff to stdout (the stuff I want to capture in logfile)
remove_handler(logger, "file-log")
redirect_stdout(out)
redirect_stderr(err)

Messages are periodically flushed to temp.log, (asserted by tailfing it), however last lines are lost??
I tried flush(logger.handlers["file-log"].io) and info(solver_logger, "Finished!") just before the handler is removed to force it to flush the buffer, to no avail...

btw. is there a way to decrease time between flushes??

@kalmarek
Copy link
Author

ok, so I figured it out: it's a matter of redirect_std|out|err:
Just before redirect_stdout(out) You need to call Base.Libc.flush_cstdio() to flush all C-buffers;

@rofinn
Copy link
Member

rofinn commented Mar 19, 2017

Hmmm, that does seem like pretty awkward behaviour. Given that this appears to be more of a problem with base julia, it might be worth opening an issue here, or modifying the redirect_* methods to include the call to Base.Libc.flush_cstdio() and opening a PR.

@kalmarek
Copy link
Author

Yeah, I found also this:
JuliaLang/julia#8765
I am not proficient enough to try to solve it...

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

2 participants