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 Mon, 10 Dec 2012 16:03:21 GMT

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

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

I've been working with the new beta this morning and I am still having the same issue.  First,
it appears that some refactoring was done (ie AppenderBase is now AbstractAppender), but the
documentation has not been updated to reflect these changes so I may be missing something.
 Anyway, I have updated my HappyAppender project to work with the latest beta code, all other
code and my log4j xml file remained the same.  When I run the HappyTest from within this project,
I get the following verbose output:

2012-12-10 10:50:34,277 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4j2Test/bin/com/log4j]
matching criteria: annotated with @Plugin
2012-12-10 10:50:34,277 DEBUG Checking to see if class com.log4j.HappyAppender matches criteria
[annotated with @Plugin]
2012-12-10 10:50:34,277 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin]
2012-12-10 10:50:34,277 DEBUG Generated plugins in 0.005191791 seconds
2012-12-10 10:50:34,308 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout
for element PatternLayout with params(pattern="%d{dd-MMM-yyyy (HH:mm:ss.SSS Z)} %-5level %message%n",
Configuration(Happy Configuration), null, charset="null")
2012-12-10 10:50:34,308 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4j2Test/bin/com/log4j]
matching criteria: annotated with @Plugin is assignable to LogEventPatternConverter
2012-12-10 10:50:34,308 DEBUG Checking to see if class com.log4j.HappyAppender matches criteria
[annotated with @Plugin is assignable to LogEventPatternConverter]
2012-12-10 10:50:34,308 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin is assignable to LogEventPatternConverter]
2012-12-10 10:50:34,308 DEBUG Generated plugins in 0.002251892 seconds
2012-12-10 10:50:34,308 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.ConsoleAppender
for element Console with params(PatternLayout(%d{dd-MMM-yyyy (HH:mm:ss.SSS Z)} %-5level %message%n),
null, target="SYSTEM_OUT", name="Console", suppressExceptions="null")
2012-12-10 10:50:34,308 DEBUG Jansi is not installed
2012-12-10 10:50:34,308 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout
for element PatternLayout with params(pattern="%message%n", Configuration(Happy Configuration),
null, charset="null")
2012-12-10 10:50:34,308 ERROR Null object returned for Happy in appenders
2012-12-10 10:50:34,308 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.plugins.AppendersPlugin
for element appenders with params(appenders={Console, })
2012-12-10 10:50:34,308 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4j2Test/bin/com/log4j]
matching criteria: annotated with @Plugin
2012-12-10 10:50:34,308 DEBUG Checking to see if class com.log4j.HappyAppender matches criteria
[annotated with @Plugin]
2012-12-10 10:50:34,308 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin]
2012-12-10 10:50:34,308 DEBUG Generated plugins in 0.001830191 seconds
2012-12-10 10:50:34,308 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef
for element appender-ref with params(ref="Console", level="null", null)
2012-12-10 10:50:34,308 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger
for element root with params(additivity="null", level="debug", appender-ref={org.apache.logging.log4j.core.config.AppenderRef@1fc3eae1},
properties={}, Configuration(Happy Configuration), null)
2012-12-10 10:50:34,308 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef
for element appender-ref with params(ref="Happy", level="null", null)
2012-12-10 10:50:34,324 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig
for element logger with params(additivity="null", level="info", name="happy.log", appender-ref={org.apache.logging.log4j.core.config.AppenderRef@181ea87d},
properties={}, Configuration(Happy Configuration), null)
2012-12-10 10:50:34,324 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.plugins.LoggersPlugin
for element loggers with params(loggers={root, happy.log})
2012-12-10 10:50:34,324 ERROR Unable to locate appender Happy for logger happy.log
2012-12-10 10:50:34,324 DEBUG Reconfiguration completed
10-Dec-2012 (10:50:34.324 -0500) INFO  I'm so happy!

As before, when executed from within the same project, log4j scans the classes as expected,
but is unable to create the HappyAppender.

I then exported HappyAppender to a jar and copied it to the same directory as the log4j beta
3 jars.  I then added it to the project path of my RFT test project and attempted to run the
same HappyTest code, which gave the following output:

