Hello,
is there any guideline on how to use log4cxx in library?
I tried use it in my library, but it seems does not work. I prepare a
test file in attachment. and when I run it, it crashed. gdb give
following information[1]. please help me, thanks.
[1]
(gdb) bt
#0 0x00002afd8d3c6536 in
log4cxx::helpers::AppenderAttachableImpl::appendLoopOnAppenders ()
from /usr/lib/liblog4cxx.so.9
#1 0x00002afd8d3f1838 in log4cxx::Logger::callAppenders () from
/usr/lib/liblog4cxx.so.9
#2 0x00002afd8d3f19a0 in log4cxx::Logger::forcedLog () from
/usr/lib/liblog4cxx.so.9
#3 0x0000000000402196 in main () at log4cxx.t.cpp:28
my platform and version info:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 3.1 (sarge)
Release: 3.1
Codename: sarge
$ uname -a
Linux ldblab 2.6.17-1-em64t-p4-smp #1 SMP Thu Jun 29 23:35:33 CEST
2006 x86_64 GNU/Linux
$ dpkg -l liblog4cxx9-dev
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name Version Description
+++-=========================-=========================-==================================================================
ii liblog4cxx9-dev 0.9.7-5 A logging
library for C++ (development files)
$
--
LI Daobing
#include <log4cxx/logger.h>
#include <log4cxx/consoleappender.h>
#include <log4cxx/level.h>
using namespace log4cxx;
// lib part begin
class Lib_Init
{
static Lib_Init initer;
Lib_Init();
};
Lib_Init::Lib_Init()
{
ConsoleAppender* app = new ConsoleAppender();
app->setTarget("system.err");
Logger::getLogger("a")->addAppender(app);
Logger::getLogger("a")->setLevel(Level::INFO);
}
Lib_Init Lib_Init::initer;
// lib part end
int main()
{
LOG4CXX_ERROR(Logger::getLogger("a"),
"can't open file: %s");
LOG4CXX_ERROR(Logger::getLogger("a.b"),
"can't open file: %s");
return 0;
}