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

A way to control which logger is used for signal handling #588

Closed
danmou opened this issue Sep 24, 2024 · 4 comments · Fixed by #589
Closed

A way to control which logger is used for signal handling #588

danmou opened this issue Sep 24, 2024 · 4 comments · Fixed by #589
Labels
enhancement New feature or request

Comments

@danmou
Copy link

danmou commented Sep 24, 2024

Is your feature request related to a problem? Please describe.
I'm using a single global logger for all my regular logging, plus a CSV logger. I'm using quill::Backend::start_with_signal_handler to make the backend catch and log crashes. However, it seems like the signal handler just finds some valid logger (which ends up being the CSV logger in my case) and logs the event there. The result is that I get no sign of the crash in my regular log, while my CSV file gets these lines, which do not adhere to the CSV format:

Received signal: Segmentation fault (signum: 11)
Program terminated unexpectedly due to signal: Segmentation fault (signum: 11)

Describe the solution you'd like
I would like to be able to either mark a specific logger as the one to use for signals, or be able to mark one or more loggers to be excluded from the signal handler.

A nice-to-have would be to flush all loggers in the signal handler and not just the one that the error is logged to.

@odygrd
Copy link
Owner

odygrd commented Sep 24, 2024

Calling flush on a logger actually flushes all loggers up to the current timestamp. The reason this is part of the Logger API is to keep the additional includes minimal—you can log and flush using just Logger.h. For instance, you don't need Frontend.h, which would otherwise be necessary to discover the loggers.

Good catch regarding the CSV logger. The SignalHandler selects the first valid logger from the vector of loggers, which are inserted in the order you create them. As a workaround, if you create the logger you want the segmentation fault error to be logged in before the CSVWriter, that should resolve the issue for now.

I'll make sure to exclude the CSV loggers from handling that error and will also look into adding an option in future versions so you can choose which logger handles the error.

@odygrd odygrd added the enhancement New feature or request label Sep 24, 2024
@odygrd
Copy link
Owner

odygrd commented Sep 24, 2024

It appears that the loggers in the vector are sorted alphabetically by their names. As a result, the SignalHandler will log errors for the first element in this sorted vector. To ensure that the logger you want to log errors for is triggered in the current version, its name needs to be alphabetically first in the vector.

@odygrd
Copy link
Owner

odygrd commented Sep 24, 2024

#590

@odygrd
Copy link
Owner

odygrd commented Sep 26, 2024

This is done on master, you can choose the logger that logs the signal handler error

Backend::start_with_signal_handler<FrontendOptions>(

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

Successfully merging a pull request may close this issue.

2 participants