Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptPatternSelector properties example throws "No type attribute provided for component patternMatch" #3078

Closed
martin-dorey-hv opened this issue Oct 10, 2024 · 2 comments · Fixed by #3092
Labels
waiting-for-user More information is needed from the user

Comments

@martin-dorey-hv
Copy link
Contributor

Problem is at https://github.com/apache/logging-log4j2/blame/f7c26cd7710fdace463a370e85d0971107c91d8b/src/site/antora/modules/ROOT/examples/manual/pattern-layout/script-pattern-selector/log4j2.properties#L33

I suggest:

martind@stormy:~/tmp/D161042$ diff -u log4j2.properties{.orig,}
--- log4j2.properties.orig	2024-10-10 15:31:13.405464567 -0700
+++ log4j2.properties	2024-10-10 15:31:34.670434140 -0700
@@ -30,12 +30,12 @@
 } else {\
   return null;\
 }
-appender.0.layout.patternSelector.patternMatch.0.type = PatternMatch
-appender.0.layout.patternSelector.patternMatch.0.key = NoLocation
-appender.0.layout.patternSelector.patternMatch.0.pattern = [%-5level] %c{1.} %msg%n
-appender.0.layout.patternSelector.patternMatch.1.type = PatternMatch
-appender.0.layout.patternSelector.patternMatch.1.key = Flow
-appender.0.layout.patternSelector.patternMatch.1.pattern = [%-5level] %c{1.} ====== %C{1.}.%M:%L %msg ======%n
+appender.0.layout.patternSelector.0.type = PatternMatch
+appender.0.layout.patternSelector.0.key = NoLocation
+appender.0.layout.patternSelector.0.pattern = [%-5level] %c{1.} %msg%n
+appender.0.layout.patternSelector.1.type = PatternMatch
+appender.0.layout.patternSelector.1.key = Flow
+appender.0.layout.patternSelector.1.pattern = [%-5level] %c{1.} ====== %C{1.}.%M:%L %msg ======%n
 
 rootLogger.level = WARN
 rootLogger.appenderRef.0.ref = CONSOLE
martind@stormy:~/tmp/D161042$ 

I didn't check whether it was the only instance of such a problem, sorry. I didn't even check whether there were any other problems in this file, let alone anything constructive such as why automated testing didn't catch this. I didn't find any other examples out on the internets. If I'm trying to provide search engine fodder, for the next poor sap, I should show the full presentation, which was this, once I'd got all my other problems out of the way:

Exception in thread "main" org.apache.logging.log4j.core.config.ConfigurationException: No type attribute provided for component patternMatch
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createComponent(PropertiesConfigurationBuilder.java:338)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.processRemainingProperties(PropertiesConfigurationBuilder.java:353)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createComponent(PropertiesConfigurationBuilder.java:341)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.processRemainingProperties(PropertiesConfigurationBuilder.java:353)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createLayout(PropertiesConfigurationBuilder.java:330)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.createAppender(PropertiesConfigurationBuilder.java:223)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationBuilder.build(PropertiesConfigurationBuilder.java:155)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:56)
	at org.apache.logging.log4j.core.config.properties.PropertiesConfigurationFactory.getConfiguration(PropertiesConfigurationFactory.java:34)
	at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:544)
	at org.apache.logging.log4j.core.config.ConfigurationFactory$Factory.getConfiguration(ConfigurationFactory.java:463)
	at org.apache.logging.log4j.core.config.ConfigurationFactory.getConfiguration(ConfigurationFactory.java:321)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:719)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:749)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:46)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:138)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(AbstractLoggerAdapter.java:136)
	at org.apache.commons.logging.impl.Log4jApiLogFactory$LogAdapter.getContext(Log4jApiLogFactory.java:161)
	at org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(AbstractLoggerAdapter.java:46)
	at org.apache.commons.logging.impl.Log4jApiLogFactory.getInstance(Log4jApiLogFactory.java:210)
	at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:933)
@ppkarwasz
Copy link
Contributor

@martin-dorey-hv,

Nice catch! 💯 Could you submit a PR to fix the problem?

I didn't even check whether there were any other problems in this file, let alone anything constructive such as why automated testing didn't catch this.

We didn't integrate our code examples into our unit test suite. The log4j2.properties we converted manually from our log4j2.xml examples (which is the recommended format). Since the Java System properties configuration format is not used by the Log4j dev team and has a lot of quirks, you might find many typos in the examples.

@ppkarwasz ppkarwasz added waiting-for-user More information is needed from the user and removed waiting-for-maintainer labels Oct 15, 2024
@ppkarwasz
Copy link
Contributor

BTW: the PropertiesConfigurationFactory should not throw, when it encounters an invalid configuration file, but log an ERROR to the status logger. I reported this as #3088.

martin-dorey-hv pushed a commit to martin-dorey-hv/logging-log4j2 that referenced this issue Oct 16, 2024
ppkarwasz pushed a commit that referenced this issue Oct 16, 2024
ppkarwasz pushed a commit that referenced this issue Oct 16, 2024
hulkoba pushed a commit to neighbourhoodie/logging-log4j2 that referenced this issue Oct 21, 2024
vy pushed a commit that referenced this issue Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-for-user More information is needed from the user
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants