logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aaron Shepherd (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-95) Adding a custom appender Appender
Date Wed, 24 Oct 2012 18:08:14 GMT

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

Aaron Shepherd commented on LOG4J2-95:
--------------------------------------

I am having a similar issue with using a custom appender with Rational Functional Tester (RFT)
scripts.  RFT is essentially plugin for Eclipse which uses java code to drive automation testing
of web interfaces, however it specifies its own "main" method and performs its own class loading.
 To debug my issue I created a basic project which was contained the following elements:

- A log4j2.xml configuration file located in the root of the project which references my custom
appender and specifies its package
- A custom appender, HappyAppender, annotated as instructed, in the package com.log4j
- A standard java file with a main method in the package com.log4j
- A standard RFT script file with a main method in the package com.log4j

Both the java file and the RFT script have the exact same code in their main methods.  When
executed with the configuration's "verbose" option set to "true", the output of the java execution
indicates that it scanned the com.log4j package and the appender class was found:

2012-10-24 13:59:38,283 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4jRftTest/com/log4j]
matching criteria: annotated with @Plugin
2012-10-24 13:59:38,283 DEBUG Checking to see if class com.log4j.HappyAppender matches criteria
[annotated with @Plugin]
2012-10-24 13:59:38,288 DEBUG Checking to see if class com.log4j.HappyScript matches criteria
[annotated with @Plugin]
2012-10-24 13:59:38,308 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin]
2012-10-24 13:59:38,308 DEBUG Generated plugins in 0.026926816 seconds

However, the verbose output of the RFT script execution does not contain the same message
and instead displays an error that the appender class could not be found:

2012-10-24 13:33:46,887 DEBUG Generated plugins in 0.000241231 seconds
2012-10-24 13:33:46,892 ERROR Error processing element Happy: CLASS_NOT_FOUND

Being that these files are all in the same package of the same project, executing the same
code and referencing the same configuration file, the only difference I can think of as to
why one execution could find the appender and the other could not is that RFT does its own
class loading.  I verified that the class loader returned by HappyScript.class.getClassLoader()
is different from the one returned by LogManager.class.getClassLoader(), and that the class
loader returned by HappyScript.class.getClassLoader() is the same as the one returned by LogManager.class.getClassLoader().

Am on the right track with this, or should the loader difference not matter?

                
> Adding a custom appender Appender
> ---------------------------------
>
>                 Key: LOG4J2-95
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-95
>             Project: Log4j 2
>          Issue Type: Question
>          Components: Configurators
>    Affects Versions: 2.0-beta1
>         Environment: Windows 7 x64, Java 7 x86, Eclipse 3.8.1 x86, Eclipse RCP plugin
application
>            Reporter: Robert Breunung
>              Labels: appender, extend
>         Attachments: Desktop.png, LogDemo.zip
>
>
> Hello,
> since two days I'm working with Log4j 2 . I try to migrate from Log4J. I'm using it in
an Eclipse application. I put the necessary jars of the binary distribution into a basic plugin
and a log4j2.xml into the root. This worked well so far. Now I tried to add a custom appender
to log4j. The class is in the default source package of the Eclipse plugin. Annotations are
set like in the homepage documentation.
> In the first try I tried to provide the package of the Appender via the log4j2.xml. I
set the attribute package in the configuration element. It seemed to me, the attribute is
completely ignored? At least the class from the given package was not loaded.
> In the second try I tried to provide the package via the static method '...log4j.core.config.plugin.PluginManager.addPackage'.
I debugged the method to get a hint why it didn't work. It tried to transform my package 'com.application.logging'
into a URI 'com/application/logging' and started to search with it somehow. It might have
found them treating them as file, as the classes were lying in a subdirectory. But as there
was no file scheme in the beginning of the URI, it searched a not existing jar.
> The XML parser of the configuration can't resolve the name of my appender in the end.
> Do you have an idea then I do anything wrong, or then there is an open issue? I can provide
more details on request. Is there a programmatical way to register my appender to Log4J 2
before the Logger initialization?
> Sincerely
> Robert Breunung

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message