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 Kaspar Fischer <ka...@dreizak.com> on 2014/03/10 03:20:27 UTC

getRootLogger() thread-safe?

Hi everybody,

Is getRootLogger() thread safe?

I am running into a situation where calling getRootLogger() concurrently
from many requests results in a EXC_BAD_ACCESS:

liblog4cxx.10.dylib`log4cxx::LogManager::getRootLogger():
0x101f180a0:  pushq  %rbp
0x101f180a1:  movq   %rsp, %rbp
0x101f180a4:  pushq  %rbx
0x101f180a5:  pushq  %rax
0x101f180a6:  movq   %rdi, %rbx
0x101f180a9:  callq  0x101f17de0               ;
log4cxx::LogManager::getLoggerRepository()
0x101f180ae:  movq   8(%rax), %rsi
0x101f180b2:  movq   (%rsi), %rax
0x101f180b5:  movq   %rbx, %rdi
0x101f180b8:  callq  *120(%rax) <<<<<< THREAD  1: EXC_BAD_ACCESS
(code=EXC_I386_GPFLT)
0x101f180bb:  movq   %rbx, %rax
0x101f180be:  addq   $8, %rsp
0x101f180c2:  popq   %rbx
0x101f180c3:  popq   %rbp
0x101f180c4:  ret
0x101f180c5:  nopw   %cs:(%rax,%rax)

If I replace the logging statement with a statement that writes to
std::cerr, I do not run into any problems.

I am using log4cxx 0.10.0 on MacOS 10.9.1.

Any ideas?

- Kaspar

$ brew info log4cxx

log4cxx: stable 0.10.0

http://logging.apache.org/log4cxx/index.html

/opt/brew/Cellar/log4cxx/0.10.0 (183 files, 7.9M) *

  Built from source

Re: getRootLogger() thread-safe?

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Kaspar Fischer,
am Montag, 10. März 2014 um 18:32 schrieben Sie:

> Static local variables are not thread-safe so it looks to me as if
> you want to change that – from a user's perspective, it's nice to be
> able to assume that getRootLogger() is thread-safe. What do you think?

I tend to agree, we fixed the same problem in LOGCXX-394 as well. I
created a new bug and provided a patch for others to review:

https://issues.apache.org/jira/browse/LOGCXX-430

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow


Re: getRootLogger() thread-safe?

Posted by Kaspar Fischer <ka...@dreizak.com>.
Hi Thorsten,

Thanks a lot for the quick response! Unfortunately, we use a pre-built
package so I can't patch the code.

However, when I create a static variable

  log4cxx::LoggerPtr log4cxx_root_logger = log4cxx::Logger::getRootLogger();

and use log4cxx_root_logger in my code (instead of
log4cxx::Logger::getRootLogger()), all works fine.

Static local variables are not thread-safe so it looks to me as if you want
to change that - from a user's perspective, it's nice to be able to assume
that getRootLogger() is thread-safe. What do you think?

- Kaspar



On Mon, Mar 10, 2014 at 12:20 AM, Thorsten Schöning
<ts...@am-soft.de>wrote:

> Guten Tag Kaspar Fischer,
> am Montag, 10. März 2014 um 03:20 schrieben Sie:
>
> > Is getRootLogger() thread safe?
>
> Looks like the same problem as in LOGCXX-394 to me.
>
> https://issues.apache.org/jira/browse/LOGCXX-394
>
> > RepositorySelectorPtr& LogManager::getRepositorySelector() {
> >    //
> >    //     call to initialize APR and trigger "start" of logging clock
> >    //
> >    APRInitializer::initialize();
> >    static spi::RepositorySelectorPtr selector;
> >    return selector;
> > }
>
> > LoggerRepositoryPtr& LogManager::getLoggerRepository()
> > {
> >         if (getRepositorySelector() == 0)
> >         {
> >                 LoggerRepositoryPtr hierarchy(new Hierarchy());
> >                 RepositorySelectorPtr selector(new
> DefaultRepositorySelector(hierarchy));
> >                 getRepositorySelector() = selector;
> >         }
> >
> >         return getRepositorySelector()->getLoggerRepository();
> > }
>
> > LoggerPtr LogManager::getRootLogger()
> > {
> >         // Delegate the actual manufacturing of the logger to the logger
> repository.
> >         return getLoggerRepository()->getRootLogger();
> > }
>
> Could try to just remove the "static" in the following line?
>
> >    static spi::RepositorySelectorPtr selector;
>
> If that works, we'll consider just removing that on trunk as well,
> like with LOG4CXX-394.
>
> Mit freundlichen Grüßen,
>
> Thorsten Schöning
>
> --
> Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
> AM-SoFT IT-Systeme      http://www.AM-SoFT.de/
>
> Telefon...........05151-  9468- 55
> Fax...............05151-  9468- 88
> Mobil..............0178-8 9468- 04
>
> AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
> AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow
>
>

Re: getRootLogger() thread-safe?

Posted by Thorsten Schöning <ts...@am-soft.de>.
Guten Tag Kaspar Fischer,
am Montag, 10. März 2014 um 03:20 schrieben Sie:

> Is getRootLogger() thread safe?

Looks like the same problem as in LOGCXX-394 to me.

https://issues.apache.org/jira/browse/LOGCXX-394

> RepositorySelectorPtr& LogManager::getRepositorySelector() {
>    //
>    //     call to initialize APR and trigger "start" of logging clock
>    //
>    APRInitializer::initialize();
>    static spi::RepositorySelectorPtr selector;
>    return selector;
> }

> LoggerRepositoryPtr& LogManager::getLoggerRepository()
> {
>         if (getRepositorySelector() == 0)
>         {
>                 LoggerRepositoryPtr hierarchy(new Hierarchy());
>                 RepositorySelectorPtr selector(new DefaultRepositorySelector(hierarchy));
>                 getRepositorySelector() = selector;
>         }
>
>         return getRepositorySelector()->getLoggerRepository();
> }

> LoggerPtr LogManager::getRootLogger()
> {
>         // Delegate the actual manufacturing of the logger to the logger repository.
>         return getLoggerRepository()->getRootLogger();
> }

Could try to just remove the "static" in the following line?

>    static spi::RepositorySelectorPtr selector;

If that works, we'll consider just removing that on trunk as well,
like with LOG4CXX-394.

Mit freundlichen Grüßen,

Thorsten Schöning

-- 
Thorsten Schöning       E-Mail:Thorsten.Schoening@AM-SoFT.de
AM-SoFT IT-Systeme      http://www.AM-SoFT.de/

Telefon...........05151-  9468- 55
Fax...............05151-  9468- 88
Mobil..............0178-8 9468- 04

AM-SoFT GmbH IT-Systeme, Brandenburger Str. 7c, 31789 Hameln
AG Hannover HRB 207 694 - Geschäftsführer: Andreas Muchow