Copyright Notice
Respect Original Works. Reprinted, please maintain the integrity of the article, and in the form of a hyperlink to indicate the original author "tingsking18" and the main site address, so that other friends can ask and correct.
After encapsulating log4cplus, the row number cannot be recorded. When using log4cplus, % L is configured in the configuration file, which is the file and row number where the log information is recorded. We can directly record log4cplus_error (logger, logmsg. In this way, the log information contains the file and row number of our log information. But sometimes we may need to encapsulate log4cplus. The encapsulated code may look like the following: void _ logerror (const char * FMT ,...) {char logmsg [4096]; intstrlen; memset (logmsg, 0x00, sizeof (logmsg); va_listap; va_start (AP, FMT); strlen = vsprintf (logmsg, FMT, AP); va_end (AP); log4cplus_error (logger, logmsg); return;} but in this case, the file name and row number of the log information record are the file where _ logerror is located and log4cplus_error (logger, logmsg); the row number. In this way, we cannot achieve what we want. 2010-01-06 00:52:30 [test. CPP: 47]-> ======================================== ======================================== 00:52:30 [test. CPP: 47]-> XXXXX log 2010-01-06 00:52:30 [test. CPP: 47]-> ======================================== ======================================== 00:52:30 [test. CPP: 47]-> when the program starts, there are two global variables: char * filename; int line; then define a macro: # define logerror filename =__ file __, line =__ line _ _, _ Logerror: Change log4cplus_error (logger, logmsg) in the _ logerror function to logger. Log (error_log_level, logmsg, filename, line. 2010-01-06 00:52:43 [test. CPP: 60]-> ========================================== ======================================== 00:52:43 [test. CPP: 61]-> XXXXX log 2010-01-06 00:52:43 [test. CPP: 62]-> ========================================== ======================================== 00:52:43 [test. CPP: 63]-> the program starts to start, but the above situation only applies to a single thread. If you want to use a multi-threaded environment, you can implement filename and line as functions, just like the implementation of errno in multi-thread scenarios, where thread specific data is used.