C + + Open source Log class

Source: Internet
Author: User
Tags system log windows x64

Today I would like to find an open-source log class for my C + + project to record the system log, resulting in a half-afternoon of wasted time. Search for relevant information from the Internet to find the following options:

1, log4cplus:http://sourceforge.net/projects/log4cplus/files/log4cplus-stable/1.1.0

2, log4cxx:http://logging.apache.org/log4cxx/download.html (Log4cxx is implemented by Java log4j Open Source, in C + + implementation of an open source library)

3, Glog:http://code.google.com/p/google-glog/downloads/list

4, Log4cpp:http://sourceforge.net/projects/log4cpp/files

I initially looked at the 1th and 4th is the open-source project on the SourceForge website, do not know whether is blocked, in short, can not open the page. Waste me half an hour to find agents and FQ, are not found. See the 2nd is the Java annotated log class log4j's sister C + + version, immediately feel should be good, the results of the compilation process let Me go directly mad off. First download Log4cxx source code, and said light download this is not enough, but also to download another two Apache project (Apr, Apr-util) code, the next three are not yet, under Windows compile also need the next version of the Windows X64 sed, OK, this does not count , even if the link failed, the network can not find the corresponding solution, the whole process wasted me 4 hours.

So today's lesson is that someone else's open source project is simply not to see the Windows platform, or simply not to see me as a rookie. Now that I'm a little rookie on the Windows platform, I'm going to be honest with the simple stuff. Download Google Glog from a third-party website and compile it with ease, very good!

1, download google-glog-v0.3.4-50-gde75983.zip from the Internet, extract to local, you can see the project file Google-glog.sln, can be opened with Visual Studio 2008.

2, directly compile can get Libglog.dll, libglog.lib and other files, here lib file at compile time to use, and DLL file is run time to use, you can see here Glog adopt "implicit" dynamic link library compile method.

3. Add the extracted folder path: "Google-glog\src\windows" to the project path in Visual Studio 2008 to facilitate reference to the header file. At the same time, the previous step to compile the Lib file into the path or directly copied to the custom project path;

4. Use the following code to test the use:

1#include <iostream>2 using namespacestd;3 4#include <glog/logging.h>5 #pragmaComment (lib, "Libglog.lib")6 7 intMainintargcChar**argv)8 {9Google::initgooglelogging ("KLH");TenGoogle::setlogdestination (Google::info,"f://"); One  A     Charstr[ -] ="Hello log!";  -LOG (INFO) <<"Found"<< Google::counter <<Endl;  -LOG (INFO) << str;//<< "cookies";  theLOG (WARNING) <<"Warning Test";//will output a warning log -LOG (ERROR) <<"Error Test";//An error log is output -  -System"Pause"); +     return 0; -}

5, the compiler generated EXE file can not run directly, you need to copy the 3rd step compiled DLL files to the same directory to run. The test log files are automatically generated in the f:/root directory. Resembles the following format:

1LogfileCreated at: -/ A/ -  -: -: -2Running on machine:victo-PC3Log line format: [IWEF]MMDD hh:mm:ss.uuuuuu ThreadIDfile: line] msg4I1214 -: -:18.590252  9648Main2.CPP: -] Found05I1214 -: -:18.591253  9648Main2.CPP: -] Hello log!6W1214 -: -:18.591253  9648Main2.CPP: the] Warning Test7E1214 -: -:18.592252  9648Main2.CPP: -] Error test

C + + Open source Log class

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.