Is there a way to create a logger that I can pass in prefix to prepend to a log file name. I would like to be able to pass in a program instance name and have the logger create a log file with that instance name followed by a timestamp and a ".log". I have been able to get the timestamp part just not sure if there is some built in way to pass the instance name.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Loggers have no relation to files, as well as other kinds of sinks. You specify file name when you initialize the corresponding sink. You can create a sink when you create the global logger though, as part of its initialization.
The library does contain the facility to obtain the program executable name, but it is implemented in the form of attribute. See here. You can obtain the name from the attribute value or use argv[0] from the arguments of main or resort to OS-specific methods.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm specifying the filename now as I create the sink, but passing it in through a wrapper function. I cannot use the raw program executable name because we are running multiple instances simultaneously and I want the log file to indicate which instance to log is for.
I am also having trouble logging from a dll. I have built the boost log as a dll and alos compiled my looging code as a dll. I create the logger in the main application and all logs from there are going out to the log file as expected. I then create a class from a second dll and try to send logs from it however they wind up on the console instead of my log file. Both the main app and the second dll are dynamically linking to the logger dll.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cannot use the raw program executable name because we are running multiple instances simultaneously and I want the log file to indicate which instance to log is for.
The best solution is to include pid into the file name. Again, you can obtain it with system-specific calls or from an attribute. The library does not offer helpers for generating file names.
I am also having trouble logging from a dll.
Assuming you only have a file sink installed, I don't see how log records could end up on the console. One possibility is that you start writing logs before you install the sink. Otherwise I can only think that your dll is linked statically with Boost.Log. This may happen if you didn't define BOOST_LOG_DYN_LINK or BOOST_ALL_DYN_LINK when building all your code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is there a way to create a logger that I can pass in prefix to prepend to a log file name. I would like to be able to pass in a program instance name and have the logger create a log file with that instance name followed by a timestamp and a ".log". I have been able to get the timestamp part just not sure if there is some built in way to pass the instance name.
Loggers have no relation to files, as well as other kinds of sinks. You specify file name when you initialize the corresponding sink. You can create a sink when you create the global logger though, as part of its initialization.
The library does contain the facility to obtain the program executable name, but it is implemented in the form of attribute. See here. You can obtain the name from the attribute value or use
argv[0]
from the arguments ofmain
or resort to OS-specific methods.I'm specifying the filename now as I create the sink, but passing it in through a wrapper function. I cannot use the raw program executable name because we are running multiple instances simultaneously and I want the log file to indicate which instance to log is for.
I am also having trouble logging from a dll. I have built the boost log as a dll and alos compiled my looging code as a dll. I create the logger in the main application and all logs from there are going out to the log file as expected. I then create a class from a second dll and try to send logs from it however they wind up on the console instead of my log file. Both the main app and the second dll are dynamically linking to the logger dll.
The best solution is to include pid into the file name. Again, you can obtain it with system-specific calls or from an attribute. The library does not offer helpers for generating file names.
Assuming you only have a file sink installed, I don't see how log records could end up on the console. One possibility is that you start writing logs before you install the sink. Otherwise I can only think that your dll is linked statically with Boost.Log. This may happen if you didn't define
BOOST_LOG_DYN_LINK
orBOOST_ALL_DYN_LINK
when building all your code.