Go Linux under compilation installation Log4cxx

Source: Internet
Author: User

Linux under compilation installation Log4cxx

A Project Server side under the Linux platform, the open source log library Log4cxx, this library is a sub-library of Apache project. The function is very good. The following is a record of its compilation and installation process.

Log4cxx's official is http://logging.apache.org/log4cxx/index.html, I use 0.10.0 version.

In order to compile it, also need two auxiliary library, Apr, and apr-util, can download http://apr.apache.org/download.cgi here, I use the version is apr-1.3.8.tar.gz and apr-util-1.3.9.tar.gz.

The first step installs apr-1.3.8, the order cannot be wrong, it must install first

$tar ZXVF apr-1.3.8.tar.gz

$CD apr-1.3.8

$./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

$CD apr-util-1.3.9

$./configure--prefix=/usr/local--WITH-APR=/USR/LOCAL/APR

$make

$SU Root

$make Install

Configure option--WITH-APR=/USR/LOCAL/APR Specify the location of the APR library

Finally, we can install Log4cxx.

$tar ZXVF apache-log4cxx-0.10.0.tar.gz

$CD apache-log4cxx-0.10.0

$configure--prefix==/usr/local

$make

$SU Root

$make Install

Because compiled into a shared library, and finally set the next search directory, edit ~/.BASHRC, add the following two lines

Ld_library_path=/usr/local/lib

Export Ld_library_path

OK, so log4cxx is ready to install.

Finally write a program, test under.

#include <log4cxx/logger.h>
#include <log4cxx/logstring.h>
#include <log4cxx/propertyconfigurator.h>

int main (int argc, char* argv[])
{
using namespace Log4cxx;

Reading configuration Files
Propertyconfigurator::configure ("Log4cxx.cfg");

Establishment of two logger
Loggerptr logger1 = Logger::getlogger ("Traceyourmama");
Loggerptr logger2 = Logger::getlogger ("Patch");

Log4cxx_trace (Logger1, "tracking");
Log4cxx_warn (Logger1, "warning");
Log4cxx_debug (Logger1, "commissioning");
Log4cxx_assert (Logger1, False, "assertion");
Log4cxx_fatal (Logger1, "deadly");

Log4cxx_trace (Logger2, "tracking");
Log4cxx_error (Logger2, "error");
return 0;
}

Compiling links

$g + +-o main main.cpp-llog4cxx

OK, finish the manual.

Finally install Log4cxx when there will be errors, missing header files, according to the wrong file to add

Related Article

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.