3

I have been working on custom JSON layout plugin and it works fine with Log4j2.xml, I have been trying to check yml documentation but unfortunately couldn't find much info regarding the same, I have found out that most of the Java developers use XML instead of yml and its hard to find detailed documentation regarding yml, so I am asking the community for any suggestions - I have the following log4j2.xml file

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" name="example"
    packages="com.withlog4j2xml.withlog4j2xmlexample">

    <Appenders>
        <Console name="Console" target="SYSTEM_OUT" follow="true">
            <JSONEventLayout locationInfo="true" />
        </Console>
    </Appenders>

    <Loggers>
        <Root level="info" additivity="false">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>

and I used the same log4j2.xml file and converted that to log4j2.yml file

Configuration:
  status: warn

  Appenders:
    Console:
      name: Console
      target: SYSTEM_OUT
      JSONEventLayout:
        locationInfo: true

  Loggers:
    Root:
      level: info
      AppenderRef:
        ref: Console

    

but it doesn't work and it does not produce JSON output logs. I have followed below link for yml custom JSON https://blog.10pines.com/2020/03/02/log-custom-json-with-log4j2/

The closest I found is the following What is a sample default config file in YAML for log4j2? I used the exact same in my yml but it doesn't work also tried How to implement Log4j2 custom layout yaml configuration

  • According to the link, the content of `Console:` should be a list, not a mapping. Try to do `- name: Console` and indent the following lines accordingly. – flyx Jul 23 '20 at 09:13
  • Thanks for responding, but that did not made any difference – SpringFramework Jul 23 '20 at 12:45

0 Answers0