Madhu Gowda | 2 Jun 2008 14:13
Picon
Favicon

using RollingFileAppender

Hi all,

 

I am trying to make use of RollingFileAppender.

My code is as follows:

 

LoggerPtr logger( Logger::getLogger("CustomLogger"));

 

RollingFileAppender *pAppender = new RollingFileAppender();

pAppender->setName( log4cxx::helpers::Transcoder::decode("TestAppender"));

pAppender->setFile( log4cxx::helpers::Transcoder::decode("TestLogFile.txt"));

pAppender->setAppend( true);

pAppender->setMaxBackupIndex( 5);

pAppender->setMaxFileSize( log4cxx::helpers::Transcoder::decode("5 KB"));

pAppender->setLayout( new PatternLayout( log4cxx::helpers::Transcoder::decode("%d [%t] %-5p %c - %l - %m%n")));

 

logger->addAppender( fAppender);

 

This code is giving the error as:

"No output stream or file set for the appender named TestAppender"

 

But, if I create the appender as:

 

RollingFileAppender *pAppender = new RollingFileAppender( new PatternLayout( log4cxx::helpers::Transcoder::decode("%d %-5p %c - %l - %m%n")),

 log4cxx::helpers::Transcoder::decode("TestLogFile.txt"));

 

and I set the MaxBackupIndex and MaxFileSize as follows: 

 

pAppender->setMaxBackupIndex( 5);

pAppender->setMaxFileSize( log4cxx::helpers::Transcoder::decode("5 KB"));

 

It works fine but, the new log file is not getting created after the MaxFileSize (5 KB) is reached, the log messages are just getting appended to same log file ().

 

Please, suggest what is going wrong here.

 

Thanks & Regards,

Madhu Gowda

 


Curt Arnold | 2 Jun 2008 18:59
Picon
Favicon

Re: using RollingFileAppender


On Jun 2, 2008, at 7:13 AM, Madhu Gowda wrote:

> Hi all,
>
>
> I am trying to make use of RollingFileAppender.
>
> My code is as follows:
>
>
> LoggerPtr logger( Logger::getLogger("CustomLogger"));
>
>
> RollingFileAppender *pAppender = new RollingFileAppender();
>

Instead use:

RollingFileAppenderPtr pAppender(new RollingFileAppender());

