Configure, install, and test the log4cplus log tool in Linux

Source: Internet
Author: User

Configure, install, and test the log4cplus log tool in Linux

Log4cplus is an open-source log system written in C ++ with comprehensive functions. log4plus is used for the first time. The following describes how to configure, install, and test log4cplus in Linux.

1. Introduction to log4cplus

Log4cplus is an open-source log system written in C ++. Its predecessor is the log4j system written in java, which is protected by Apache Software License. The author is Tad E. Smith. Log4cplus has the features of thread security, flexibility, and multi-granularity control. By dividing information into priorities, log4cplus can face the entire life cycle of program debugging, running, testing, and maintenance; you can choose to output the information to the screen, file, NT event log, or even remote server, and regularly back up the log by specifying a policy.

2. Download log4cplus

The latest log4cplus can be downloaded from the following URL.

Log4cplus: http://sourceforge.net/projects/log4cplus/

Run the following command to install RedHat in Linux:

Wget http://sourceforeg.net/projects/log4cplus/files/log4cplus-stable/1.1.2/log4cplus-x.x.x.tar.gz

3. log4cplus Installation

Tar xvzf log4cplus-x.x.x.tar.gz

Cd log4cplus-x.x.x

./Configure

Make

Make install

4. log4cplus Configuration

By default, log4cplus is installed in the/usr/local/include/log4cplus header file path. The installation file path of the library file is/usr/local/lib. Edit the. bash_profile file to add the library file.

$ Vi ~ /. Bash_profile

Add:

LD_LIBRARY_PATH = LD_LIBRARY_PATH:/usr/local/lib

Export LD_LIBRARY_PATH

Source ~ /. Make the change take effect

$ Vi/etc/profile

Add:

CPLUS_INCLUDE_PATH = LD_LIBRARY_PATH:/usr/local/lib

Export CPLUS_INCLUDE_PATH

Source ~ /. Make the change take effect

5. Test

# Include <log4cplus/logger. h>
# Include <log4cplus/aggregator. h>
# Include <iomanip>
# Include <log4cplus/logger. h>
# Include <log4cplus/fileappender. h>
# Include <log4cplus/leleappender. h>

# Include <log4cplus/loggingmacros. h>
# Include <log4cplus/layout. h>
# Include <time. h>
Using namespace std;
Using namespace log4cplus;
Logger pTestLogger;

Void writelog (char * leval, char * info)
{
Struct tm * p;
Time_t lt = time (NULL );
P = localtime (<);
Char * timetemp = ctime (<);
* (Timetemp + strlen (timetemp)-1) = '\ 0 ';
Char temp [10000];
Sprintf (temp, "[% s] % s", timetemp, info );
Printf ("temp = % s", temp );
Printf ("leval ===% s \ n", leval );
If (memcmp (leval, "TRACE", 5) = 0)
Printf ("% d = % d", memcmp ("TRACE", "TRAC1E", 5), memcmp (leval, "TRACE", 5 ));
LOG4CPLUS_TRACE (pTestLogger, temp );
If (memcmp (leval, "DEBUG", 5) = 0)
LOG4CPLUS_DEBUG (pTestLogger, temp );
If (memcmp (leval, "INFO", 4) = 0)
LOG4CPLUS_INFO (pTestLogger, temp );
If (memcmp (leval, "WARN", 4) = 0)
LOG4CPLUS_WARN (pTestLogger, temp );
If (memcmp (leval, "ERROR", 5) = 0)
LOG4CPLUS_ERROR (pTestLogger, temp );
If (memcmp (leval, "FATAL", 5) = 0)
LOG4CPLUS_FATAL (pTestLogger, temp );
}
Int main ()
{
Char * info = "you have a iuns ";
Char filename [50];
Struct tm * p;
Time_t lt = time (NULL );
P = localtime (<);
Sprintf (filename, "Your d-0000d-0000d.txt", (1900 + p-> tm_year), (1 + p-> tm_mon), p-> tm_mday );
FILE * stream = fopen (filename, "wb ");
SharedAppenderPtr pFileAppender (new FileAppender (filename )));
PTestLogger = Logger: getInstance ("LoggerName "));
PTestLogger. addAppender (pFileAppender );
Writelog ("TRACE", info );
Writelog ("DEBUG", info );
Writelog ("ERROR", info );
Return 0;
}

Compile command

G ++ filetime. cpp-I/usr/local/log4cplus/include/-L/usr/local/log4cplus/lib-llog4cplus-o filetime

For details about log4cplus, click here
Log4cplus: click here

This article permanently updates the link address:

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.