Hello,
I am using log4cpp in two different Windows dlls. The problem is that the logging data from each ends up being put into both log files. SO I end up with all of dll1's logs in dll2's logfile and vice-versa.
This is the code I use t osetup logging:
void dll1::setupLogging(log4cpp::Priority::PriorityLevel priority)
{
// Setup logging
// 1 instantiate an appender object that
// will append to a log file
log4cpp::Appender* app = new
log4cpp::FileAppender("FileAppender",
"..\\logs\\dll1.log");
// 2. Instantiate a layout object
// Two layouts come already available in log4cpp
// unless you create your own.
// BasicLayout includes a time stamp
log4cpp::Layout* layout =
new log4cpp::BasicLayout();
// 3. attach the layout object to the
// appender object
app->setLayout(layout);
// 4. Step 1
// an Appender when added to a category becomes
// an additional output destination unless
// Additivity is set to false when it is false,
// the appender added to the category replaces
// all previously existing appenders
main_cat.setAdditivity(false);
// 4. Step 2
// this appender becomes the only one
main_cat.setAppender(app);
// 5. Set up the priority for the category
// and is given INFO priority
// attempts to log DEBUG messages will fail
main_cat.setPriority(priority);
}
dll2 has the same function except for the name of the file being changed.
Both files are created but end up being exactly the same.
Can anybody give any help?
Regards,
David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In order to log to one file, you must create a global category that both dll can access. One way is to put the log4cpp startup code in a dll and export the gloabl category. Another way is export the category in one of the existing dlls and have the other reference to the first one.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I am using log4cpp in two different Windows dlls. The problem is that the logging data from each ends up being put into both log files. SO I end up with all of dll1's logs in dll2's logfile and vice-versa.
This is the code I use t osetup logging:
void dll1::setupLogging(log4cpp::Priority::PriorityLevel priority)
{
// Setup logging
// 1 instantiate an appender object that
// will append to a log file
log4cpp::Appender* app = new
log4cpp::FileAppender("FileAppender",
"..\\logs\\dll1.log");
// 2. Instantiate a layout object
// Two layouts come already available in log4cpp
// unless you create your own.
// BasicLayout includes a time stamp
log4cpp::Layout* layout =
new log4cpp::BasicLayout();
// 3. attach the layout object to the
// appender object
app->setLayout(layout);
// 4. Step 1
// an Appender when added to a category becomes
// an additional output destination unless
// Additivity is set to false when it is false,
// the appender added to the category replaces
// all previously existing appenders
main_cat.setAdditivity(false);
// 4. Step 2
// this appender becomes the only one
main_cat.setAppender(app);
// 5. Set up the priority for the category
// and is given INFO priority
// attempts to log DEBUG messages will fail
main_cat.setPriority(priority);
}
dll2 has the same function except for the name of the file being changed.
Both files are created but end up being exactly the same.
Can anybody give any help?
Regards,
David
In order to log to one file, you must create a global category that both dll can access. One way is to put the log4cpp startup code in a dll and export the gloabl category. Another way is export the category in one of the existing dlls and have the other reference to the first one.