plog
plog copied to clipboard
Have option to set the logger id during run time and not just compile time.
Im at a stage where i need to use multiple copies of a lib that uses Plog. Problem is that since Plog takes ids at compile time, when the libs are running, they all share the same logging ids and log to the same file. To fix this i need to compile each lib with a new id.
I think it would be an improvement if plog could somehow be able to use logger ids during runtime like taking the logger id as a parameter in its init instead of using template parameters. That way i can pass the ids and set up each lib with a different id during runtime.
It seems to be related to #178.
Do you use static libs?
No, dlls for windows and .so for linux.
It seems to be related to https://github.com/SergiusTheBest/plog/issues/178.
Oh yea, this is exactly the problem for me too, i guess i will close this issue then?
Let the issue be open for now.
Shared (dynamic) libraries are isolated from each other (however on Linux it depends on compiler options, you can explicitly specify the behavior). So you can reuse the same ids. Unless you have logging in inline functions in public headers.
Ahh, i see why you asked. Yes on windows, as long as we make unique metadata for the dll before compiling, when loading the dll it will load each one uniquely and the "global state" of the dll will remain isolated from each other and log to separate log files. It works by default without adding macros, at least for us.
I expected similar behaviour for Linux but looks like while Linux does load unique instances of the .so, they are all loaded into a shared "global space" and therefore seem to log to the same log file even though they were told to have different files names. I tested this by compiling 2 versions of the .so with different logging ids defined and they then wrote separate log files.
The Macro section that you linked seems like it should solve this problem but i am having no luck with getting it to work, i probably dont understand how to use it. I have included it in the pre-processor definitions for the project in VS and also did a #define PLOG_LOCAL
in one of the header files but neither did anything and they continue to log to the same log file.
Yes, PLOG_LOCAL
should isolate .so files and fix your issue. Did you set the pre-processor definitions for all .so projects?
Well, the thing is that there is only 1 .so file that is copied multiple times. Long story why that is. Basically its the same .so file (compiled once) that is copy pasted and renamed to all have different names, then loaded one by one into another c++ app using dlopen()
.
I see. And you generate log file name according to .so name?
Thats correct. The lib has an init function that takes in the name it will use for the plog output file. The lib loader will loop over the number of libs it will need and inits it with its own name suffixed with the id and "_log.txt".
Again, i did a test where i compiled the same lib with only the global plog instance id changed and i got 2 different log files. I can in theory fix it like this but i need to do this for 40 libs and i need to do it every time there is a change and we want to test the change in the lib loader app. So a pretty gruelling process.
Do you think https://github.com/SergiusTheBest/plog/issues/178 will solve my problem? I took a quick look at the sample example but dont yet understand how it works and if it would work with multiple loggers in one lib. You see we have 3 loggers per lib that collect related logging into separate files to not clutter the other logs.
Yes, #178 will help you as you're in full control of logger instance visibility. I'll update documentation and samples (expect it ready next week).
Meanwhile could you prepare a minimal sample of your code to demonstrate the issue? I'd like to investigate why PLOG_LOCAL
didn't work for you.
Awesome, thank you!
I have prepared a sample project that shows the issue, it can be found here: https://github.com/JoelSatkas/PlogIssueSampleCode
Its quick and dirty but its roughly what my real project has, a lib using plog that is copy pasted multiple times and multiple instances are loaded into the lib runner. I have left instructions in the read me but if you have any questions or need clarification, feel free to ask but since im taking a holiday i probably wont respond for about a week.
Thank you for your help and clarifications!
@JoelSatkas It seems that https://github.com/JoelSatkas/PlogIssueSampleCode is a private repo. It returns 404 for me.
Oh your right, sorry for that. It should now be public.
@JoelSatkas Yes, now it's good.
@JoelSatkas I'm able to fix the issue. Just need to run some checks on Windows.
Thats great news Sergey, thank you!
@JoelSatkas Your issue is fixed by #219. First of all you need to update plog to the latest master. Your existing 1.1.5 doesn't support PLOG_LOCAL
(note that you need to include plog/Initializers/RollingFileInitializer.h
instead of plog/Init.h
in newer versions). Then define PLOG_LOCAL
in project settings (or before including plog). And each SO file will have its own logger with its own file name as you wanted.
@JoelSatkas Also I've added the NotShared sample to demonstrate your use case.
Thank you @SergiusTheBest. I tried it and it does indeed resolve my issue and all i needed to do was include that Initializer header. Can I ask if you know when the next release of plog will be? I would rather use a released version than a commit on master.
Actually you can use the latest released version (1.1.8) and set -fvisibility=hidden
compiler option for you SO files (in Visual Studio this is Symbols Hidden By Default option).
The next release will be within 2 months.
A new release is ready!