You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "darkSheep404 (via GitHub)" <gi...@apache.org> on 2025/01/06 09:14:22 UTC
[I] Log4j2 yml config do not support YAML Anchors and Aliases (logging-log4j2)
darkSheep404 opened a new issue, #3358:
URL: https://github.com/apache/logging-log4j2/issues/3358
## Description
Log4j2 yml config do not support YAML Anchors and Aliases with error Logger contains an invalid element or attribute "<<"
```
Configuration:
status: WARN
Appenders:
RollingFileTemplate: &RollingFileTemplate
ignoreExceptions: false
PatternLayout:
pattern: "[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%X{traceId},%X{spanId}] [%pid] [%thread] %-5level %X{class}.%M - %msg%n"
Policies:
SizeBasedTriggeringPolicy:
size: "50 MB"
DefaultRolloverStrategy:
max: 200
RollingFile:
- name: XX_LOGGER_LOG
fileName: ./logs/xx/${env:HOSTNAME:-}/app/app.log
filePattern: "./logs/xx/${env:HOSTNAME:-}/app/app_%d{yyyy}-%i.log.gz"
<<: *RollingFileTemplate
Loggers:
Root:
level: INFO
AppenderRef:
- ref: CONSOLE_OUT_APPENDER
- ref: XX_LOGGER_LOG
```
```
main ERROR Unable to locate plugin for LoggerTemplate
2025-01-06T08:35:01.514260458Z 2025-01-06 08:35:01,514 main ERROR Logger contains an invalid element or attribute "<<"
2025-01-06T08:35:01.514794013Z 2025-01-06 08:35:01,514 main ERROR Logger contains an invalid element or attribute "<<"
2025-01-06T08:35:01.515709563Z 2025-01-06 08:35:01,515 main ERROR Logger contains an invalid element or attribute "<<"
2025-01-06T08:35:01.516202917Z 2025-01-06 08:35:01,516 main ERROR Logger contains an invalid element or attribute "<<"
2025-01-06 08:35:01,516 main ERROR Unable to invoke factory method in class org.apache.logging.log4j.core.config.LoggersPlugin for element Loggers: java.lang.NullPointerException
```
## Configuration
**Version:** [2.18.0]
**Operating system:** [redheat]
**JDK:** [JDK 8 ]
## Logs
```
[Stacktraces, errors, etc. relevant applications logs.]
```
## Reproduction
```
```
[An isolated test reproducing the test.
JUnit tests similar to the ones in the code base are extremely appreciated.]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Log4j2 yml config do not support YAML Anchors and Aliases (logging-log4j2)
Posted by "ppkarwasz (via GitHub)" <gi...@apache.org>.
ppkarwasz commented on issue #3358:
URL: https://github.com/apache/logging-log4j2/issues/3358#issuecomment-2572901859
The YAML features that you can use in a Log4j configuration depend on the features supported by the parser we use.
Since the [Jackson YAML data format module](https://github.com/FasterXML/jackson-dataformats-text/blob/master/yaml) does not support the [`<<` merge key YAML extension](https://yaml.org/type/merge.html), you can not use it in a Log4j configuration file. Log4j will automatically support merge keys, if FasterXML/jackson-dataformats-text#171 is ever implemented.
If you wish to use merge keys in a Log4j configuration file consider:
- contributing a PR to the Jackson project that solves FasterXML/jackson-dataformats-text#171. This is the **preferred** solution, since it does not require a change to the tree parser used by Log4j.
- or contributing an [`AbstractConfiguration`](https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/config/AbstractConfiguration.html) implementation to Log4j that is based on [SnakeYAML](https://bitbucket.org/snakeyaml/snakeyaml/src/master/), which is the low-level parser used by Jackson. Since adding an additional **direct** dependency to Log4j has security implications, please discuss it on the [`dev@logging.apache.org` mailing list](https://logging.apache.org/support.html#discussions-maintainer) first, if you choose this way.
**Remark**: Regardless of the support for merge keys, your configuration file would not work, since `RollingFileTemplate` is not a valid configuration snippet: it lacks the **required** `name`, `fileName` and `filePattern` attributes. This will always result in a configuration error, because Log4j Core interprets **all** the children of `Appenders` as appender definitions.
You should use something like this instead (again: assuming merge keys are supported by `jackson-dataformat-yaml`, which is **not** the case right now):
```yaml
RollingFile:
- &template
name: FOO_LOG
fileName: logs/foo.log
filePattern: logs/foo.%i.log.gz
ignoreExceptions: false
PatternLayout:
pattern: "%d [%t] %-5p %c{1.} - %m%n"
Policies:
SizeBasedTriggeringPolicy:
size: "50 MB"
DefaultRolloverStrategy:
max: 200
- <<: *template
name: BAR_LOG
fileName: logs/bar.log
filePattern: logs/bar.%i.log.gz
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Log4j2 yml config do not support YAML Anchors and Aliases (logging-log4j2)
Posted by "darkSheep404 (via GitHub)" <gi...@apache.org>.
darkSheep404 closed issue #3358: Log4j2 yml config do not support YAML Anchors and Aliases
URL: https://github.com/apache/logging-log4j2/issues/3358
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Log4j2 yml config do not support YAML Anchors and Aliases (logging-log4j2)
Posted by "darkSheep404 (via GitHub)" <gi...@apache.org>.
darkSheep404 commented on issue #3358:
URL: https://github.com/apache/logging-log4j2/issues/3358#issuecomment-2573085556
got it , many thx
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@logging.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org