<configuration>
<statusListener class="ch.qos.logback.core.status.OnConsoleStatusListener" />
<appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
<!-- <evaluator class="ch.qos.logback.classic.boolex.GEventEvaluator">
<expression>
(marker != null) &&
(marker.contains("DEV") || marker.contains("TRANSACTION_FAILURE"))
</expression>
</evaluator> -->
<SMTPHost>${smtpHost}</SMTPHost>
<To>a@newegg.com</To>
<From>b@newegg.com</From>
<smtpHost>1.1.1.1</smtpHost>
<smtpPort>215</smtpPort>
<layout class="ch.qos.logback.classic.html.HTMLLayout"/>
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">
<expression>
(marker != null) &&
(marker.contains("DEV") && level == ERROR)
</expression>
</evaluator>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<root>
<level value ="debug"/>
<appender-ref ref="EMAIL" />
</root>
</configuration>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Logback Log Messages</title>
<style type="text/css">
table { margin-left: 2em; margin-right: 2em; border-left: 2px solid #AAA; } TR.even { background: #FFFFFF; } TR.odd { background: #EAEAEA; } TR.warn TD.Level, TR.error TD.Level, TR.fatal TD.Level {font-weight: bold; color: #FF4040 } TD { padding-right: 1ex; padding-left: 1ex; border-right: 2px solid #AAA; } TD.Time, TD.Date { text-align: right; font-family: courier, monospace; font-size: smaller; } TD.Thread { text-align: left; } TD.Level { text-align: right; } TD.Logger { text-align: left; } TR.header { background: #596ED5; color: #FFF; font-weight: bold; font-size: larger; } TD.Exception { background: #A2AEE8; font-family: courier, monospace;} </style>
</head>
<body>
<hr/>
<p>Log session start time Sat Dec 26 17:17:47 CST 2015</p><p></p>
<table cellspacing="0">
<tr class="header">
<td class="Date">Date</td>
<td class="Thread">Thread</td>
<td class="Level">Level</td>
<td class="Logger">Logger</td>
<td class="MDC">MDC</td>
<td class="Message">Message</td>
</tr>
<tr class="error even">
<td class="Date">2015-12-26 17:17:47,228</td> <td class="Thread">http-bio-80-exec-6</td>
<td class="Level">ERROR</td>
<td class="Logger">com.log.MyLogServlet</td>
<td class="MDC"></td>
<td class="Message">hello</td>
</tr>
</table>
</body></html>
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2015, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/
package chapters.appenders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;
import chapters.appenders.sub.sample.Bar;
/**
*
* This class can be used to check the result of a configuration file.
*
* @author Sébastien Pennec
*/
public class ConfigurationTester {
public static void main(String[] args) throws InterruptedException {
Logger logger = (Logger) LoggerFactory.getLogger(ConfigurationTester.class);
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
try {
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
lc.reset();
configurator.doConfigure(args[0]);
} catch (JoranException je) {
je.printStackTrace();
}
// After we've called Joran, let's print information about the
// internal status of logback
StatusPrinter.print(lc);
logger.debug("**Hello {}", new Bar());
MDC.put("testKey", "testValueFromMDC");
MDC.put("testKey2", "value2");
for (int i = 0; i < 10; i++) {
logger.debug("logging statement " + i);
Thread.sleep(100);
}
Bar bar = new Bar();
bar.createLoggingRequest();
}
}