Otherwise, reference counts are likely to be mismanaged.
> pAppender- 
> >setName( log4cxx::helpers::Transcoder::decode("TestAppender"));
>
> pAppender- 
> >setFile( log4cxx::helpers::Transcoder::decode("TestLogFile.txt"));
>
> pAppender->setAppend( true);
>
> pAppender->setMaxBackupIndex( 5);
>
> pAppender->setMaxFileSize( log4cxx::helpers::Transcoder::decode("5  
> KB"));
>
> pAppender->setLayout( new  
> PatternLayout( log4cxx::helpers::Transcoder::decode("%d [%t] %-5p %c  
> - %l - %m%n")));
>
>

If an appender (also applies to layouts, etc) is created with the  
default constructor, the activateOptions() method must be called after  
the properties are set.

Pool p;
pAppender->activateOptions(p);

>
> logger->addAppender( fAppender);
>
>
> This code is giving the error as:
>
> "No output stream or file set for the appender named TestAppender"
>
>
> But, if I create the appender as:
>
>
> RollingFileAppender *pAppender = new RollingFileAppender( new  
> PatternLayout( log4cxx::helpers::Transcoder::decode("%d %-5p %c - %l  
> - %m%n")),
>
>  log4cxx::helpers::Transcoder::decode("TestLogFile.txt"));
>
>
> and I set the MaxBackupIndex and MaxFileSize as follows:
>
>
> pAppender->setMaxBackupIndex( 5);
>
> pAppender->setMaxFileSize( log4cxx::helpers::Transcoder::decode("5  
> KB"));
>
>
> It works fine but, the new log file is not getting created after the  
> MaxFileSize (5 KB) is reached, the log messages are just getting  
> appended to same log file ().
>

When an constructor takes arguments, it has a call to  
activateOptions() to make it ready for action upon construction.   
However, any changes that occur after that point would need an call to  
activateOptions() to ensure that the changes are reflected in the  
behavior.

>
> Please, suggest what is going wrong here.
>
>
> Thanks & Regards,
>
> Madhu Gowda
>
>
>

thinktwice | 3 Jun 2008 10:32
Picon
Favicon

is there any com implementation that wrapper around log4cxx?


cause my solution contains vc++ project & c# project, i hope all these
projects could use the same logging system.
--

-- 
View this message in context: http://www.nabble.com/is-there-any-com-implementation-that-wrapper-around-log4cxx--tp17618711p17618711.html
Sent from the Log4cxx - Users mailing list archive at Nabble.com.

Peter Steele | 4 Jun 2008 01:39

Using the syslog appender in log4cxx

We have a multi-host, multi-application product and want to use syslog to collect logs in one location. For our Java apps, I just had to add the code

 

   <!-- Syslog events -->

   <appender name="SYSLOG" class="org.apache.log4j.net.SyslogAppender">

     <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>

     <param name="Facility" value="LOCAL7"/>

     <param name="FacilityPrinting" value="true"/>

     <param name="SyslogHost" value="myloghost"/>  

     <layout class="org.apache.log4j.PatternLayout">

       <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n"/>

     </layout>

   </appender>

 

to the log4j config file to enable our Java apps to use the syslog through the SyslogAppender. I tried the same thing in the xml file that’s used by our log4cxx-based applications and I am not seeing anything appearing in the main syslog file for these applications. What other magic do I need to do in log4cxx to get our apps to log to our syslog host? We are using the 0.9.7 release.

 

Jacob L. Anawalt | 4 Jun 2008 02:18

Re: Using the syslog appender in log4cxx

Peter Steele wrote:
> anything appearing in the main syslog file for these applications. What
> other magic do I need to do in log4cxx to get our apps to log to our
> syslog host? We are using the 0.9.7 release.
>   

While this version is no longer supported by the developers, the following 
syslog appender works on my Debian systems running 0.9.7:

         <appender name="SYSLOG" class="org.apache.log4j.SyslogAppender">
                 <param name="Threshold" value="WARN" />
                 <param name="SysLogHost" value="localhost" />
                 <param name="Facility" value="DAEMON" />
                 <layout class="org.apache.log4j.PatternLayout">
                         <param name="ConversionPattern"
                                 value="%-4r %-5p %c %x - %m" />
                 </layout>
                 <filter class="LevelRangeFilter">
                         <param name="AcceptOnMatch" value="true"/>
                         <param name="LevelMin" value="WARN" />
                         <param name="LevelMax" value="FATAL" />
                 </filter>
         </appender>

To troubleshoot, I'd start simple and go forward. Verify the rest of your 
log4cxx.xml is correct by making sure it will log to the console and then to a 
file. Then I'd try simpler syslog configurations without filters, error handlers 
and using localhost. Going forward from there use tools like logger(1) to verify 
your facility, sysloghost and other settings.

Good luck,
--

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

Peter Steele | 4 Jun 2008 15:30

RE: Using the syslog appender in log4cxx

>While this version is no longer supported by the developers, the
following 
>syslog appender works on my Debian systems running 0.9.7:

Thanks for the xml snippet, I'll give this a try. And we may very well
upgrade to the latest version, but we have 65+ machines with 0.9.7 so
it's a bit of a job to get everything upgraded...

>To troubleshoot, I'd start simple and go forward. Verify the rest of
your 
>log4cxx.xml is correct by making sure it will log to the console and
then to a 
>file. Then I'd try simpler syslog configurations without filters, error
handlers 
>and using localhost.

Right now file and console logging work fine, it's just the syslog
appender that's causing us problems, even using localhost without
filters. Hopefully your xml code will do the trick.

>Going forward from there use tools like logger(1) to verify 
>your facility, sysloghost and other settings.

I'm not familiar with logger; I'll have to check it out. Thanks.

Peter

GregN | 4 Jun 2008 20:14
Picon
Favicon

Re: Segmentation fault log4cxx 0.10.0 on app exit ( RH Linux)


I made changes you recommended in src/main/cpp/objectimpl.cpp but it
unfortunately didn't help.

It seems that #if statement is true

#if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)  
&& !defined(USE_GENERAL_ATOMICS)

   __i386__ - defined
  __x86_64__ - NOT defined
  __GNUC__ - defined
  USE_GENERAL_ATOMICS - NOT defined
  (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__) &&
!defined(USE_GENERAL_ATOMICS) - defined

The stack is:
C++ [C/C++ Local Application]	
	gdb/mi (6/4/08 1:46 PM) (Suspended)	
		Thread [1] (Suspended: Signal 'SIGSEGV' received. Description:
Segmentation fault.)	
			27 apr_pool_create_ex()
/home/grn/Projects/apr-1.2.12/memory/unix/apr_pools.c:249 0xb7d22fb7	
			26 Pool()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/pool.cpp:34 0xb7e47db7	
			25 log4cxx::helpers::IOException::formatMessage()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/exception.cpp:149
0xb7df5176	
			24 IOException()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/exception.cpp:130
0xb7df65f0	
			23 log4cxx::helpers::FileOutputStream::close()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/fileoutputstream.cpp:71
0xb7dfef2a	
			22 log4cxx::rolling::CountingOutputStream::close()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:157
0xb7e58102	
			21 log4cxx::helpers::OutputStreamWriter::close()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:157
0xb7e3f278	
			20 log4cxx::WriterAppender::closeWriter()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:157
0xb7e850b1	
			19 log4cxx::WriterAppender::close()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/writerappender.cpp:143
0xb7e851cf	
			18 log4cxx::AppenderSkeleton::finalize()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/appenderskeleton.cpp:80
0xb7dc8846	
			17 ~FileAppender()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/fileappender.cpp:88
0xb7dfafd3	
			16 ~RollingFileAppenderSkeleton()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:100
0xb7dddedc	
			15 ~RollingFileAppender()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/obsoleterollingfileappender.cpp:87
0xb7e37c55	
			14 log4cxx::helpers::ObjectImpl::releaseRef()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:84
0xb7e35e28	
			13 log4cxx::AppenderSkeleton::releaseRef()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/appenderskeleton.cpp:68
0xb7dc8819	
			12 ~ObjectPtrT()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:100
0xb7dc799c	
			11 ~AppenderAttachableImpl()
/usr/include/c++/3.4.3/bits/stl_construct.h:107 0xb7dc852c	
			10 log4cxx::helpers::ObjectImpl::releaseRef()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:84
0xb7e35e28	
			9 log4cxx::helpers::AppenderAttachableImpl::releaseRef()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/appenderattachableimpl.cpp:41
0xb7dc6bcd	
			8 ~Logger()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/helpers/objectptr.h:100
0xb7e2065c	
			7 log4cxx::helpers::ObjectImpl::releaseRef()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/objectimpl.cpp:84
0xb7e35e28	
			6 log4cxx::Logger::releaseRef()
/home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/logger.cpp:62
0xb7e1fc65	
			5 ~ObjectPtrT() /usr/local/include/log4cxx/helpers/objectptr.h:100
0x080550e3	
			4 __tcf_1() /home/grn/Projects/C++/..project related.. 0x08083e91	
			3 exit()  0x004ce467	
			2 __libc_start_main()  0x004b8e2d	
			1 _start()  0x080545ad	

--

-- 
View this message in context: http://www.nabble.com/Segmentation-fault-log4cxx-0.10.0-on-app-exit-%28-RH-Linux%29-tp17543738p17653096.html
Sent from the Log4cxx - Users mailing list archive at Nabble.com.

Peter Steele | 5 Jun 2008 16:39

RE: Using the syslog appender in log4cxx

I've been able to get the syslog appender to work, with one exception.
For our Java apps that use log4j, I have set up a custom entry in
/etc/syslog.conf for the local7 facility so that messages targeting this
facility are all logged to a custom log file. In my log4j config file I
simply have to set the Facility parameter to LOCAL7 to have log messages
directed to this custom log file. This doesn't seem to work for log4cxx.
I tried setting Facility to LOCAL7 and the log messages disappeared. It
seems I have to use DAEMON, and this directs log messages to
/var/log/messages. I'd prefer to have log4cxx send log messages to the
same LOCAL7 log file that we use for our Java apps. Any suggestions on
how to accomplish this?

-----Original Message-----
From: Peter Steele [mailto:psteele <at> maxiscale.com] 
Sent: Wednesday, June 04, 2008 6:30 AM
To: Log4CXX User
Subject: RE: Using the syslog appender in log4cxx

>While this version is no longer supported by the developers, the
following 
>syslog appender works on my Debian systems running 0.9.7:

Thanks for the xml snippet, I'll give this a try. And we may very well
upgrade to the latest version, but we have 65+ machines with 0.9.7 so
it's a bit of a job to get everything upgraded...

>To troubleshoot, I'd start simple and go forward. Verify the rest of
your 
>log4cxx.xml is correct by making sure it will log to the console and
then to a 
>file. Then I'd try simpler syslog configurations without filters, error
handlers 
>and using localhost.

Right now file and console logging work fine, it's just the syslog
appender that's causing us problems, even using localhost without
filters. Hopefully your xml code will do the trick.

>Going forward from there use tools like logger(1) to verify 
>your facility, sysloghost and other settings.

I'm not familiar with logger; I'll have to check it out. Thanks.

Peter

Curt Arnold | 5 Jun 2008 18:18
Picon
Favicon

Re: Segmentation fault log4cxx 0.10.0 on app exit ( RH Linux)


On Jun 4, 2008, at 1:14 PM, GregN wrote:

>
> I made changes you recommended in src/main/cpp/objectimpl.cpp but it
> unfortunately didn't help.
>
> It seems that #if statement is true
>
> #if (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__)
> && !defined(USE_GENERAL_ATOMICS)
>
>   __i386__ - defined
>  __x86_64__ - NOT defined
>  __GNUC__ - defined
>  USE_GENERAL_ATOMICS - NOT defined
>  (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__) &&
> !defined(USE_GENERAL_ATOMICS) - defined
>

The previous stack trace suggested that the expression was false.

> The stack is:
> C++ [C/C++ Local Application]	
> 	gdb/mi (6/4/08 1:46 PM) (Suspended)	
> 		Thread [1] (Suspended: Signal 'SIGSEGV' received. Description:
> Segmentation fault.)	
> 			27 apr_pool_create_ex()
> /home/grn/Projects/apr-1.2.12/memory/unix/apr_pools.c:249 0xb7d22fb7	
> 			26 Pool()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/pool.cpp:34  
> 0xb7e47db7	
> 			25 log4cxx::helpers::IOException::formatMessage()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/exception.cpp: 
> 149
> 0xb7df5176	
> 			24 IOException()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/exception.cpp: 
> 130
> 0xb7df65f0	
> 			23 log4cxx::helpers::FileOutputStream::close()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> fileoutputstream.cpp:71
> 0xb7dfef2a	
> 			22 log4cxx::rolling::CountingOutputStream::close()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/ 
> helpers/objectptr.h:157
> 0xb7e58102	
> 			21 log4cxx::helpers::OutputStreamWriter::close()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/ 
> helpers/objectptr.h:157
> 0xb7e3f278	
> 			20 log4cxx::WriterAppender::closeWriter()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/ 
> helpers/objectptr.h:157
> 0xb7e850b1	
> 			19 log4cxx::WriterAppender::close()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> writerappender.cpp:143
> 0xb7e851cf	
> 			18 log4cxx::AppenderSkeleton::finalize()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> appenderskeleton.cpp:80
> 0xb7dc8846	
> 			17 ~FileAppender()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> fileappender.cpp:88
> 0xb7dfafd3	
> 			16 ~RollingFileAppenderSkeleton()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/ 
> helpers/objectptr.h:100
> 0xb7dddedc	
> 			15 ~RollingFileAppender()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> obsoleterollingfileappender.cpp:87
> 0xb7e37c55	
> 			14 log4cxx::helpers::ObjectImpl::releaseRef()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/objectimpl.cpp: 
> 84
> 0xb7e35e28	
> 			13 log4cxx::AppenderSkeleton::releaseRef()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> appenderskeleton.cpp:68
> 0xb7dc8819	
> 			12 ~ObjectPtrT()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/ 
> helpers/objectptr.h:100
> 0xb7dc799c	
> 			11 ~AppenderAttachableImpl()
> /usr/include/c++/3.4.3/bits/stl_construct.h:107 0xb7dc852c	
> 			10 log4cxx::helpers::ObjectImpl::releaseRef()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/objectimpl.cpp: 
> 84
> 0xb7e35e28	
> 			9 log4cxx::helpers::AppenderAttachableImpl::releaseRef()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/ 
> appenderattachableimpl.cpp:41
> 0xb7dc6bcd	
> 			8 ~Logger()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/include/log4cxx/ 
> helpers/objectptr.h:100
> 0xb7e2065c	
> 			7 log4cxx::helpers::ObjectImpl::releaseRef()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/objectimpl.cpp: 
> 84
> 0xb7e35e28	
> 			6 log4cxx::Logger::releaseRef()
> /home/grn/Projects/apache-log4cxx-0.10.0/src/main/cpp/logger.cpp:62
> 0xb7e1fc65	
> 			5 ~ObjectPtrT() /usr/local/include/log4cxx/helpers/objectptr.h:100
> 0x080550e3	
> 			4 __tcf_1() /home/grn/Projects/C++/..project related.. 0x08083e91	
> 			3 exit()  0x004ce467	
> 			2 __libc_start_main()  0x004b8e2d	
> 			1 _start()  0x080545ad	
>

This stack trace is different since it doesn't die in  
apr_atomic_dec32, but the underlying problem is still the same, APR is  
terminated prematurely during destruction of static variables.  I have  
spent a little time trying to reproduce this issue, but haven't  
succeeded yet.

As a work around until a resolution, you could try commenting out the  
apr_terminate() call in src/main/cpp/aprinitializer.cpp.

Dale King | 5 Jun 2008 19:55
Picon

Re: Using the syslog appender in log4cxx

On Thu, Jun 5, 2008 at 10:39 AM, Peter Steele <psteele <at> maxiscale.com> wrote:
> I've been able to get the syslog appender to work, with one exception.
> For our Java apps that use log4j, I have set up a custom entry in
> /etc/syslog.conf for the local7 facility so that messages targeting this
> facility are all logged to a custom log file. In my log4j config file I
> simply have to set the Facility parameter to LOCAL7 to have log messages
> directed to this custom log file. This doesn't seem to work for log4cxx.
> I tried setting Facility to LOCAL7 and the log messages disappeared. It
> seems I have to use DAEMON, and this directs log messages to
> /var/log/messages. I'd prefer to have log4cxx send log messages to the
> same LOCAL7 log file that we use for our Java apps. Any suggestions on
> how to accomplish this?
>
> -----Original Message-----
> From: Peter Steele [mailto:psteele <at> maxiscale.com]
> Sent: Wednesday, June 04, 2008 6:30 AM
> To: Log4CXX User
> Subject: RE: Using the syslog appender in log4cxx
>
>>While this version is no longer supported by the developers, the
> following
>>syslog appender works on my Debian systems running 0.9.7:
>
> Thanks for the xml snippet, I'll give this a try. And we may very well
> upgrade to the latest version, but we have 65+ machines with 0.9.7 so
> it's a bit of a job to get everything upgraded...
>
>>To troubleshoot, I'd start simple and go forward. Verify the rest of
> your
>>log4cxx.xml is correct by making sure it will log to the console and
> then to a
>>file. Then I'd try simpler syslog configurations without filters, error
> handlers
>>and using localhost.
>
> Right now file and console logging work fine, it's just the syslog
> appender that's causing us problems, even using localhost without
> filters. Hopefully your xml code will do the trick.
>
>>Going forward from there use tools like logger(1) to verify
>>your facility, sysloghost and other settings.
>
> I'm not familiar with logger; I'll have to check it out. Thanks.
>
> Peter
>
>

That is a bug in version 0.10.0 Local 2 and higher was not implemented
correctly. See this difference to see the cut-and-paste error:

<http://svn.apache.org/viewvc/logging/log4cxx/trunk/src/main/cpp/syslogappender.cpp?r1=613005&r2=654960&pathrev=654960&diff_format=l>

It has already been fixed in the trunk version of the repository. See
this revision:

http://svn.apache.org/viewvc?view=rev&revision=654960

--

-- 
Dale King


Gmane