Fabian Jacquet | 5 Oct 10:49 2010
Picon

Async appender and const char *

Hi all,

We detected a problem if we use a dynamic DLL using Log4cxx on Windows.
We use AsyncAppenders and we have a lot of DLL dynamically loaded.

LocationInfo::fileName and methodName are const char* but it's possible that the AsyncAppender use those variables after the unload of the DLL which added the message. So the char* redirect to a deleted memory.
The application crash after the unload of the dll if the AsyncAppender is a bit slow.

To fix this problem we replaced the type of those two variables to std::string. So we have a copy.

But we don't know if this is the best solution.

Dana Irvin | 7 Oct 00:31 2010

RE: Filtering Loggers added to the LogManager

Hello all. I’m curious as to the functionality of the LogManager and the various configurators in Log4cxx. Is there a way to filter out loggers from being added to the LogManager based on a runtime parameter? I load a set of configuration files, some with logger names that represent a hierarchy I’m interested in, some with ones I’m not. But all the files are loaded up. Is there a way to filter those loggers out so their respective appenders aren’t activated?

 

-D


This e-mail and any attachments are confidential CVG, Inc/Avtec Systems communications. If you are not the intended recipient, please delete this message and notify the sender. The views expressed are those of the sender and not necessarily those of CVG,Inc/Avtec Systems. All emails are scanned for viruses, but no guarantees are made that it is virus-free.
Curt Arnold | 7 Oct 06:16 2010
Picon

Re: Filtering Loggers added to the LogManager

The configurators would be responsible for creating the appenders, activating them and attaching them to
the logger repository.  Don't think there is anything that you can do at the LogManager or
LoggerRepository level to interfere with the activation of the appenders which is what I think you want to avoid.

If you aren't interested in a branch of the hierarchy, you could always remove the appenders from the
configuration.  In general, appenders try to obtain their resources at configuration time for a few good
reasons.  You could write an appender that obtains its resources at the first handled logging event, but
your first logged event would be very expensive and you'd really need to watch for concurrency issues.  The
standard appenders were not carefully designed for concurrency and avoid most of their potential
dangers by being activated early.  I don't expect many of them would work well if they had multiple threads
firing at them and the first one was trying to obtain resources.

On Oct 6, 2010, at 5:31 PM, Dana Irvin wrote:

> Hello all. I’m curious as to the functionality of the LogManager and the various configurators in
Log4cxx. Is there a way to filter out loggers from being added to the LogManager based on a runtime
parameter? I load a set of configuration files, some with logger names that represent a hierarchy I’m
interested in, some with ones I’m not. But all the files are loaded up. Is there a way to filter those
loggers out so their respective appenders aren’t activated?
>  
> -D
> 
> This e-mail and any attachments are confidential CVG, Inc/Avtec Systems communications. If you are not
the intended recipient, please delete this message and notify the sender. The views expressed are those
of the sender and not necessarily those of CVG,Inc/Avtec Systems. All emails are scanned for viruses, but
no guarantees are made that it is virus-free.

s243a | 12 Oct 09:07 2010
Picon

Extendening/wrapping Logger?


The code shown bellow was given as an example of how to extend Loger what I 
don't get is why logger was made a static field. Would this mean you would need 
a separate class for every instance?

directory.  It is a bit out of date (my fault), but it includes some tips for  
extending various portions of log4j.> - Paul > Paul Glezen > Consulting IT 
Specialist > IBM Software Services for WebSphere > 818 539 3321 > AIM: 
pfglezenibm > YIM: pfglezen > ICQ: 179406599 > Please respond to "Log4J 
Developers List" <log4j-dev <at> logging.apache.org>  >  > To:	log4j-dev <at> 
logging.apache.orgcc:	 Subject:	How to extendLogger Class> Hi  > I am using 
Logger class in my project..BUt All the functions are of typestatic type and we 
cant override the static functions in subclasss..so how can  i extend Logger 
class.Is there anyway..Please suggest me> Thanx in advanceNidhi Garg > Software 
Development Engineer (R&D)Barco | Control RoomsTel +91(0) (120) 2421651(10 
Lines) Ext. 245Fax +91(0) (120) 242 1691  >   >Hi, > >  Try using the following 
code snippet > >public class MyLogger >    extends Logger { >   >  static Logger 
logger; > >//in the constructor, create the object of Logger class >  public 
RALogger(String name) { >    super (name); >    logger = this.getLogger(name); >    
logger.setLevel(Level.ALL); >  }//Override the methods and here you can massage 
the data as required by you  >before you print it... >  public void debug(Object 
message) {  >    logger.debug(message); >  } >  public void debug(Object 
message, Throwable t) {  >    logger.debug(message, t); >  } >  public void 
error(Object message) {  >    logger.error(message); >  } >  public void 
error(Object message, Throwable t) {  >    logger.error(message, t); >  } > >  
public void fatal(Object message) {  >    logger.fatal(message); >  } >  public 
void fatal(Object message, Throwable t) {  >    logger.fatal(message, t); >  } > 
>  public void info(Object message) {  >    logger.info(message); >  } >   >  
public void info(Object message, Throwable t) {  >    logger.info(message, t); >  
} > >  public void warn(Object message) {  >    logger.warn(message); >  } >  
public void warn(Object message, Throwable t) {  >    logger.warn(message, t); >  
} > > >} > >Regards, >Deepal Mehta
http://web.archiveorange.com/archive/v/uhq8tUYjy7IxiVqTYDg9

