Compile and install log4cxx 0.10.0 in Linux

Source: Internet
Author: User

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.

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.