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 <bentry...@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 <zhu.lij...@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 <bentry...@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 <renny.ko...@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.
>>>>
>>>
>>>
>>
>

Reply via email to