0

I'm looking for a log4j2.properties snippet that I can drop in to src/test/resources just to make the No logj2 configuration file found warning disappear. If it contains other useful sample like configuration examples that's great as well.

Basically I'm looking for the .properties version of this:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss} %c{1.} [%t] %-5level} - %msg%n" />
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>
Ole
  • 41,793
  • 59
  • 191
  • 359
  • Possible duplicate of [Disabling Log4J Output in Java](http://stackoverflow.com/questions/571960/disabling-log4j-output-in-java) – Raedwald Jul 08 '16 at 07:02
  • Please remove the duplicate notification. I'm trying to silcence the warning only, while keeping the trace logging going to the console. – Ole Jul 08 '16 at 17:09
  • Edit the body of the question to indicate why it is not a duplicate of that question. – Raedwald Jul 09 '16 at 08:23

1 Answers1

1

I haven't tried it but this should do the trick.

status = error
name = PropertiesConfig

property.filename = target/logs/test.log

appender.file.type = File
appender.file.name = LogFile
appender.file.fileName = ${filename}
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d %p %C{1.} [%t] %m%n

rootLogger.level = error
rootLogger.appenderRef.stdout.ref = LogFile

Here is a log4j2.xml that I actually use in some of my unit tests.

<?xml version="1.0" encoding="UTF-8"?>

<Configuration status="ERROR">
  <properties>
    <property name="LOG_DIR">target/logs</property>
  </properties>
  <MarkerFilter marker="FLOW" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d{ABSOLUTE} %-5level # %class.%method %m%n" />
    </Console>

    <RollingFile name="log4j" fileName="${LOG_DIR}/log4j.txt" filePattern="${LOG_DIR}/archive/log4j.txt.%d{yyyyMMdd_HH}-%i">
      <PatternLayout>
        <MarkerPatternSelector defaultPattern="%d [%t] %-5p %X{loginId, userId, ipAddress, corpAcctNumber} %C{1.}.%M:%L - %m%n">
          <PatternMatch key="FLOW" pattern="%d [%t] %-5p %X{loginId, userId, ipAddress, corpAcctNumber} -------- %C{1.}.%M:%L %msg --------%n"/>
        </MarkerPatternSelector>
      </PatternLayout>
      <Policies>
        <SizeBasedTriggeringPolicy size="30 MB"/>
      </Policies>
      <DefaultRolloverStrategy min="1" max="20"/>
    </RollingFile>
  </Appenders>
  <Loggers>
    <Root level="debug">
      <AppenderRef ref="log4j" />
    </Root>
  </Loggers>
</Configuration>
rgoers
  • 8,696
  • 1
  • 22
  • 24