-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
re: file-event-handlers, async loggers and dist-sink: what am I doing wrong? #3200
Comments
As far as I can see there are two problems.
|
I have sidestepped the error for now, although I don't think it was related to that. |
No other obvious problems are found in the code provided. |
I think the latter may have been the case, because the way I sidestepped it is, instead of adding an |
Maybe duplicate #2113 |
After my question re: having a "subsystem"/"context" name for my logs, I decided to give a whirl to just having one logger for each subsystem, so I can use the logger name.
So, I'm constructing my logger class as follows:
Since creating loggers is theoretically cheap, but accessing the registry not so much, I decided to have my own in-class registry, in the form of an unordered map.
The way I thought it up is the following: I have a getLogger function (code attached below) that looks loggers up in its own registry and returns a
shared_ptr
if found. If not found, it looks it up in the spdlog registry. If It finds them, it adds it to the in-class registry and returns the pointer. If not found, it creates and registers the logger with spdlog, then it adds it to the in-class registry and returns the pointer.It looks like this:
One thing to note, the
warn
function in the constructor above is not spdlog's but rather a shortcut to a log function I wrote, as follows:The problem? I get a segfault, apparently caused by the
before_open
file-handler (If I comment that handler out, the sink is created without issue)Here's a backtrace of that crash:
Now, I thought maybe it could have been some sort of race-condition between creating the sink, the logger, opening the file and writing that first message to it, which is why I modified the code slightly to the version I pasted above (If you look closely, you'll see the backtrace is from a slightly different version). In this newer iteration, I decided to try to construct the
dist_sink
first, and construct theLOGGER
logger which would be used on that event handler. After both of those are done, I construct the console and file sinks, and add them to the dist-sink usingadd_sink
.By doing it in this way, I manage to get the
after-close
text on my console, before, once again, getting a segfault.Can you spot what the issue might be?
The text was updated successfully, but these errors were encountered: