C++ Logging Library Setup
Asked Answered
P

4

8

I've been trying for about 2 weeks now to get a logging library to work with. I've tried Log4cxx, Log4cpp, log4cplus and boost.log. The problem isn't that none of these work for me, it's that I can't figure out how to get them to work at all. I would really like to use log4cxx since I'm working with log4j/logback at work, but I haven't been able to get any of the libraries based on log4j to build. I've been able to build and use the boost library, but boost.log gives me all kinds of linker errors no matter what I try. If anyone could direct me to a step-by-step guide to get one of these libraries working I would greatly appreciate it. Also, I'm using eclipse as my IDE if that matters.

Prang answered 1/2, 2011 at 2:55 Comment(2)
What operating system are you using? Also, be sure to first compile the libraries and then take the header files to include into your project (the implementation will be compiled into the libraries one time so you don't have to recompile the huge library multiple times)Siftings
I'm using Windows 7. I'm not sure what you mean about compiling and then taking the header files. Sorry, I'm kind of new to using third party libraries. For boost at least I just add the boost root directory as an include path and then use an include directive for each file that I need.Prang
U
1

Did you ever get this working? Log4cxx definitely works on Win7. Maybe you could post some of your build errors. Just guessing, perhaps you didn't configure your eclipse project to link with a log4cxx static lib.

Unvoiced answered 8/10, 2011 at 20:42 Comment(0)
J
1

Boost.Log works for me quite well (Linux and Windows). It is not a header only library, there is a compiled part that you need to link against. See instructions here.

It also depends on other, non-header, Boost libraries:

The logging library uses several other Boost libraries that need building too. These are Boost.Filesystem, Boost.System, Boost.DateTime, Boost.Thread and Boost.Regex. Refer to their documentation for detailed instructions on the building procedure.

Depending on your platform there may be pre-built versions of the Boost libraries. Otherwise building it yourself is straightforward if you follow the instructions. If you get stuck update your question with where exactly you got stuck and what you're seeing.

Johnathon answered 8/10, 2011 at 20:51 Comment(0)
B
0

I'd recommend Pantheios. It takes some time to build everything when you first download - type make build test and go have lunch - and you have to select the output streams (Pantheios calls them "back ends") at link time, but for coding, it is really simple, e.g.

std::string name;
int age;

pantheios::log_DEBUG("name=", name, " age=", pantheios::integer(age));

It's designed from the ground up for speed - the age won't be converted into a string unless the "DEBUG" level is switched on - and robustness - which is why you can't pass fundamental types directly, and use "inserters" (e.g. pantheios::integer). See this recent blog post by Pantheios' author for more information.

Blaine answered 1/2, 2011 at 3:51 Comment(0)
G
0

I managed to get log4cxx to work, this was done in Visual Studios 2013 running on Windows 7 OS.

This following is what I did, step by step:

Download the log4cxx ZIP package extract its contents, http://logging.apache.org/log4cxx/download.html

Download apr and apr-util ZIP packages, http://apr.apache.org/download.cgi

Then

  1. manually extract this zip apr-1.2.11-win32-src.zip (the extracted folder should be named 'apr', if it is not manually rename it)
  2. manually extract this zip apr-util-1.2.10-win32-src.zip (the extracted folder should be named 'apr-util', if it is not manually rename it)
  3. open a command prompt and run the following: cd apache-log4cxx-0.10.0 configure (this will execute configure.bat)

We will need to disable to use of the APR ICONV and LDAP support. In order to do so, we will append the following files manually:

  1. Open apr-util\include\apu.hw. Find the line starting with “#define APU_HAVE_APR_ICONV”. Change the value to 0 and save.
  2. Open apr-util\include\apr_ldap.hw. Find the line starting with “#define APR_HAS_LDAP” Change the value to 0 and save.

We need to build the log4cxx.dll, to do so convert *.dsw to *.cxproj.

  1. Launch Visual Studio 2013 and open log4cxx.dsw.
  2. VS will ask if you like to convert everything. Simply click Yes. There may be some warnings in the migration report, but nothing that should prevent the solution from opening.

> The projects xml, apr, and apr-util should build successfully.

If you try compiling the log4cxx project it will most likely fail with hundreds of errors. This is due to a bug in VC++ which can be worked around.

  1. Move all macros outside (above) the class they are in. LOG4CXX_LIST_DEF macro is used to define classes. All macros reported in error C2252 will need to move out of any classes. This may also include moving definitions which are used in the macro.
  2. Next, change all LoggingEvent::KeySet to KeySet (this is no longer nested in a parent class)

> Following this, the log4cxx project should now compile successfully on your machine.

Gaberones answered 20/4, 2016 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.