You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4cxx-user@logging.apache.org by yaohua xiao <be...@gmail.com> on 2009/04/22 03:29:52 UTC

How can I know log4cxx is initialized?

Hi all,

I am new to log4cxx and have a mutiple dll project to use log4cxx for some
logging task.
My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need logging.

log4cxx needs some initialize code such like BasicConfigurator::configure() ,
load properties files, to prepare the logger. Because i use import lib to
load the dlls,
i don't know which dll will load first.

So I want to determine if log4cxx is initialized when I call log4cxx in each
dll.
Is there any api can tell user is log4cxx initialized?

Thanks.

Re: How can I know log4cxx is initialized?

Posted by re...@rubixinfotech.com.
Or -- why not have an "Initialize()" method in ONE of the DLL's.... then 
all of the others can call Initialize(), which should only init the 
Log4CXX once?

Renny Koshy
President & CEO

--------------------------------------------
Rubix Information Technologies, Inc.
www.rubixinfotech.com



Lijuan Zhu <zh...@gmail.com> 
04/21/2009 10:25 PM
Please respond to
"Log4CXX User" <lo...@logging.apache.org>


To
Log4CXX User <lo...@logging.apache.org>
cc

Subject
Re: How can I know log4cxx is initialized?






Your project should have an entry point, like some Initialize method, if 
you initalize the log4cxx there, the log4cxx should be initialized for all 
other dlls.

HTH,
Lijuan

On Wed, Apr 22, 2009 at 10:18 AM, yaohua xiao <be...@gmail.com> wrote:
Renny, Thanks for your replay!

I already have a singleton class called "log4cxx_LogManager" to manage 
log4cxx 
in all the dlls.

But I found that every dll will have a copy of that singleton class,
so the singleton manager "log4cxx_LogManager" is not single in the mutiple 
dll enviromnents.If let the log4cxx_LogManager do the log4cxx initialized 
stuff, 
will initialize more than one times.

Because log4cxx is compiled into a dll, it has only one copy in runtime.
So I want my log4cxx_LogManager query if log4cxx is initialzed first, if 
not, initialize it. 
otherwise, use the logger directly.

If log4cxx.dll has some initialize flag or api, the problem will simply 
solve.

2009/4/22 <re...@rubixinfotech.com>

Why don't you simply create a singleton instance of a class that will 
"manage" log4cxx for you? 

Then you can just query the singleton to see if it is initialized or 
not... or even just call the "init()" method of the singleton in all your 
DLL's... so the init will only happen once. 

Renny Koshy
President & CEO

--------------------------------------------
Rubix Information Technologies, Inc.
www.rubixinfotech.com 


Hi all,

I am new to log4cxx and have a mutiple dll project to use log4cxx for some 
logging task.
My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need logging.

log4cxx needs some initialize code such like 
BasicConfigurator::configure() 
, load properties files, to prepare the logger. Because i use import lib 
to load the dlls, 
i don't know which dll will load first. 

So I want to determine if log4cxx is initialized when I call log4cxx in 
each dll.
Is there any api can tell user is log4cxx initialized?

Thanks. 



Re: How can I know log4cxx is initialized?

Posted by yaohua xiao <be...@gmail.com>.
Hiļ¼Œall!
Finally, I got an alternative way to check if log4cxx has initialized. I get
the RootLogger's appender count to see if the rootlogger has any appender.
If none, the log4cxx hasn't initialize yet.  The code like that:

    bool check_init()
    {
        bool result = true;

        try {
            log4cxx::LoggerPtr rootLogger =
log4cxx::Logger::getRootLogger();
            result = rootLogger->getAllAppenders().size() ? true : false;
        } catch ( log4cxx::helpers::Exception& e ) {
            std::cout << e.what() << std::endl;
        }

        return result;
    };

I don't know if it's the best way, but it's fine for me. Anyone give me some
suggestion?  Thanks.



2009/4/22 yaohua xiao <be...@gmail.com>

