Log4j2 YAML creates several log files

My goals;

  • Create 2 log files.
  • First, only the message will be logged (nothing but messages)
  • The second journal will register all INFO journals

I did something like below;

log4j2- spring.yml

Configuration:
  status: warn
  monitorInterval: 30
  shutdownHook: disable

  CustomLevels:
    CustomLevel:
      -
        name: MESSAGE
        intLevel: 50

  Appenders:
    Console:
      name: Console
      target: SYSTEM_OUT
      PatternLayout:
        Pattern: "[%d{yyyy-MM-dd HH:mm:ss}][%-5p][%t][%c{2}] - %m%n"
    RollingFile:
      name: InfoLog
      fileName: "logs/all-info-logs.log"
      filePattern: "logs/${date:yyyy-MM}/all-info-logs-%d{MM-dd-yyyy}-%i.log.zip"
      PatternLayout:
        Pattern: "[%d{yyyy-MM-dd HH:mm:ss}][%-5p][%t][%c{2}] - %m%n"
      Policies:
        SizeBasedTriggeringPolicy:
          size: 5 MB
      DefaultRolloverStrategy:
        max: 50
    RollingFile:
      name: MessageLog
      fileName: "logs/only-message-logs.log"
      filePattern: "logs/${date:yyyy-MM}/only-message-logs-%d{MM-dd-yyyy}-%i.log.zip"
      PatternLayout:
        Pattern: "[%d{yyyy-MM-dd HH:mm:ss}][%-5p][%t][%c{2}] - %m%n"
      Policies:
        SizeBasedTriggeringPolicy:
          size: 5 MB
      DefaultRolloverStrategy:
         max: 50

  Loggers:
    Logger:
      name: com.testlog.testpackage
      additivity: false
      level: MESSAGE
      AppenderRef:
        - ref: MessageLog
    Root:
      level: info
      additivity: false
      AppenderRef:
        - ref: Console
        - ref: InfoLog

My MessageLogwork and file have been created only-message-logs.log, but it logs everything, including messages and information.

And I get an error when starting the application;

2017-12-08 16:28:34,349 main ERROR Unable to locate appender "InfoLog" for logger config "root"

The logger Rootlogs only messages on the console. And a file with a name is all-info-logs.lognever generated.

Check out the other examples in the log4j2 docs and it says that it declares several applications, for example I did.

What am I doing wrong here?

0
source share

All Articles