What are markers in Java Logging frameworks and what is a reason to use them?

This is a rehashed version my answer to the question “Best practices for using Markers in SLF4J/Logback”. Markers can be used to color or mark a single log statement. What you do with these colors, i.e. markers, is entirely up to you. However, two patterns seem to be common for marker usage. Triggering: Some appender … Read more

Best practices for using Markers in SLF4J/Logback

First, as @darioo said: MDC is used for associating multiple events with few “entities” [Markers] are used for “special” events that you want to have filtered from usual ones So your assertion that You want to use MDC for this. Markers are for highlighting “special” events–filtering, if you will–rather than “slicing”. For example, you might … Read more

Building with Lombok’s @Slf4j and Intellij: Cannot find symbol log

In addition to having Lombok plugin installed, also make sure that the “Enable annotation processing” checkbox is ticked under: Preferences > Compiler > Annotation Processors Note: starting with IntelliJ 2017, the “Enable Annotation Processing” checkbox has moved to: Settings > Build, Execution, Deployment > Compiler > Annotation Processors

Logback to log different messages to two files

It’s very possible to do something like this in logback. Here’s an example configuration: <?xml version=”1.0″?> <configuration> <appender name=”FILE” class=”ch.qos.logback.core.FileAppender”> <file>logfile.log</file> <append>true</append> <encoder> <pattern>%-4relative [%thread] %-5level %logger{35} – %msg %n</pattern> </encoder> </appender> <appender name=”ANALYTICS-FILE” class=”ch.qos.logback.core.FileAppender”> <file>analytics.log</file> <append>true</append> <encoder> <pattern>%-4relative [%thread] %-5level %logger{35} – %msg %n</pattern> </encoder> </appender> <!– additivity=false ensures analytics data only goes to … Read more

Configuring Log4j Loggers Programmatically

You can add/remove Appender programmatically to Log4j: ConsoleAppender console = new ConsoleAppender(); //create appender //configure the appender String PATTERN = “%d [%p|%c|%C{1}] %m%n”; console.setLayout(new PatternLayout(PATTERN)); console.setThreshold(Level.FATAL); console.activateOptions(); //add appender to any Logger (here is root) Logger.getRootLogger().addAppender(console); FileAppender fa = new FileAppender(); fa.setName(“FileLogger”); fa.setFile(“mylog.log”); fa.setLayout(new PatternLayout(“%d %-5p [%c{1}] %m%n”)); fa.setThreshold(Level.DEBUG); fa.setAppend(true); fa.activateOptions(); //add appender to any … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)