> Thanks, Zhu.
>
> That's a solution, but expose a initialize method to the client exe is not
> so clean
> an not so smart.
> But if there isn't another solution, that will make it. :(
>
> But I think the log4cxx is likely have some api for the user to query the
> intialize status.
>
> 2009/4/22 Lijuan Zhu <zh...@gmail.com>
>
> Your project should have an entry point, like some Initialize method, if
>> you initalize the log4cxx there, the log4cxx should be initialized for all
>> other dlls.
>>
>> HTH,
>> Lijuan
>>
>>
>> On Wed, Apr 22, 2009 at 10:18 AM, yaohua xiao <be...@gmail.com>wrote:
>>
>>> Renny, Thanks for your replay!
>>>
>>> I already have a singleton class called "log4cxx_LogManager" to manage
>>> log4cxx
>>> in all the dlls.
>>>
>>> But I found that every dll will have a copy of that singleton class,
>>> so the singleton manager "log4cxx_LogManager" is not single in the
>>> mutiple dll enviromnents.If let the log4cxx_LogManager do the log4cxx
>>> initialized stuff,
>>> will initialize more than one times.
>>>
>>> Because log4cxx is compiled into a dll, it has only one copy in runtime.
>>> So I want my log4cxx_LogManager query if log4cxx is initialzed first, if
>>> not, initialize it.
>>> otherwise, use the logger directly.
>>>
>>> If log4cxx.dll has some initialize flag or api, the problem will simply
>>> solve.
>>>
>>> 2009/4/22 <re...@rubixinfotech.com>
>>>
>>>>
>>>> Why don't you simply create a singleton instance of a class that will
>>>> "manage" log4cxx for you?
>>>>
>>>> Then you can just query the singleton to see if it is initialized or
>>>> not... or even just call the "init()" method of the singleton in all your
>>>> DLL's... so the init will only happen once.
>>>>
>>>> Renny Koshy
>>>> President & CEO
>>>>
>>>> --------------------------------------------
>>>> Rubix Information Technologies, Inc.
>>>> www.rubixinfotech.com
>>>>
>>>>
>>>> Hi all,
>>>>
>>>> I am new to log4cxx and have a mutiple dll project to use log4cxx for
>>>> some logging task.
>>>> My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need
>>>> logging.
>>>>
>>>> log4cxx needs some initialize code such like
>>>> BasicConfigurator::configure()
>>>> , load properties files, to prepare the logger. Because i use import lib
>>>> to load the dlls,
>>>> i don't know which dll will load first.
>>>>
>>>> So I want to determine if log4cxx is initialized when I call log4cxx in
>>>> each dll.
>>>> Is there any api can tell user is log4cxx initialized?
>>>>
>>>> Thanks.
>>>>
>>>
>>>
>>
>

Re: How can I know log4cxx is initialized?

Posted by yaohua xiao <be...@gmail.com>.
Thanks, Zhu.

That's a solution, but expose a initialize method to the client exe is not
so clean
an not so smart.
But if there isn't another solution, that will make it. :(

But I think the log4cxx is likely have some api for the user to query the
intialize status.

2009/4/22 Lijuan Zhu <zh...@gmail.com>

> Your project should have an entry point, like some Initialize method, if
> you initalize the log4cxx there, the log4cxx should be initialized for all
> other dlls.
>
> HTH,
> Lijuan
>
>
> On Wed, Apr 22, 2009 at 10:18 AM, yaohua xiao <be...@gmail.com> wrote:
>
>> Renny, Thanks for your replay!
>>
>> I already have a singleton class called "log4cxx_LogManager" to manage
>> log4cxx
>> in all the dlls.
>>
>> But I found that every dll will have a copy of that singleton class,
>> so the singleton manager "log4cxx_LogManager" is not single in the
>> mutiple dll enviromnents.If let the log4cxx_LogManager do the log4cxx
>> initialized stuff,
>> will initialize more than one times.
>>
>> Because log4cxx is compiled into a dll, it has only one copy in runtime.
>> So I want my log4cxx_LogManager query if log4cxx is initialzed first, if
>> not, initialize it.
>> otherwise, use the logger directly.
>>
>> If log4cxx.dll has some initialize flag or api, the problem will simply
>> solve.
>>
>> 2009/4/22 <re...@rubixinfotech.com>
>>
>>>
>>> Why don't you simply create a singleton instance of a class that will
>>> "manage" log4cxx for you?
>>>
>>> Then you can just query the singleton to see if it is initialized or
>>> not... or even just call the "init()" method of the singleton in all your
>>> DLL's... so the init will only happen once.
>>>
>>> Renny Koshy
>>> President & CEO
>>>
>>> --------------------------------------------
>>> Rubix Information Technologies, Inc.
>>> www.rubixinfotech.com
>>>
>>>
>>> Hi all,
>>>
>>> I am new to log4cxx and have a mutiple dll project to use log4cxx for
>>> some logging task.
>>> My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need
>>> logging.
>>>
>>> log4cxx needs some initialize code such like
>>> BasicConfigurator::configure()
>>> , load properties files, to prepare the logger. Because i use import lib
>>> to load the dlls,
>>> i don't know which dll will load first.
>>>
>>> So I want to determine if log4cxx is initialized when I call log4cxx in
>>> each dll.
>>> Is there any api can tell user is log4cxx initialized?
>>>
>>> Thanks.
>>>
>>
>>
>

Re: How can I know log4cxx is initialized?

Posted by Lijuan Zhu <zh...@gmail.com>.
Your project should have an entry point, like some Initialize method, if you
initalize the log4cxx there, the log4cxx should be initialized for all other
dlls.

HTH,
Lijuan

