Log4cpp usage Problems

Source: Internet
Author: User
Log4cpp usage problems-general Linux technology-Linux programming and kernel information. The following is a detailed description. // FileName: test_log4cpp1.cpp
// Test log4cpp by manual operation.
// Announce: use as your own risk.
// Compile: g ++-otest1-llog4cpp test_log4cpp1.cpp
// Run:./test1
// Tested: RedHat 7.2 log4cp1_3.4b
// Author: liqun (liqun@nsfocus.com)
// Data: 2003-6-27
# Include "log4cpp/Category. hh"
# Include "log4cpp/FileAppender. hh"
# Include "log4cpp/BasicLayout. hh"
Int main (int argc, char * argv [])
{
// 1 instantiate a layout object
Log4cpp: Layout * layout =
New log4cpp: BasicLayout ();
// 2. Initialize an appender object
Log4cpp: Appender * appender = new
Log4cpp: FileAppender ("FileAppender ",
"./Test_log4cpp1.log ");
// 3. Attach the layout object to the appender object
Appender-> setLayout (layout );
// 4. instantiate a category object
Log4cpp: Category & warn_log =
Log4cpp: Category: getInstance ("mywarn ");
// 5. Set additivity to false to replace the existing appender
Warn_log.setadditi.pdf (false );
// 5. Attach the appender object to the category
Warn_log.setAppender (appender );
// 6. Set the category priority. logs with a lower priority are not recorded.
Warn_log.setPriority (log4cpp: Priority: WARN );
// Record some logs
Warn_log.info ("Program info which cannot be wirten ");
Warn_log.debug ("This debug message will fail to write ");
Warn_log.alert ("Alert info ");
// Other logging methods
Warn_log.log (log4cpp: Priority: WARN, "This will be a logged warning ");
Log4cpp: Priority: PriorityLevel priority;
Bool this_is_critical = true;
If (this_is_critical)
Priority = log4cpp: Priority: CRIT;
Else
Priority = log4cpp: Priority: DEBUG;
Warn_log.log (priority, "Importance depends on context ");

Warn_log.critStream () <"This will show up <"
<1 <"critical message"
<Log4cpp: CategoryStream: ENDLINE;
// Clean up and flush all appenders
Log4cpp: Category: shutdown ();
Return 0;
}

==================
The above is the sample code for learning log4cpp from the Internet.
During g ++ compilation, the error "ENDLINE is not a member of CategoryStream" is reported.
The file time is relatively early, and I use the 1.0 library.
Please be familiar with the guidance of log4cpp talents. Thank you!

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.