Thorsten Schöning | 12 Oct 18:24 2010
Picon

exception std::out_of_range in StringHelper::startsWith

Hello,

I get an out_of_range exception everytime I use a logger which name is
longer than the name of the root logger and wonder if anyone else ran
into this problem, too. We use a pretty old Borland Builder 5, may it
be an implementation issue of the stl? Reading how
basic_string::compare works for other implementations the current
startWith should work, in my opinion.

http://www.sgi.com/tech/stl/basic_string.html

I had to make the following changes:

Index: stringhelper.cpp
===================================================================
--- stringhelper.cpp    (Revision 1652)
+++ stringhelper.cpp    (Arbeitskopie)
 <at>  <at>  -79,6 +79,11  <at>  <at> 

 bool StringHelper::startsWith(const LogString& s, const LogString& prefix)
 {
+    if (s.length() < prefix.length())
+    {
+      return false;
+    }
+
     return s.compare(0, prefix.length(), prefix) == 0;
 }

Mit freundlichen Grüßen,

Thorsten Schöning

--

-- 
Thorsten Schöning
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig

Telefon: Potsdam: 0331-743881-0
E-Mail:  tschoening <at> am-soft.de
Web:     http://www.am-soft.de

AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow

Thorsten Schöning | 15 Oct 12:14 2010
Picon

apr_terminate called too early...

Hello,

I have a GUI-application in Borland C++-Builder 5 which I needed to
add logging support using log4cxx. It started fine but I noticed
problems after closing the application. Like others on the net I have
the problem that the application crashes during accessing or deleting
some mutexes during destruction of different objects. Because I didn't
find a real solution or advice what might be the problem, just some
infos on locking problems or stuff like that, I tried to look into
this myself.

What I have found is that apr_terminate is called during
deconstruction of APRInitializer before the access problems or
exceptions occur. This makes sense, because the problem was that some
apr-mutexes where inaccessible in some point during application
shutdown and all those mutexes are owned by apr, if I understood
correctly.

From my point of view I would have expected that apr_terminate is the
last thing called in Log4cxx but it seems that after deconstruction of
APRInitializer and apr_terminate deconstructing objects just continues
with some Loggers, Appenders etc. All of them use mutexes which aren't
available anymore if apr_terminate was called before.

It does seem that theres only one instance of APRInitializer available
during runtime and that apr_initiliaze is called only once, therefore
the one call of apr_terminate I noticed really kills all objects and
memory. I didn't understand how and when APRInitializer is
deconstructed, though.

So, can it be correct that apr_terminate is called before everything
else has finished and all Objects using apr-mutexes released them
properly? If I uncomment apr_terminate, the application seems to
finish properly.

Mit freundlichen Grüßen,

Thorsten Schöning

--

-- 
Thorsten Schöning
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig

Telefon: Potsdam: 0331-743881-0
E-Mail:  tschoening <at> am-soft.de
Web:     http://www.am-soft.de

AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow

Thorsten Schöning | 15 Oct 13:53 2010
Picon

get method name of logging caller...

Hello,

is there any way to get the method name of the logging caller in the
log message? In some places %M is mentioned, but it doesn't seem to
work and is not in the documentation of class PatternLayout. With
log4perl and log4j I'm able to log the whole class path down to a
method and wondered if this is possible using log4cxx, too. Seems one
has to stay with line number, right?

Mit freundlichen Grüßen,

Thorsten Schöning

--

-- 
Thorsten Schöning
AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig

Telefon: Potsdam: 0331-743881-0
E-Mail:  tschoening <at> am-soft.de
Web:     http://www.am-soft.de

AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow

rhosyn@purplescarab.com | 15 Oct 22:48 2010

apr_terminate called too early...

 >From    Thorsten Schöning <tschoening <at> am-soft.de>
 >reply-to    Log4CXX User <log4cxx-user <at> logging.apache.org>
 >to    Log4CXX User <log4cxx-user <at> logging.apache.org>
 >date    15 October 2010 11:14
 >subject    apr_terminate called too early...
 >mailing list <log4cxx-user.logging.apache.org> Filter messages from 
