Skip to content
This repository has been archived by the owner on Mar 20, 2024. It is now read-only.

Solve completeness issue regarding closed contexts or applications exiting #18

Open
benjivesterby opened this issue Jan 11, 2021 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@benjivesterby
Copy link
Member

When a context is closed the current implementation will exit out of all logging without draining the channel first. This can cause logs to be lost because they are not pulled prior to exiting.

Each channel should be monitored using something like len of the channel to ensure that all logs are drained prior to exiting the logger. Obviously, this doesn't solve the case where the application is closed, but perhaps an option should be added to monitor for an os signal and drain remaining logs when that happens.

@benjivesterby benjivesterby added the bug Something isn't working label Jan 11, 2021
@benjivesterby benjivesterby self-assigned this Jan 11, 2021
@benjivesterby
Copy link
Member Author

A possible way to to do this is wait for a ctx.Done to return then

for len(chan) > 0 {
  ... drain channel
close the channel
return
}

in the Wait() method

 <-ctx.Done()
for log destinations {
 <- destination close channels... 
}

This would ensure the logger doesn't exit until all the channels have been drained and closed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant