Log output format for custom Log4cpp

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.