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 Unnikrishnan Udinoor <uu...@Brocade.COM> on 2007/11/28 21:07:28 UTC
On Static Linking - Could not instantiate class [org.apache.log4j.ConsoleAppender]
Hi,
I am using log4cxx 0.9.7 version. On dynamically linking to the log4cxx
library my C++ application works fine with the logging.
On changing the linking to static log4cxx , I get errors stating that
unable to instantiate the class.
Can someone help me to fix this issue ? Thanks a lot in Advance.
To be specific, this is the error I am getting.
Could not instantiate class [org.apache.log4j.ConsoleAppender].
Class 'org.apache.log4j.ConsoleAppender' not found
Could not instantiate appender named "stdout".
Could not instantiate class
[org.apache.log4j.RollingFileAppender].
Class 'org.apache.log4j.RollingFileAppender' not found
Could not instantiate appender named "R".
My log4j.proerties file is as follows:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} [%t]
%-5p %c{1}:%L - %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=app.log
log4j.appender.R.MaxFileSize=100KB
# Keep one backup file
log4j.appender.R.MaxBackupIndex=1
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{ABSOLUTE} [%t] %-5p
%c{1}:%L - %m%n
log4j.rootLogger=trace, stdout,R
Re: On Static Linking - Could not instantiate class [org.apache.log4j.ConsoleAppender]
Posted by Curt Arnold <ca...@apache.org>.
On Nov 28, 2007, at 2:07 PM, Unnikrishnan Udinoor wrote:
> Hi,
>
> I am using log4cxx 0.9.7 version. On dynamically linking to the
> log4cxx library my C++ application works fine with the logging.
>
> On changing the linking to static log4cxx , I get errors stating
> that unable to instantiate the class.
>
> Can someone help me to fix this issue ? Thanks a lot in Advance.
>
> To be specific, this is the error I am getting.
>
Use of log4cxx 0.9.7 is discouraged. Please consider moving to the
SVN HEAD. I remember a lot of pain with using log4cxx 0.9.7 from a
static library and those issues should be fixed in the SVN HEAD.
The issue is due to the class registration information is only linked
in when there is some explicit reference to the appender in the code.
In this case, the linker did not see any reference to ConsoleAppender
or RollingFileAppender when it linked your app, so those object files
weren't linked into your app. Since they weren't linked the static
constructor that adds those classes to the list of available classes
and so you get the class not found messages. If you really want to
use 0.9.7, you need to compel the linker to bring the appenders and
layouts that you need into the app. You could do that by having
something (even unreachable code) in your app call
ConsoleAppender::getStaticClass(), etc.