XML schema or DTD for logback.xml?

As of June 2011, the official documentation states As shall become clear, the syntax of logback configuration files is extremely flexible. As such, it is not possible specify the allowed syntax with a DTD file or an XML Schema. There was a brief thread on the topic, but didn’t seem to go anywhere.

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

How to change root logging level programmatically for logback

Try this: import org.slf4j.LoggerFactory; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; Logger root = (Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME); root.setLevel(Level.INFO); Note that you can also tell logback to periodically scan your config file like this: <configuration scan=”true” scanPeriod=”30 seconds” > … </configuration>

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

log4j vs logback [closed]

Logback natively implements the SLF4J API. This means that if you are using logback, you are actually using the SLF4J API. You could theoretically use the internals of the logback API directly for logging, but that is highly discouraged. All logback documentation and examples on loggers are written in terms of the SLF4J API. So … Read more

How can I configure Logback to log different levels for a logger to different destinations?

I believe this would be the simplest solution: <configuration> <contextName>selenium-plugin</contextName> <!– Logging configuration –> <appender name=”STDOUT” class=”ch.qos.logback.core.ConsoleAppender”> <Target>System.out</Target> <filter class=”ch.qos.logback.classic.filter.LevelFilter”> <level>INFO</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <encoder> <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%level] %msg%n</pattern> </encoder> </appender> <appender name=”STDERR” class=”ch.qos.logback.core.ConsoleAppender”> <Target>System.err</Target> <filter class=”ch.qos.logback.classic.filter.LevelFilter”> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <encoder> <pattern>[%d{yyyy-MM-dd HH:mm:ss.SSS}] [%level] [%thread] %logger{10} [%file:%line] %msg%n</pattern> </encoder> </appender> <root level=”INFO”> <appender-ref ref=”STDOUT”/> … Read more

Logging levels – Logback – rule-of-thumb to assign log levels

I mostly build large scale, high availability type systems, so my answer is biased towards looking at it from a production support standpoint; that said, we assign roughly as follows: error: the system is in distress, customers are probably being affected (or will soon be) and the fix probably requires human intervention. The “2AM rule” … Read more

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