Log4cxx-win7-debugging successful

Source: Internet
Author: User

1. Introduction

Log4cxx is a sub-project of Apache Logging Service, an open-source project. It is a c ++ porting version of log4j, a well-known Java Community, used to provide log functions for C ++ programs, this allows developers to debug and audit the target program. More information about log4cxx can be obtained from the website http://logging.apache.org of the Apache Loggin Service. The latest version is 0.10.0. The content and sample code of this article are based on this version.

2. Obtain the Software Package

1. Download two software packages from the official http://apr.apache.org/download.cgi:

Win32 Source: apr-1.4.5-win32-src.zip [PGP] [MD5]
[SHA1]

Windows Source: apr-util-1.3.12-win32-src.zip [PGP] [MD5]

Download official http://logging.apache.org/log4cxx/download.html:

Apache log4cxx 0.10.0 (tar.gz) Apache-log4cxx-0.10.0.tar.gz Apache-log4cxx-0.10.0.tar.gz.md5 Apache-log4cxx-0.10.0.tar.gz.asc
Apache log4cxx 0.10.0 (zip) Apache-log4cxx-0.10.0.zip Apache-log4cxx-0.10.0.zip.md5 Apache-log4cxx-0.10.0.zip.asc

Download both the tar.gz and zip packages.

2, or download from my own resources: http://download.csdn.net/detail/Qyee16/3662176 (resource points 1 point)

3. decompress the three software packages to obtain

1) apache-log4cxx-0.10.0 2) apr-1.4.5-win32-src 3) apr-util-1.3.12-win32-src

Because the files with the same name exist under the decompressed directory, You need to copy them separately, rename them to: apache-log4cxx, arp, apr-util, put in the same directory, I placed inD: \ log4cxxDirectory

4. Execute the bat file

Open the cmd command line and switch to D: \ log4cxx \ apache-log4cxx (because the directory I created above isD: \ log4cxx)

(1) type: configure (execute configure. bat

As shown in the following figure, the operation is successful:

1 file copied

1 file copied

It actually completed this task: configure. bat copies the prefabricated log4cxx. hw and private/log4cxx_private.hw over to log4cxx. h and private/log4cxx_private.h.

(2) Type: configure-aprutil (execute configure-aprutil.bat

As shown in the following figure, the operation is successful:

The actual work is: "sed" to modify apu. hw and apr_ldap.hw to disable APR-Iconv and LDAP which are not necessary for log4cxx and problematic to build. if "sed" is not available, the modifications wocould be trivial to do in any text editor.

Common Errors: As shown above, the "sed" command is used, and the "sed" command is a unix Command. During execution, window reports that it is not an "internal or external command ".

Solution: download and install Cygwin from the official website: http://www.cygwin.com/. the downloaded package is included in the package. The installation is simple, but the installation is complete. The bin in the installation directory is included in the system environment variable.

If the installation directory is C: \ Cygwin, include C: \ Cygwin \ bin in the system Path.

5. compile and generate lib and dl files

1. Use vc. net2003 to open the log4cxx. dsw project under the Projects folder, set the log4cxx project as the startup project, and compile the project,

2. After compilation is successful, you can view the lib and dll files in the Debuge or Release folder of projects.

Note: if an error occurs when using vs2010, use vs2008 for compiling.

6. Test

1. Open vs2008 and create a win32 console Project Test

2. Right-click the Test project, select properties, and then add the additional library directory in the C ++ tab, note that the directory is ../apache-log4cxx-0.10.0 \ src \ main \ include

3. Add "log4cxx. lib" to "additional dependencies" on the input tab of the property linker, and copy the compiled log4cxxlib and log4cxx. dll to the Test project directory.

4. Enter the following test code in the cpp file:

// Log4cppTest. cpp: Defines the entry point for the console application. // # include "stdafx. h "# include <string> # include <log4cxx/logger. h> # include <log4cxx/propertyconfigurator. h> # include <log4cxx/helpers/exception. h> using namespace log4cxx; using namespace log4cxx: helpers; using namespace std; int main (int argc, char * argv []) {string msg = "log4cxx. properties "; LoggerPtr Logger = Logger: getRootLogger (); log4cxx: PropertyConfigurator: configure (msg); Logger-> info (_ T (" Hello world ")); LOG4CXX_INFO (Logger, "hello"); getchar (); return 0 ;}

5. Create a text file named log4cxx. properties, and enter the following content: (also in the Test project directory)

# 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

6. If Test is run successfully, the output. log file is generated in the project directory, and the information is recorded in the file.

Log4cxx is a powerful and configurable logging tool. You can study the detailed configuration by yourself.

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.