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 stdout logs #2669

Merged
merged 1 commit into from
Jun 29, 2021
Merged

flush stdout logs #2669

merged 1 commit into from
Jun 29, 2021

Conversation

arnetheduck
Copy link
Member

else pipes end up not getting log output until much later

else pipes end up not getting log output until much later
@cheatfate
Copy link
Contributor

Because we are printing to stdout in sync mode this will slowdown all the process if DEBUG level is going to be used, so if this really needed i prefer to make it hidden under compilation flag and not enabled by default.

@github-actions
Copy link

github-actions bot commented Jun 22, 2021

Unit Test Results

     28 files  ±0     328 suites  ±0   16m 40s ⏱️ ±0s
   631 tests ±0     613 ✔️ ±0    18 💤 ±0  0 ❌ ±0 
3 452 runs  ±0  3 348 ✔️ ±0  104 💤 ±0  0 ❌ ±0 

Results for commit cc8f7c2. ± Comparison against base commit cc8f7c2.

♻️ This comment has been updated with latest results.

@stefantalpalaru
Copy link
Contributor

Aren't we already flushing stdout here? https://github.com/status-im/nim-chronicles/blob/8b1419b4a37a3a8995a9a0a992b4705427056d98/chronicles.nim#L317

Worth checking the C output.

@arnetheduck
Copy link
Member Author

It's a noop for the dynamic output: https://github.com/status-im/nim-chronicles/blob/63ce43a86a40a4c73d1b3b8317278d47ec55a458/chronicles/log_output.nim#L384

Also, the effect is plainly visible before and after (ie pipe through grep and look at the timestamps of first logs from startup vs how they appear on screen)

@mratsim
Copy link
Contributor

mratsim commented Jun 23, 2021

Because we are printing to stdout in sync mode this will slowdown all the process if DEBUG level is going to be used, so if this really needed i prefer to make it hidden under compilation flag and not enabled by default.

I agree, but debug mode implies perf implications anyway.

stdout.write msg
render statusBar
# p.showPrompt
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this false branch taken? Since a DynamicOutput implies a BufferedOutput in Chronicles, only complete log lines are supposed to reach here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

someone mentioned it as a possibility so I added the extra protection..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but looking at the data that comes here, it's indeed the case that only full log lines make it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be more clean if chronicles had a flush call as well for the dynamic output

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean a flush callback? The dynamic output is entirely application-specific. Some applications may decide to use a custom logging UI, other will send the data over the network, etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you mean it's part of the API of the dynamic output that only fully preformatted lines are ever given? even if they're significantly long etc?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ie your comment BufferedOutput sounds more like an implementation detail than a guarantee

Copy link
Contributor

@zah zah Jun 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, this assumption is part of the API. This simplifies the problem for the user in two ways:

  1. No need to buffer the partial messages on your own
  2. No need to implement a separate flush call. You can flush in your single-message callback if you wish.

I believe the usage here is a real-world example for this simplification actually. Due to some complications in the way erase statusBar works, I think the code wouldn't produce the desired effect if partial messages were being pushed.

@bauerj
Copy link
Contributor

bauerj commented Jun 25, 2021

Because we are printing to stdout in sync mode this will slowdown all the process if DEBUG level is going to be used, so if this really needed i prefer to make it hidden under compilation flag and not enabled by default.

Maybe it would make sense to use a timer to only flush when it hasn't been done in the last few hundred milliseconds or so?

This is a real problem: When restarting, I don't see any log output in the systemd journal for a few minutes which initially made me suspect something was broken.

try:
stdout.write(msg)
if msg[^1] == '\n':
stdout.flushFile()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR can be reduced to include only this call to flushFile (it will be unconditional)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incidentally, that's what the first commit does

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arnetheduck
Copy link
Member Author

reverted back to commit that just simply flushes since it's only called ones per log message anyway

@arnetheduck arnetheduck reopened this Jun 28, 2021
@zah zah merged commit cc8f7c2 into unstable Jun 29, 2021
@zah zah deleted the flush-stdout branch June 29, 2021 13:53
arnetheduck added a commit that referenced this pull request Jul 7, 2021
else pipes end up not getting log output until much later
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.

6 participants