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

Flush log output for info and higher level #527

Merged
merged 1 commit into from
Dec 24, 2023

Conversation

maxberger
Copy link
Contributor

This is required for docker; without flushing, log outputs to stdout are not written immediately, causing confusion (e.g. only errors on startup)

@maxberger
Copy link
Contributor Author

Note: The failing test is unlelated and fixed in PR #528

@r00t-
Copy link
Contributor

r00t- commented Aug 22, 2022

do we really want to do this unconditionally?

@r00t-
Copy link
Contributor

r00t- commented Sep 18, 2022

would running with docker -t be a working/acceptable solution?
how do other projects handle this in dockerized services?
it would seem sensible to flush after messages of some minimum log-level, but i.e. not for every debug message.

@maxberger
Copy link
Contributor Author

Addressed the original comment by adding a config option to enable this conditionally. I never had this problem with other dockerized services, but they usually use an existing log library, which does everything. Only in the case of vzlogger I was not gettting any output until I started adding the flush.

@r00t-
Copy link
Contributor

r00t- commented Feb 8, 2023

can you add that parameter to the example vzlogger.conf?

@J-A-U
Copy link
Collaborator

J-A-U commented Feb 9, 2023

I would prefer to not add more (unnecessary?) options to the configuration. Therefore my question:
Is there a reason not to make this behavior standard?

@r00t-
Copy link
Contributor

r00t- commented Feb 9, 2023

@J-A-U:
flushing after every message causes unnecessary (disk-)i/o,
specifically when running on a flash filesystem (raspberry pi) one would want to avoid this. (not sure how flush() relates to sync(), but still the buffering is there for a reason.)
i.e. when setting the loglevel to debug, one will want the buffering to avoid extra cpu load.

i suggested the alternative to flush() by default but only for messages of some minimum level. (as in, for errors but not for debug.)
i also asked how other applications handle this. i'm not sure, but i'm pretty sure it's not best-practice to unconditonally flush after every single message.

this whole thing doesn't seem a bg priority to me, as i don't think many people will run vzloger in docker. and systemd doesn't seem to have the same issue, at least it was not reported. (or nobody uses it for logging yet? :\ )

@maxberger
Copy link
Contributor Author

Here is another post also mentioning the without issue with docker logs, and doing more deep dives:

https://stackoverflow.com/questions/36217674/docker-logs-and-buffered-output (6 years old)

Looks like it is dependent on the docker log driver, so not everyone encounters it.

Flushing for everything >= info would also work, and re-simplify this patch.

I am happy to provide which ever solution you decide on. My goal is to see these messages immediately on my setup, ideally with using upstream. So I can either add update the sample (as requested above), or roll back to flush, but then would use everything >= Info

What would you prefer?

@maxberger
Copy link
Contributor Author

There is also another option: Use an existing logging library (though that would introduce another dependency, but it would also make the code simpler). I can also prepare a patch for that if you like.

I did a test with python and docker - using "print" statements the log output was delayed, using logger.info statements the output was there immediately. So this issue is not specific to vzlogger or C++

@r00t-
Copy link
Contributor

r00t- commented Feb 20, 2023

Here is another post also mentioning the without issue with docker logs, and doing more deep dives:
https://stackoverflow.com/questions/36217674/docker-logs-and-buffered-output (6 years old)

thanks, that's exactly the kind of research i had asked for in #527 (comment)

@r00t-
Copy link
Contributor

r00t- commented Feb 20, 2023

@maxberger:
i'd personally accept either:

  • the config-option (as in this MR now), with an example in etc/vzlogger.conf that points it out as useful for docker users (nobody will use an option documented only in the sourcecode)
  • or flushing depending on loglevel (that was my initial suggestions for improvement)

@maxberger maxberger changed the title Flush log output after every statement Flush log output for info and higher level Apr 8, 2023
@maxberger
Copy link
Contributor Author

Updated. Now flushed only for level input and higher.

@r00t-
Copy link
Contributor

r00t- commented Dec 24, 2023

not sure why this is not merged yet,
sorry for the delay and thanks for your contribution.

@r00t- r00t- merged commit 5188375 into volkszaehler:master Dec 24, 2023
2 checks passed
max-te pushed a commit to max-te/nix-flake-vzlogger that referenced this pull request Dec 24, 2023
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

Successfully merging this pull request may close these issues.

3 participants