Log4j2

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.foo.Bar" level="trace">
<AppenderRef ref="Console"/>
</Logger>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
  • Logger: The Logger element here represents the configuration for a Logger object. You can specify settings like level which control what level of logs should be emitted. You connect your loggers to specific appenders using AppenderRef.
  • Appender: this specifies the destination for your log events (the logs you emit). In the above example, we specify a Console appender; some other types of appenders are File appender, JDBC appender etc.
  • PatternLayout: this specifies how to format your log events when sending it to that destination
Logger logger = LogManager.getLogger(getClass());

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store