2012-12-10 10:55:18,924 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4jRftTest/com/log4j]
matching criteria: annotated with @Plugin
2012-12-10 10:55:18,940 DEBUG Checking to see if class com.log4j.HappyScript matches criteria
[annotated with @Plugin]
2012-12-10 10:55:18,940 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin]
2012-12-10 10:55:18,940 DEBUG Generated plugins in 0.015682859 seconds
2012-12-10 10:55:18,955 ERROR Error processing element Happy: CLASS_NOT_FOUND
2012-12-10 10:55:18,971 DEBUG Calling createLayout on class org.apache.logging.log4j.core.layout.PatternLayout
for element PatternLayout with params(pattern="%d{dd-MMM-yyyy (HH:mm:ss.SSS Z)} %-5level %message%n",
Configuration(Happy Configuration), null, charset="null")
2012-12-10 10:55:18,971 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4jRftTest/com/log4j]
matching criteria: annotated with @Plugin is assignable to LogEventPatternConverter
2012-12-10 10:55:18,971 DEBUG Checking to see if class com.log4j.HappyScript matches criteria
[annotated with @Plugin is assignable to LogEventPatternConverter]
2012-12-10 10:55:18,971 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin is assignable to LogEventPatternConverter]
2012-12-10 10:55:18,971 DEBUG Generated plugins in 0.002187708 seconds
2012-12-10 10:55:18,971 DEBUG Calling createAppender on class org.apache.logging.log4j.core.appender.ConsoleAppender
for element Console with params(PatternLayout(%d{dd-MMM-yyyy (HH:mm:ss.SSS Z)} %-5level %message%n),
null, target="SYSTEM_OUT", name="Console", suppressExceptions="null")
2012-12-10 10:55:18,971 DEBUG Jansi is not installed
2012-12-10 10:55:18,971 DEBUG Calling createAppenders on class org.apache.logging.log4j.core.config.plugins.AppendersPlugin
for element appenders with params(appenders={Console})
2012-12-10 10:55:18,971 INFO Scanning for classes in [/C:/Users/Automation/IBM/rationalsdp/workspace/Log4jRftTest/com/log4j]
matching criteria: annotated with @Plugin
2012-12-10 10:55:18,971 DEBUG Checking to see if class com.log4j.HappyScript matches criteria
[annotated with @Plugin]
2012-12-10 10:55:18,971 DEBUG Checking to see if class com.log4j.HappyTest matches criteria
[annotated with @Plugin]
2012-12-10 10:55:18,971 DEBUG Generated plugins in 0.002113816 seconds
2012-12-10 10:55:18,971 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef
for element appender-ref with params(ref="Console", level="null", null)
2012-12-10 10:55:18,971 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig$RootLogger
for element root with params(additivity="null", level="debug", appender-ref={org.apache.logging.log4j.core.config.AppenderRef@280882b8},
properties={}, Configuration(Happy Configuration), null)
2012-12-10 10:55:18,986 DEBUG Calling createAppenderRef on class org.apache.logging.log4j.core.config.AppenderRef
for element appender-ref with params(ref="Happy", level="null", null)
2012-12-10 10:55:18,986 DEBUG Calling createLogger on class org.apache.logging.log4j.core.config.LoggerConfig
for element logger with params(additivity="null", level="info", name="happy.log", appender-ref={org.apache.logging.log4j.core.config.AppenderRef@677eb214},
properties={}, Configuration(Happy Configuration), null)
2012-12-10 10:55:18,986 DEBUG Calling createLoggers on class org.apache.logging.log4j.core.config.plugins.LoggersPlugin
for element loggers with params(loggers={root, happy.log})
2012-12-10 10:55:18,986 ERROR Unable to locate appender Happy for logger happy.log
2012-12-10 10:55:18,986 DEBUG Reconfiguration completed
10-Dec-2012 (10:55:18.986 -0500) INFO  I'm so happy!

So it looks like either I am doing something wrong or something still is not working.

                
> 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
>            Assignee: Ralph Goers
>              Labels: appender, extend
>             Fix For: 2.0-beta3
>
>         Attachments: Desktop.png, happyTestProject.rftjdtr, 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