1. Introduction:
On the Linux platform, the server of a project uses the open-source log4cxx library, a sub-library of the apache project. Good features. The compilation and installation processes are recorded below.
The official version of log4cxx is http://logging.apache.org/log4cxx/index.html. I use 0.10.0133.
Linux: centos5.3
2. Download
To compile the SDK, you also need two auxiliary libraries, apr, and apr-util. You can download them at http://apr.apache.org/download.cgiand unix apr-1.4.5.tar.gz and apr-util-1.3.12.tar.gz.
3. Compile and install
1) The first step to install the apr-1.4.5, the order can not be wrong, it must first install
$ Tar zxvf apr-1.4.5.tar.gz
$ Cd apr-1.4.
$./Configure -- prefix =/usr/local
$ Make
$ Su root
$ Make install
2) then install apr-util-1.3.12
$ Tar zxvf apr-util-1.3.12.tar.gz
$ Apr-util-1.3.12 cd
$./Configure -- prefix =/usr/local -- with-apr =/usr/local/apr
$ Make
$ Su root
$ Make install
Configure option -- with-apr =/usr/local/apr specifies the location of the apr Library
3) Finally, you can install log4cxx.
$ Tar zxvf apache-log4cxx-0.10.0.tar.gz
$ Apache-log4cxx-0.10.0 cd
$ Configure -- prefix =/usr/local
$ Make
$ Su root
$ Make install
4) Add a shared Link Library
Export LD_LIBRARY_PATH =/usr/local/lib
OK. Now log4cxx is installed.
4. Test the program.
1) create a main. cpp File
# Include <log4cxx/logger. h> # include <log4cxx/logstring. h> # include <log4cxx/propertyconfigurator. h> int main (int argc, char * argv []) {using namespace log4cxx; // read the configuration file PropertyConfigurator: configure ("log4cxx. properties "); // create two logger LoggerPtr logger1 = Logger: getLogger (" TraceYourMama "); LoggerPtr logger2 = Logger: getLogger (" Patch "); LOG4CXX_TRACE (logger1, "Trail"); LOG4CXX_WARN (logger1, "warning"); LOG4CXX_DEBUG (logger1, "debug"); LOG4CXX_ASSERT (logger1, false, "asserted"); LOG4CXX_FATAL (logger1, "Fatal"); LOG4CXX_TRACE (logger2, "trace"); LOG4CXX_ERROR (logger2, "error"); return 0 ;}
2. Compile the log4cxx. properties file.
# Set the root logger to the DEBUG level and use the ca and fa Appenderlog4j. rootLogger = DEBUG, ca, fa # Set Appender fa: # This is a File-type Appender, # its output File (File) is. /output. log, # The output mode (Append) is the overwrite mode, # The output format (layout) is PatternLayoutlog4j. appender. fa = org. apache. log4j. fileAppenderlog4j. appender. fa. file =. /output. loglog4j. appender. fa. append = falselog4j. appender. fa. layout = org. apache. log4j. patternLayoutlog4j. appender. fa. layout. conversionPattern = % d [% t] %-5 p %. 16c-% m % n # Set the Appender ca # This is a console-type Appender # The output format (layout) is PatternLayoutlog4j. appender. ca = org. apache. log4j. leleappenderlog4j. appender. ca. layout = org. apache. log4j. patternLayoutlog4j. appender. ca. layout. conversionPattern = % d [% t] %-5 p %. 16c-% m % n
Compile Link
$ G ++-o main. cpp-llog4cxx
$./Mian