Introduction
This article is a step-by-step tutorial about building the logging framework log4cxx from Apache based on my own experience. I've used version 0.10.0 of log4cxx when writing this article.
Background
I tried to build log4cxx on many different ways like using the source out of the
CVS repository and so on but with none of these ways I could get a working log4cxx library. I got a lot of help and ideas from another blog post located here. A big thank you to the author! I also posted this "article" as an answer on stackoverflow.com and you can find it here.
Let's get started ...
- Download the latest log4cxx package from here
- Download apr and apr-util ZIP packages from here
- Extract log4cxx, apr und apr-util to the same directory
- Rename the apr_VERSION and apr-util_VERSION folder to apr and apr-util resulting in a directory with three folder: apache-log4cxx-0.10.0, apr and apr-util
- Change into the log4cxx directory and execute
configure.bat
- Change to apr-util/include direcotry and open
apu-hw
in a texteditor of your choice - Find the entry
#define APU_HAVE_APR_ICONV
, set it to 0
and save the file - Open apr_ldap.hw from the same directory and find the entry
#define APR_HAS_LDAP
, set it to 0
and save the file, too - Change to log4cxx/projects directory and open log4cxx.dsw with VS2010. Answer the converting prompts of VS2010 with yes/ok for each project (apr, apr-util, log4cxx, xml)
OK ... if you hit build (F6) now then you will see around 2000 errors and that is where the interesting and hard part starts ... if it compiles fine then you're damn lucky guy!
- Ctrl+F and find each entry of the "LOG4CXX_LIST_DEF" macro. You have to move these entries out of its related class and right before the same class. Sometimes you need to move a typedef too or add the class right before the macro.
Some examples which should help you to understand what I mean:
...
typedef log4cxx::helpers::SocketPtr Connection;
LOG4CXX_LIST_DEF(ConnectionList, Connection);
class LOG4CXX_EXPORT TelnetAppender : public AppenderSkeleton
...
...
class Appender;
LOG4CXX_PTR_DEF(Appender);
LOG4CXX_LIST_DEF(AppenderList, AppenderPtr);
class Layout;
typedef log4cxx::helpers::ObjectPtrT<Layout> LayoutPtr;
...
class LOG4CXX_EXPORT Appender :public virtual spi::OptionHandler
{
...
If the compiler complains about KeySet not being member of LoggingEvent
, just remove the scope (since we moved the type to outside the class in the previous step,
these types no longer are inside the class).
Example:
LoggingEvent::KeySet set;
KeySet set;
- If the compiler complains about
insert_iterator
not being in the namespace std, add #include <iterator>
to the include section of the source file - Last but not least, right-click on log4cxx project and select Add References and select the other 3 projects as reference
That's it ... I hope this article can help someone who's struggling with the same problem!