Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Log4cplus logging facility configuration, installation, testing     - Linux kernel network subsystem analysis (Programming)

- Spark build standalone version cluster (Server)

- Cache implementation APP interacts with the server-side interface control Session (Server)

- CentOS permanently banned from running in the background PackageKit (Linux)

- KVM virtualization of nested virtualization (Linux)

- Linux network cut package is not fully defragment (Linux)

- linux firewall configuration (Linux)

- Ubuntu 14.04 users how to install VLC 2.2.0 (Linux)

- Redis is installed and set up Ubuntu 14.04 from the environment under the main ssdb (Server)

- CentOS 7 hard disk expansion toss record (Linux)

- Linux system started to learn: how to view the contents of the seed on the Linux file (Linux)

- Reset CentOS / RHEL root account password 7 (Linux)

- systemd Power Management (Linux)

- Linux System Getting Started tutorial: Ubuntu desktop using the command line to change the system proxy settings (Linux)

- Hibernate Search and Lucene quick introduction (Linux)

- Browser caching mechanism on the analysis (Linux)

- Ora-00600 [fast hot Atkins soft _ that _ Oh, of course not _less_ profile] (Database)

- Fragment Android developers learning to resolve (Programming)

- Redis logging system (Database)

- A detailed introduction to the Hadoop ecosystem (Server)

  Log4cplus logging facility configuration, installation, testing
  Add Date : 2018-11-21      
  Log4cplus is written in C ++ open source logging system, which is very comprehensive, the initial use log4plus, described below under Linux log4cplus their own learning process configuration, installation and testing process.

1, log4cplus Introduction

log4cplus is written in C ++ open source logging system, was formerly written in java log4j system. License protected by the Apache Software. The author is Tad E. Smith. log4cplus thread-safe, flexible, and more granular control features, by prioritizing information so that it can be oriented programming commissioning, operation, testing, and maintenance life cycle; you can choose to output information to the screen, file, NT event log, and even a remote server; regular backups of the log by the specified policy.

2, log4cplus download

The latest log4cplus can be downloaded from the following URL.

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

In RedHat Linux systems can use the following command to install:

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



make install

4, log4cplus configuration

log4cplus default installation behind file path is / usr / local / include / log4cplus, installation files Road King library file is / usr / local / lib, edit the .bash_profile file to add the library file.

$ Vi ~ / .bash_profile

Add to:

LD_LIBRARY_PATH = LD_LIBRARY_PATH: / usr / local / lib


After adding source ~ / .bash_profile changes to take effect

$ Vi / etc / profile

Add to:



After adding source ~ / .bash_profile changes to take effect

5, the test

#include < log4cplus / logger.h>
#include < log4cplus / configurator.h>
#include < iomanip>
#include < log4cplus / logger.h>
#include < log4cplus / fileappender.h>
#include < log4cplus / consoleappender.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, "% d-% d-% d.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
- Repair after installing Ubuntu no boot device error (Linux)
- CentOS7 installed VMware 10 (Linux)
- Ubuntu deploying Solr (4.4) to Tomcat (7.0.53) (Server)
- Parse Server supports iOS and Android push messaging (Programming)
- Impact test noatime Linux file access time (Linux)
- You can not ignore the seven Git tips (Linux)
- Linux find command usage summary (Linux)
- Ubuntu amend resolv.conf restart failure problem (Linux)
- Using IE can also be easily remotely control the computer (Linux)
- Debian (Wheezy) were installed wxPython GUI development (Linux)
- Ubuntu 12.04 64-bit installation Redmine + Git + ReviewBoard (Linux)
- Postmodern systems programming language (Programming)
- Linux uses a screen recording under RecordMyDesktop (Linux)
- Detailed Linux su command to switch users Mistakes (Linux)
- Linux System Getting Started Tutorial: How to update outdated version of Ubuntu (Linux)
- JBPM6 Tutorial - Fast Fun JBPM table (Linux)
- UNIX how to restrict users by IP Telnet (Linux)
- Oracle archive log summary (Database)
- Binary tree and some basic operations with binary list (Programming)
- Installation of JDK and Tomcat under Linux (CentOS) (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.