You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Stephen Webb (Jira)" <lo...@logging.apache.org> on 2022/10/03 05:54:00 UTC

[jira] [Comment Edited] (LOGCXX-560) Logging in a static initializer

    [ https://issues.apache.org/jira/browse/LOGCXX-560?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17612180#comment-17612180 ] 

Stephen Webb edited comment on LOGCXX-560 at 10/3/22 5:53 AM:
--------------------------------------------------------------

A better configure-in-a-static-initializer approach is for the user to define thier own log manager. Then the user's code in MyLogManager.cpp would look like:

 
{code:java}
struct log4cxx_initializer
{
log4cxx_initializer()
{
log4cxx:DefaultConfigurator::setConfigurationFileName, LOG4CXX_STR("myApp.xml") );
}
~log4cxx_initializer()
{
log4cxx::LogManager::shutdown();
}
MyLogManager::getLogger(const std::string& name)
{
static log4cxx_initializer initAndShutdown;
return log4cxx::LogManager::getLogger(name);
}
{code}
 

Is it possibly to simplify this with a template?

 

 


was (Author: swebb2066):
A better configure in a static initializer approach is by the user difining thier own lo manager. Then the code in MyLogManager.cpp would look like:

 
{code:java}
struct log4cxx_initializer
{
log4cxx_initializer()
{
log4cxx:DefaultConfigurator::setConfigurationFileName, LOG4CXX_STR("myApp.xml") );
}
~log4cxx_initializer()
{
log4cxx::LogManager::shutdown();
}
MyLogManager::getLogger(const std::string& name)
{
static log4cxx_initializer initAndShutdown;
return log4cxx::LogManager::getLogger(name);
}
{code}
 

Is it possibly to simplify this with a template?

 

 

> Logging in a static initializer
> -------------------------------
>
>                 Key: LOGCXX-560
>                 URL: https://issues.apache.org/jira/browse/LOGCXX-560
>             Project: Log4cxx
>          Issue Type: Improvement
>            Reporter: Stephen Webb
>            Priority: Major
>
> Logging needs to be configured before the first log call. To log in a static initializer code, configuration must be executed during static initialization.
> The log4cxx documentation and examples suggest calling the configure method of the selected configurator in the main routine. It does not currently describe automatic configuration. 
> Automatic configuration currently requires either a special name (log4cxx.xxx or log4j.xxx) for the config file or an environment variable (LOG4CXX_CONFIGURATION or log4j.configuration) set with the name of the config file.
> It would be nice to be able to plug in user specified configuration logic that is invoked by log4cxx.
> One possible approach would be to override autoConfigure() (added in [#135)|https://github.com/apache/logging-log4cxx/pull/135] in a class that inherits from log4cxx::Hierarchy.
> Calling the LogManager::setRepositorySelector static function before other static initialisations is difficult as static initialization order is not easily controlled.
> A new static method LogManager::getLogger("name", MyRepository::Instance()) would prevent static initialization order issues.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)