..bits & bytes teleported

Wednesday Jul 16, 2008

I am using Ubuntu Linux 8.04 and using log4cpp 1.0

Installing log4cpp from sources

  • D/l the sources are available from Sourceforge download page
  • ./configure
  • make
  • make check
  • sudo make install

You may also install log4cpp from repository using 'apt-get'.

Checking the installation

The log4cpp source tarball contains simple examples using the API in the 'tests/' sub-directory. Let us try one of them (testConfig.cpp) to check the installation:

  $ g++ -o testConfig testConfig.cpp -lpthread -llog4cpp
'lpthread' is required to link the pthreads shared libraries and 'log4cpp' is the log4cpp shared library. Execute it:
$./testConfig
I got this error:
./testConfig: error while loading shared libraries: liblog4cpp.so.4: cannot open shared object file: No such file or directory
I had the shared lib file in the '/usr/local/lib' directory. Still, I got the error. May be I needed a ld cache updation. ⁞So I just ran the 'ldconfig' to update the 'ld.so.cache' and then executed the object file:
$ ./testConfig 
1216198972 ERROR  : root error
1216198972 WARN  : root warn
1216198972 ERROR sub1 : sub1 error
1216198972 WARN sub1 : sub1 warn
The message sub2 error at time 2008-07-16 14:32:55,024
1216198975 ERROR sub1.sub2 : sub2 error
1216198975 ERROR  : root error
1216198975 WARN  : root warn
1216198975 ERROR sub1 : sub1 error
1216198975 WARN sub1 : sub1 warn
The message sub2 error at time 2008-07-16 14:32:58,374
1216198978 ERROR sub1.sub2 : sub2 error
The message test vform 123 at time 2008-07-16 14:32:58,375
1216198978 ERROR sub1.sub2 : test vform 123

Thus, log4cpp is ready to be used in your applications.

log4cpp-config

log4cpp-config is a command line tool which is also installed when you do a 'make install'. You can use it to obtain various information about your log4cpp installation.

$ log4cpp-config --help
All available options:
  --prefix=DIR and   change $prefix and $exec-prefix
  --exec-prefix=DIR  (affects all other options)
  --prefix           $prefix        /usr/local
  --exec_prefix  or... 
  --eprefix          $exec_prefix   /usr/local
  --version          $version        1.0
  --cflags           -I$includedir  unless it is /usr/include
  --libs             -L$libdir $LIBS  -llog4cpp  -lnsl 
  --package          $package       log4cpp
  --bindir           $bindir        /usr/local/bin
  --sbindir          $sbindir       /usr/local/sbin
  --libexecdir       $libexecdir    /usr/local/libexec
  --datadir          $datadir       /usr/local/share
  --sysconfdir       $sysconfdir    /usr/local/etc
  --sharedstatedir   $sharedstatedir/usr/local/com
  --localstatedir    $localstatedir /usr/local/var
  --libdir           $libdir        /usr/local/lib
  --infodir          $infodir       /usr/local/share/info
  --mandir           $mandir        /usr/local/share/man
  --target           $target        
  --host             $host          i686-pc-linux-gnu
  --build            $build         i686-pc-linux-gnu
  --pkgdatadir       $datadir/$package    /usr/local/share/log4cpp
  --pkglibdir        $libdir/$package     /usr/local/lib/log4cpp
  --pkgincludedir    $includedir/$package /usr/local/include/log4cpp
  --template-version $template_version     1.0.0
  --help

I am yet to find other uses of it. Seems like that you can change the various defaults using this tool.
Comments:

You might want to look at log4cxx from Apache. Seems to be more active than log4cpp.

Posted by Chris Williams on July 16, 2008 at 06:21 PM IST #

Hi Chris,

The inactivity of log4cpp concerned me. But then, I didn't know 'Apache log4cxx' was a similar solution. I will definitely now take a look at it.

Thanks for pointing that out.

Posted by Amit on July 16, 2008 at 07:32 PM IST #

Post a Comment:
Comments are closed for this entry.