this mailing list
 >
 >Hello,
 >
 >I have a GUI-application in Borland C++-Builder 5 which I needed to
 >add logging support using log4cxx. It started fine but I noticed
 >problems after closing the application. Like others on the net I have
 >the problem that the application crashes during accessing or deleting
 >some mutexes during destruction of different objects. Because I didn't
 >find a real solution or advice what might be the problem, just some
 >infos on locking problems or stuff like that, I tried to look into
 >this myself.
 >
 >What I have found is that apr_terminate is called during
 >deconstruction of APRInitializer before the access problems or
 >exceptions occur. This makes sense, because the problem was that some
 >apr-mutexes where inaccessible in some point during application
 >shutdown and all those mutexes are owned by apr, if I understood
 >correctly.
 >
 >From my point of view I would have expected that apr_terminate is the
 >last thing called in Log4cxx but it seems that after deconstruction of
 >APRInitializer and apr_terminate deconstructing objects just continues
 >with some Loggers, Appenders etc. All of them use mutexes which aren't
 >available anymore if apr_terminate was called before.
 >
 >It does seem that theres only one instance of APRInitializer available
 >during runtime and that apr_initiliaze is called only once, therefore
 >the one call of apr_terminate I noticed really kills all objects and
 >memory. I didn't understand how and when APRInitializer is
 >deconstructed, though.
 >
 >So, can it be correct that apr_terminate is called before everything
 >else has finished and all Objects using apr-mutexes released them
 >properly? If I uncomment apr_terminate, the application seems to
 >finish properly.
 >
 >Mit freundlichen Grüßen,
 >
 >Thorsten Schöning
 >
 >--
 >Thorsten Schöning
 >AM-SoFT IT-Systeme - Hameln | Potsdam | Leipzig
 >
 >Telefon: Potsdam: 0331-743881-0
 >E-Mail:  tschoening <at> am-soft.de
 >Web:     http://www.am-soft.de
 >
 >AM-SoFT GmbH IT-Systeme, Konsumhof 1-5, 14482 Potsdam
 >Amtsgericht Potsdam HRB 21278 P, Geschäftsführer: Andreas Muchow

We ran into the same issue viz-a-vis APRInitializer in the product we 
were building - see

http://mail-archives.apache.org/mod_mbox/logging-log4cxx-dev/200901.mbox/%3C4975157F.8070001 <at> purplescarab.com%3E 
for a discussion.

Ensuring safe order of destruction of objects in C++ (especially if 
there are statics, & also especially so if there are multiple threads) 
is fraught with difficulty.

The ideal solution (imho) would be to implement a "Singleton holder" as 
discussed in the above link to guarantee a correct/safe order of 
destruction.

However, in the absence of sufficient  time/resources to remodel log4cxx 
along these lines we ended up (as a "dirty" but pragmatic measure) 
patching our log4cxx by commenting out apr_terminate (just as you suggest).

Hth,

Rhosyn

Jacob L. Anawalt | 15 Oct 23:08 2010

Re: get method name of logging caller...

On 10/15/2010 5:53 AM, Thorsten Schöning wrote:
> Hello,
>
> is there any way to get the method name of the logging caller in the
> log message?

As you say, the log4j docs document %M in the PatternLayout (while 
log4cxx does not) but caution against the inefficiency of it's use. 
Additionally "The Complete Log4J Manual" (a good document to have) 
points out that even in Java this information can be discarded by the 
compiler.

In log4cxx %F and %L provide the file name and line number 
respectively, but that is because they can rely on the ubiquitious 
__FILE__ and __LINE__ macros. The LOG4CXX_LOCATION macro is documented 
to use __LOG4CXX_FUNC__ with a value of "".

If your compiler and flags support __FUNCTION__, you could work that 
into your message or change the definition of __LOG4CXX_FUNC__ and go 
on to implement %M.

I haven't even glanced at the code to see where that's at. I just 
inflexibly typed the function name into a DEBUG message near the top 
of the message call, or sometimes used a NDC to track the call stack 
in debug logs.

Good luck,
--

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt <at> geckosoftware.com
435-752-8026

Jacob L. Anawalt | 15 Oct 23:30 2010

Re: exception std::out_of_range in StringHelper::startsWith

On 10/12/2010 10:24 AM, Thorsten Schöning wrote:
> I get an out_of_range exception everytime I use a logger which name is
> longer than the name of the root logger

I'm not sure what this named root logger you're referring too. In xml 
config it's just <root> and in property format it's log4j.rootLogger.

I have logging hierarchies where the child logger's name is longer 
than the parent's in a java like way only I sometimes use 
abbreviations of my classes and sometimes use names/levels for 
non-class things. Eg, for a postgresql accessing class:

PQ
PQ.Worker
PQ.TX
PQ.TX.Lookup

I've been building with the GCC on Debian for a few years now without 
any out_of_range errors to do with log4cxx loggers.

--

-- 
Jacob Anawalt
Gecko Software, Inc.
janawalt <at> geckosoftware.com
435-752-8026


Gmane