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.
To compile it, you also need two auxiliary libraries, APR, and APR-util, which can be downloaded here.
The first step to install the apr-1.3.8, the order cannot be wrong, it must be preinstalled
$ Tar zxvf apr-1.3.8.tar.gz
$ Apr-1.3.8 CD
$./Configure -- prefix =/usr/local
$ Make
$ Su Root
$ Make install
Then install apr-util-1.3.9
$ Tar zxvf apr-util-1.3.9.tar.gz
$ Apr-util-1.3.9 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
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
Because it is compiled into a shared library, you also need to set the search directory and edit ~ /. Bashrc, add the following two rows
LD_LIBRARY_PATH =/usr/local/lib
Export LD_LIBRARY_PATH
OK. Now log4cxx is installed.
Finally, write a program and test it.
# 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. cfg ");
// Create two Logger
Loggerptr logger1 = logger: getlogger ("traceyourmama ");
Loggerptr logger2 = logger: getlogger ("patch ");
Log4cxx_trace (logger1, "trace ");
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;
}
Compile Link
$ G ++-O main. cpp-llog4cxx
OK.