On Wed, Apr 22, 2009 at 10:18 AM, yaohua xiao <be...@gmail.com> wrote:

> Renny, Thanks for your replay!
>
> I already have a singleton class called "log4cxx_LogManager" to manage
> log4cxx
> in all the dlls.
>
> But I found that every dll will have a copy of that singleton class,
> so the singleton manager "log4cxx_LogManager" is not single in the mutiple
> dll enviromnents.If let the log4cxx_LogManager do the log4cxx initializedstuff,
> will initialize more than one times.
>
> Because log4cxx is compiled into a dll, it has only one copy in runtime.
> So I want my log4cxx_LogManager query if log4cxx is initialzed first, if
> not, initialize it.
> otherwise, use the logger directly.
>
> If log4cxx.dll has some initialize flag or api, the problem will simply
> solve.
>
> 2009/4/22 <re...@rubixinfotech.com>
>
>>
>> Why don't you simply create a singleton instance of a class that will
>> "manage" log4cxx for you?
>>
>> Then you can just query the singleton to see if it is initialized or
>> not... or even just call the "init()" method of the singleton in all your
>> DLL's... so the init will only happen once.
>>
>> Renny Koshy
>> President & CEO
>>
>> --------------------------------------------
>> Rubix Information Technologies, Inc.
>> www.rubixinfotech.com
>>
>>
>> Hi all,
>>
>> I am new to log4cxx and have a mutiple dll project to use log4cxx for some
>> logging task.
>> My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need logging.
>>
>> log4cxx needs some initialize code such like
>> BasicConfigurator::configure()
>> , load properties files, to prepare the logger. Because i use import lib
>> to load the dlls,
>> i don't know which dll will load first.
>>
>> So I want to determine if log4cxx is initialized when I call log4cxx in
>> each dll.
>> Is there any api can tell user is log4cxx initialized?
>>
>> Thanks.
>>
>
>

Re: How can I know log4cxx is initialized?

Posted by yaohua xiao <be...@gmail.com>.
Renny, Thanks for your replay!

I already have a singleton class called "log4cxx_LogManager" to manage
log4cxx
in all the dlls.

But I found that every dll will have a copy of that singleton class,
so the singleton manager "log4cxx_LogManager" is not single in the mutiple
dll enviromnents.If let the log4cxx_LogManager do the log4cxx initializedstuff,
will initialize more than one times.

Because log4cxx is compiled into a dll, it has only one copy in runtime.
So I want my log4cxx_LogManager query if log4cxx is initialzed first, if
not, initialize it.
otherwise, use the logger directly.

If log4cxx.dll has some initialize flag or api, the problem will simply
solve.

2009/4/22 <re...@rubixinfotech.com>

>
> Why don't you simply create a singleton instance of a class that will
> "manage" log4cxx for you?
>
> Then you can just query the singleton to see if it is initialized or not...
> or even just call the "init()" method of the singleton in all your DLL's...
> so the init will only happen once.
>
> Renny Koshy
> President & CEO
>
> --------------------------------------------
> Rubix Information Technologies, Inc.
> www.rubixinfotech.com
>
>
> Hi all,
>
> I am new to log4cxx and have a mutiple dll project to use log4cxx for some
> logging task.
> My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need logging.
>
> log4cxx needs some initialize code such like BasicConfigurator::configure()
>
> , load properties files, to prepare the logger. Because i use import lib to
> load the dlls,
> i don't know which dll will load first.
>
> So I want to determine if log4cxx is initialized when I call log4cxx in
> each dll.
> Is there any api can tell user is log4cxx initialized?
>
> Thanks.
>

Re: How can I know log4cxx is initialized?

Posted by re...@rubixinfotech.com.
Why don't you simply create a singleton instance of a class that will 
"manage" log4cxx for you?

Then you can just query the singleton to see if it is initialized or 
not... or even just call the "init()" method of the singleton in all your 
DLL's... so the init will only happen once.

Renny Koshy
President & CEO

--------------------------------------------
Rubix Information Technologies, Inc.
www.rubixinfotech.com



yaohua xiao <be...@gmail.com> 
04/21/2009 09:29 PM
Please respond to
"Log4CXX User" <lo...@logging.apache.org>


To
log4cxx-user <lo...@logging.apache.org>
cc

Subject
How can I know log4cxx is initialized?






Hi all,

I am new to log4cxx and have a mutiple dll project to use log4cxx for some 
logging task.
My project has 3 dll modules: a.dll, b.dll, c.dll , all dlls need logging.

log4cxx needs some initialize code such like 
BasicConfigurator::configure() 
, load properties files, to prepare the logger. Because i use import lib 
to load the dlls, 
i don't know which dll will load first. 

So I want to determine if log4cxx is initialized when I call log4cxx in 
each dll.
Is there any api can tell user is log4cxx initialized?

Thanks.