1. Instantiate a Patternlayout object
Log4cpp::P atternlayout* playout = new log4cpp::P atternlayout ();
2. Instantiate a Rollingfileappender object
log4cpp::rollingfileappender* Rollingappender = new Log4cpp::rollingfileappender ("Rollingfileappender", Path);
Playout->setconversionpattern ("%d:[%t][%05p]%c%x-%m%n");
3. Attaching the Playout object to the Rollingappender object
Rollingappender->setlayout (playout);
4. Instantiate a Category Object
log4cpp::category& Logcat = log4cpp::category::getinstance (catrgory_name);
5. Set additivity to False to replace the existing Appender
Logcat.setadditivity (FALSE);
5. Attach the Appender object to the category
Logcat.setappender (Rollingappender);
6. Set the priority of category, logs below this priority are not logged
Switch (level)
{
Case DebugLevel:
Logcat.setpriority (log4cpp::P riority::D ebug);
Break
Case Infolevel:
Logcat.setpriority (log4cpp::P riority::info);
Break
Case Warnlevel:
Logcat.setpriority (log4cpp::P riority::warn);
Break
Case Errlevel:
Logcat.setpriority (log4cpp::P riority::error);
Break
Default
Logcat.setpriority (log4cpp::P riority::info);
Break
}
Record Start log
Logcat.alert ("-------------Init-------------");
Log output format for custom Log4cpp