[
https://issues.apache.org/jira/browse/LOG4J2-3519?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17543121#comment-17543121
]
XIAOMING ZHAO commented on LOG4J2-3519:
---------------------------------------
[~vy]
Thanks a lot for your reply!
I open the log4j debug and the following is some of my understanding, please
correct me if it's wrong:
1). it firstly scanning osgi/bundles, since my plugin is put under osgi/custo
directory, not in osgi/bundles. but I am not sure if osgi/custo will be scaned
first,
2). then it watching log4j2.xml file:
DEBUG StatusLogger Watching configuration
'/opt/SPS_22_5_R1/osgi/instance/log4j2.xml' for lastModified Fri May 27
07:39:49 EDT 2022 (1653651589120)
1249 DEBUG StatusLogger Apache Log4j Core 2.17.1 initializing configuration
XmlConfiguration[location=/opt/SPS_22_5_R1/osgi/instance/log4j2.xml]
1250 DEBUG StatusLogger Installed 1 script engine
1251 DEBUG StatusLogger Oracle Nashorn version: 1.8.0_322, language:
ECMAScript, threading: Not Thread Safe, compile: true, names: [nashorn,
Nashorn, js, JS, JavaScript, javascript, ECMAScript, ecmascri pt],
factory class: jdk.nashorn.api.scripting.NashornScriptEngineFactory
1252 DEBUG StatusLogger PluginManager 'Core' found 127 plugins
1253 DEBUG StatusLogger PluginManager 'Level' found 0 plugins
1254 DEBUG StatusLogger PluginManager 'Lookup' found 16 plugins
I saw some log it build the plugin and appender. since my custom plugin was not
loaded, so building the RollingFile appender will report error "ERROR
StatusLogger RollingFile contains invalid attributes "UnifiedLoggingFormat",
3). then later: I saw some log like
1942 TRACE StatusLogger Using default SystemClock for timestamps.
1943 DEBUG StatusLogger org.apache.logging.log4j.core.util.SystemClock does
not support precise timestamps.
1944 TRACE StatusLogger Using DummyNanoClock for nanosecond timestamps.
1945 DEBUG StatusLogger Reconfiguration complete for
context[name=com.mycompany.as.service.impl.fileconfig] at URI
/opt/SPS_22_5_R1/osgi/instance/log4j2.xml
(org.apache.logging.log4j.core.LoggerContext@744932e6) with optional
ClassLoader: null
1946 DEBUG StatusLogger Shutdown hook enabled. Registering a new one.
it tried to reconfigure for different context.
I can see at this time the plugin was loaded. but it's too late already I
think.
> Log4j2 failed to load custom plugin
> ------------------------------------
>
> Key: LOG4J2-3519
> URL: https://issues.apache.org/jira/browse/LOG4J2-3519
> Project: Log4j 2
> Issue Type: Bug
> Components: Plugins
> Affects Versions: 2.17.1
> Reporter: XIAOMING ZHAO
> Priority: Major
>
> We got some issue to load the custom plugin.
> we add annotation Plugin like the following:
> @Plugin(name = "UnifiedLoggingFormat", category = Node.CATEGORY,
> elementType = Layout.ELEMENT_TYPE, printObject = true)
> public class UnifiedLoggingFormat extends AbstractStringLayout
> then add the annotationProcessor in build.gradle
> annotationProcessor( 'org.apache.logging.log4j:log4j-core:2.17.1')
>
> after the build, we can see the
> META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat in
> the class jar file.
> > jar tvf *appender*.jar
> 0 Tue May 24 14:18:40 EDT 2022 META-INF/
> 1077 Tue May 24 14:18:40 EDT 2022 META-INF/MANIFEST.MF
> 0 Tue May 24 14:18:40 EDT 2022 META-INF/org/
> 0 Tue May 24 14:18:40 EDT 2022 META-INF/org/apache/
> 0 Tue May 24 14:18:40 EDT 2022 META-INF/org/apache/logging/
> 0 Tue May 24 14:18:40 EDT 2022 META-INF/org/apache/logging/log4j/
> 0 Tue May 24 14:18:40 EDT 2022 META-INF/org/apache/logging/log4j/core/
> 0 Tue May 24 14:18:40 EDT 2022
> META-INF/org/apache/logging/log4j/core/config/
> 0 Tue May 24 14:18:40 EDT 2022
> META-INF/org/apache/logging/log4j/core/config/plugins/
> 236 Tue May 24 14:18:40 EDT 2022
> META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
>
> then in log42j.xml, we added the package of this custom plugin class.
> <Configuration status="trace" monitorInterval="30"
> packages="com.server.logging.log4jappenders, com.common.utils">
>
> but we still got the problem
> FelixDispatchQueue DEBUG Took 0.003516 seconds to load 0 plugins from package
> com.server.logging.log4jappenders
> FelixDispatchQueue DEBUG Took 0.000117 seconds to load 0 plugins from package
> com.common.utils
>
> Would you please help out?
--
This message was sent by Atlassian Jira
(v8.20.7#820007)