private static void initLogger() {
Logger rootLogger = Logger.getRootLogger();
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
try {
RollingFileAppender fileAppender = new RollingFileAppender(layout, System.getProperty("log.file", "./vnt.log"));
fileAppender.setImmediateFlush(true);
fileAppender.setThreshold(Level.DEBUG);
fileAppender.setAppend(true);
fileAppender.setMaxFileSize("5MB");
fileAppender.setMaxBackupIndex(2);
rootLogger.addAppender(fileAppender);
} catch (IOException e) {
log.error("Failed to add appender !!", e);
}
}
java类org.apache.log4j.PatternLayout的实例源码
VntMain.java 文件源码
项目:vntscraper
阅读 22
收藏 0
点赞 0
评论 0
Log4JMetricsFileWriter.java 文件源码
项目:incubator-servicecomb-java-chassis
阅读 28
收藏 0
点赞 0
评论 0
private RollingFileAppender initLogger(String loggerName, String filePrefix) {
String fileName = Paths.get(rootPath, filePrefix + "." + loggerName + ".dat").toString();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName(loggerName);
fileAppender.setFile(fileName);
fileAppender.setLayout(new PatternLayout("%m%n"));
fileAppender.setAppend(true);
fileAppender.setMaxFileSize(maxFileSize);
fileAppender.setMaxBackupIndex(maxFileCount);
fileAppender.activateOptions();
return fileAppender;
}
SPLGroungControlTest.java 文件源码
项目:SPLGroundControl
阅读 26
收藏 0
点赞 0
评论 0
@BeforeClass
public static void setUpClass() throws Exception {
//Configure log4j
ConsoleAppender console = new ConsoleAppender();
String PATTERN = "%d [%p|%c|%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
Logger.getRootLogger().addAppender(console);
System.out.println("SETUP: Starting SPLGroundControl...");
config.init(args);
daemon.init(new SPLGroundControl.SPLDaemonContext(args));
daemon.start();
}
EndPointHealthServiceImpl.java 文件源码
项目:endpoint-health
阅读 22
收藏 0
点赞 0
评论 0
private void setupLogging() {
LogManager.getLogManager().reset();
Logger.getRootLogger().getLoggerRepository().resetConfiguration();
final Logger rootLogger = Logger.getRootLogger();
final PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
final Level level = endPointHealthConfiguration.logLevel();
final ConsoleAppender consoleAppender = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_ERR);
consoleAppender.setThreshold(level);
consoleAppender.activateOptions();
final FileAppender fileAppender = new FileAppender();
fileAppender.setFile(endPointHealthConfiguration.logFile().getAbsolutePath());
fileAppender.setLayout(layout);
fileAppender.setThreshold(level);
fileAppender.setAppend(true);
fileAppender.setErrorHandler(new FallbackAppenderErrorHandler(rootLogger, fileAppender, consoleAppender));
rootLogger.addAppender(fileAppender);
fileAppender.activateOptions();
}
AgentConfigurationServiceImpl.java 文件源码
项目:ats-framework
阅读 20
收藏 0
点赞 0
评论 0
private void attachPassiveDbAppender(
DbAppenderConfiguration appenderConfiguration,
long timestamp ) {
// create the new appender
PassiveDbAppender attachedAppender = new PassiveDbAppender(ThreadsPerCaller.getCaller());
// calculate the time stamp offset, between the test executor and the agent
attachedAppender.calculateTimeOffset(timestamp);
attachedAppender.setAppenderConfig(appenderConfiguration);
// use a default pattern, as we log in the db
attachedAppender.setLayout(new PatternLayout("%c{2}: %m%n"));
attachedAppender.activateOptions();
// attach the appender to the logging system
Category log = Logger.getRootLogger();
log.setLevel(Level.toLevel(appenderConfiguration.getLoggingThreshold().toInt()));
log.addAppender(attachedAppender);
}
TestLogMessage.java 文件源码
项目:log4j-aws-appenders
阅读 28
收藏 0
点赞 0
评论 0
@Test
public void testAsciiMessageFromEventDefaultLayout() throws Exception
{
final long timestamp = System.currentTimeMillis();
final String text = "test";
LoggingEvent event = createLoggingEvent(timestamp, text, null);
LogMessage message = new LogMessage(event, new PatternLayout());
// the default pattern appends a newline
String expectedText = text + "\n";
assertEquals("timestmap", timestamp, message.getTimestamp());
assertEquals("message", expectedText, message.getMessage());
assertArrayEquals("message as bytes", expectedText.getBytes("UTF-8"), message.getBytes());
assertEquals("size", 5, message.size());
}
TestLogMessage.java 文件源码
项目:log4j-aws-appenders
阅读 27
收藏 0
点赞 0
评论 0
@Test
public void testUnicodeMessageFromEventDefaultLayout() throws Exception
{
final long timestamp = System.currentTimeMillis();
final String text = "\u0024\u00a2\u20ac";
LoggingEvent event = createLoggingEvent(timestamp, text, null);
LogMessage message = new LogMessage(event, new PatternLayout());
// the default pattern appends a newline
String expectedText = text + "\n";
assertEquals("timestmap", timestamp, message.getTimestamp());
assertEquals("message", expectedText, message.getMessage());
assertArrayEquals("message as bytes", expectedText.getBytes("UTF-8"), message.getBytes());
assertEquals("size", 7, message.size());
}
TestLogMessage.java 文件源码
项目:log4j-aws-appenders
阅读 23
收藏 0
点赞 0
评论 0
@Test
// at this point we'll assume that UTF-8 conversion works as expected
public void testAsciiMessageFromEventDefaultLayoutWithException() throws Exception
{
final long timestamp = System.currentTimeMillis();
final String text = "test";
final Exception ex = new Exception();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
pw.println(text);
ex.printStackTrace(pw);
pw.close();
String expectedText = sw.toString();
LoggingEvent event = createLoggingEvent(timestamp, text, ex);
LogMessage message = new LogMessage(event, new PatternLayout());
assertEquals("explicit timestamp", timestamp, message.getTimestamp());
assertEquals("message as string", expectedText, message.getMessage());
}
DeadSocketTlsTest.java 文件源码
项目:LightSIP
阅读 21
收藏 0
点赞 0
评论 0
public void setUp() {
Logger root = Logger.getRootLogger();
root.setLevel(Level.DEBUG);
root.addAppender(new ConsoleAppender(
new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
// setup TLS properties
System.setProperty( "javax.net.ssl.keyStore", TlsTest.class.getResource("testkeys").getPath() );
System.setProperty( "javax.net.ssl.trustStore", TlsTest.class.getResource("testkeys").getPath() );
System.setProperty( "javax.net.ssl.keyStorePassword", "passphrase" );
System.setProperty( "javax.net.ssl.keyStoreType", "jks" );
this.shootist = new BadShootist();
this.shootme = new BadShootme();
shootist.setSocketDisconnectWorstCase(true);
shootme.setSocketDisconnectWorstCase(true);
this.shootme.init();
}
MarkLogicMonitor.java 文件源码
项目:marklogic-monitoring-extension
阅读 18
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws TaskExecutionException {
ConsoleAppender ca = new ConsoleAppender();
ca.setWriter(new OutputStreamWriter(System.out));
ca.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
ca.setThreshold(Level.TRACE);
logger.getRootLogger().addAppender(ca);
final MarkLogicMonitor monitor = new MarkLogicMonitor();
final Map<String, String> taskArgs = new HashMap<String, String>();
taskArgs.put("config-file", "src/main/resources/conf/config.yml");
taskArgs.put("metrics-file", "src/main/resources/conf/metrics.xml");
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
try {
monitor.execute(taskArgs, null);
} catch (Exception e) {
logger.error("Error while running the task", e);
}
}
}, 2, 30, TimeUnit.SECONDS);
}
iBenchDriver.java 文件源码
项目:ibench
阅读 27
收藏 0
点赞 0
评论 0
private static void setUpExperimentalLogger(File pathF) throws IOException {
Logger.getRootLogger().removeAllAppenders();
log.removeAllAppenders();
PropertyConfigurator.configure("resource/log4jproperties.txt");
FileAppender resultAppender = new FileAppender(
new PatternLayout("%m"),
new File(pathF, "result.txt").toString(), false);
LevelRangeFilter infoFilter = new LevelRangeFilter();
infoFilter.setLevelMin(Level.INFO);
infoFilter.setLevelMax(Level.FATAL);
infoFilter.setAcceptOnMatch(true);
resultAppender.addFilter(infoFilter);
log.addAppender(resultAppender);
Logger.getLogger(iBench.class).addAppender(resultAppender);
}
iBenchDriver.java 文件源码
项目:ibench
阅读 35
收藏 0
点赞 0
评论 0
private static void setUpConfigLogger(File pathF, String configName) throws IOException {
Logger.getRootLogger().removeAllAppenders();
String nameSuffix = configName.replace(".txt", "");
PropertyConfigurator.configure("resource/log4jproperties.txt");
FileAppender logFileAppender = new FileAppender(
new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"),
new File(pathF, "log_" + nameSuffix + ".txt").toString(), false);
Logger.getRootLogger().addAppender(logFileAppender);
if (opt.logToConsole)
Logger.getRootLogger().addAppender(new ConsoleAppender(
new PatternLayout("%-4r [%t] %-5p %c %x - %m%n")));
}
Log.java 文件源码
项目:traccar-service
阅读 32
收藏 0
点赞 0
评论 0
public static void setupLogger(Config config) throws IOException {
Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
Appender appender = new DailyRollingFileAppender(
layout, config.getString("logger.file"), "'.'yyyyMMdd");
LogManager.resetConfiguration();
LogManager.getRootLogger().addAppender(new NullAppender());
logger = Logger.getLogger(LOGGER_NAME);
logger.addAppender(appender);
logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
// Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
@Override
public InternalLogger newInstance(String string) {
return new NettyInternalLogger();
}
});
Log.logSystemInfo();
Log.info("Version: " + getAppVersion());
}
LogUtil.java 文件源码
项目:Log4Reports
阅读 35
收藏 0
点赞 0
评论 0
public LogUtil(LogConfig config, Object obj){
this.logConfig = config;
if(LogConfig.logType == 0){
report = new ExtentReports(config.getExtentLogPath(),false);
File configFile = new File(System.getProperty("user.dir") + "\\configs\\extent-config.xml");
if(configFile.exists()) {
report.loadConfig(configFile);
}
testLog = report.startTest(String.valueOf(obj));
}else{
logger = Logger.getLogger(String.valueOf(obj));
Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} [%p] %c:%L �� %m%n");
try {
Appender appender = new FileAppender(layout, config.getLog4jPath());
logger.addAppender(appender);
} catch (IOException e) {
e.printStackTrace();
}
}
}
TestContainerLogAppender.java 文件源码
项目:hadoop
阅读 21
收藏 0
点赞 0
评论 0
@Test
public void testAppendInClose() throws Exception {
final ContainerLogAppender claAppender = new ContainerLogAppender();
claAppender.setName("testCLA");
claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
claAppender.setContainerLogDir("target/testAppendInClose/logDir");
claAppender.setContainerLogFile("syslog");
claAppender.setTotalLogFileSize(1000);
claAppender.activateOptions();
final Logger claLog = Logger.getLogger("testAppendInClose-catergory");
claLog.setAdditivity(false);
claLog.addAppender(claAppender);
claLog.info(new Object() {
public String toString() {
claLog.info("message1");
return "return message1";
}
});
claAppender.close();
}
TestAuditLogs.java 文件源码
项目:hadoop
阅读 28
收藏 0
点赞 0
评论 0
private void configureAuditLogs() throws IOException {
// Shutdown the LogManager to release all logger open file handles.
// Unfortunately, Apache commons logging library does not provide
// means to release underlying loggers. For additional info look up
// commons library FAQ.
LogManager.shutdown();
File file = new File(auditLogFile);
if (file.exists()) {
assertTrue(file.delete());
}
Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
// disable logging while the cluster startup preps files
logger.setLevel(Level.OFF);
PatternLayout layout = new PatternLayout("%m%n");
RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
logger.addAppender(appender);
}
LogUtils.java 文件源码
项目:Jerkoff
阅读 33
收藏 0
点赞 0
评论 0
/**
*
* @param prop
* @param clazz
* @return
*/
public static Logger getLogger(Properties prop, Class<?> clazz) {
Logger LOG = Logger.getLogger(clazz);
String appName = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.APP_NAME);
String fileDir = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_DIR);
String patternLayout = PropertiesUtils.getRequiredProperty(prop,
PropertiesUtils.LOG_PATTERN);
String level = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_LEVEL);
LOG.setLevel(Level.toLevel(level, Level.INFO));
DailyRollingFileAppender rollingAppender = new DailyRollingFileAppender();
rollingAppender.setFile(fileDir + "/" + appName + ".log");
rollingAppender.setLayout(new PatternLayout(patternLayout));
rollingAppender.setDatePattern("'.'yyyy-MM-dd");
rollingAppender.activateOptions();
LOG.addAppender(rollingAppender);
LOG.setAdditivity(false);
return LOG;
}
StressTest.java 文件源码
项目:MLE5109-Course-samples
阅读 22
收藏 0
点赞 0
评论 0
public static void main(String[] args) throws Exception {
Logger.getRootLogger().addAppender(new ConsoleAppender(new PatternLayout("%d{MM-dd HH:mm:ss,SSS} [%t] %5p: %m%n")));
Logger.getRootLogger().setLevel(Level.DEBUG);
final RecoveryMessage recoveryMessage = new RecoveryMessage("GROUP1~1~ADD~data1");
final RecoveryMessage recoveryMessage2 = new RecoveryMessage("GROUP1~1~ADD~data1");
Service service = new Service(Arrays.asList("GROUP1", "GROUP2"), 10);
service.process(recoveryMessage);
ExecutorService executorService = Executors.newSingleThreadExecutor();
executorService.execute(() -> {
IntStream.rangeClosed(0, 5000)
.mapToObj(count -> new RecoveryMessage("GROUP1~" + count + "~ADD~data2"))
.forEach(service::process);
Logger.getRootLogger().info("Recovery done");
});
service.process(recoveryMessage2);
service.start();
executorService.shutdown();
Utils.simulateWork(TimeUnit.SECONDS.toMillis(2));
}
TestContainerLogAppender.java 文件源码
项目:aliyun-oss-hadoop-fs
阅读 19
收藏 0
点赞 0
评论 0
@Test
public void testAppendInClose() throws Exception {
final ContainerLogAppender claAppender = new ContainerLogAppender();
claAppender.setName("testCLA");
claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
claAppender.setContainerLogDir("target/testAppendInClose/logDir");
claAppender.setContainerLogFile("syslog");
claAppender.setTotalLogFileSize(1000);
claAppender.activateOptions();
final Logger claLog = Logger.getLogger("testAppendInClose-catergory");
claLog.setAdditivity(false);
claLog.addAppender(claAppender);
claLog.info(new Object() {
public String toString() {
claLog.info("message1");
return "return message1";
}
});
claAppender.close();
}
TestAuditLogs.java 文件源码
项目:aliyun-oss-hadoop-fs
阅读 27
收藏 0
点赞 0
评论 0
private void configureAuditLogs() throws IOException {
// Shutdown the LogManager to release all logger open file handles.
// Unfortunately, Apache commons logging library does not provide
// means to release underlying loggers. For additional info look up
// commons library FAQ.
LogManager.shutdown();
File file = new File(auditLogFile);
if (file.exists()) {
assertTrue(file.delete());
}
Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
// disable logging while the cluster startup preps files
logger.setLevel(Level.OFF);
PatternLayout layout = new PatternLayout("%m%n");
RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
logger.addAppender(appender);
}
Exec.java 文件源码
项目:wring
阅读 25
收藏 0
点赞 0
评论 0
/**
* Push and collect logs.
* @return Logs
* @throws IOException If fails
*/
private String log() throws IOException {
final org.apache.log4j.Logger root =
org.apache.log4j.Logger.getRootLogger();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final Appender appender = new ThreadAppender(
new PatternLayout("%t %p %m\n"),
baos
);
root.addAppender(appender);
try {
this.pipe.status(this.agent.push(this.events));
return baos.toString();
} finally {
root.removeAppender(appender);
}
}
Printer.java 文件源码
项目:DBTestCompare
阅读 22
收藏 0
点赞 0
评论 0
public static void init(CmpSqlResultsConfig cmpSqlResultsConfig) {
log.debug("Initializing logger / printer ...");
ConsoleAppender consoleAppender = (ConsoleAppender) Logger.getRootLogger().getAppender("stdout");
if (cmpSqlResultsConfig.getLogger() != null && cmpSqlResultsConfig.getLogger().getLogLevel() !=
null && !cmpSqlResultsConfig.getLogger().getLogLevel().isEmpty()) {
Logger.getRootLogger().setLevel(Level.toLevel(cmpSqlResultsConfig.getLogger().getLogLevel()));
}
if (cmpSqlResultsConfig.getLogger().isTeamcityLogsEnabled()) {
consoleAppender.setLayout(new PatternLayout("%m%n"));
}
consoleAppender.addFilter(new Filter() {
@Override
public int decide(LoggingEvent loggingEvent) {
if(loggingEvent.getMessage() instanceof String == false) return ACCEPT;
boolean isTCMsg = ((String) loggingEvent.getMessage()).contains(TCMessages.TC);
// before threads (and buffering messages for TC) we allowed "common" logs
// boolean isNotTCMsg = ((String) loggingEvent.getMessage()).contains(TCMessages.NOT_TC);
if (cmpSqlResultsConfig.getLogger().isTeamcityLogsEnabled()) {
return isTCMsg ? ACCEPT : DENY;
// return isNotTCMsg ? DENY : ACCEPT;
} else {
return isTCMsg ? DENY : ACCEPT;
}
}
});
}
SeedboxSync.java 文件源码
项目:SeedboxSync
阅读 21
收藏 0
点赞 0
评论 0
/**
* Configures the logger.
*/
private static void configureLogging() {
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd' 'HH:mm:ss.SSS} [%-5p] [%c] - %m%n");
ConsoleAppender console = new ConsoleAppender();
console.setLayout(layout);
console.setThreshold(Level.INFO);
console.activateOptions();
DailyRollingFileAppender file = new DailyRollingFileAppender();
file.setFile("log/app.log");
file.setDatePattern("'.'yyyy-MM-dd");
file.setLayout(layout);
file.activateOptions();
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
logger.addAppender(console);
logger.addAppender(file);
}
TestContainerLogAppender.java 文件源码
项目:big-c
阅读 17
收藏 0
点赞 0
评论 0
@Test
public void testAppendInClose() throws Exception {
final ContainerLogAppender claAppender = new ContainerLogAppender();
claAppender.setName("testCLA");
claAppender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
claAppender.setContainerLogDir("target/testAppendInClose/logDir");
claAppender.setContainerLogFile("syslog");
claAppender.setTotalLogFileSize(1000);
claAppender.activateOptions();
final Logger claLog = Logger.getLogger("testAppendInClose-catergory");
claLog.setAdditivity(false);
claLog.addAppender(claAppender);
claLog.info(new Object() {
public String toString() {
claLog.info("message1");
return "return message1";
}
});
claAppender.close();
}
TestAuditLogs.java 文件源码
项目:big-c
阅读 33
收藏 0
点赞 0
评论 0
private void configureAuditLogs() throws IOException {
// Shutdown the LogManager to release all logger open file handles.
// Unfortunately, Apache commons logging library does not provide
// means to release underlying loggers. For additional info look up
// commons library FAQ.
LogManager.shutdown();
File file = new File(auditLogFile);
if (file.exists()) {
assertTrue(file.delete());
}
Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
// disable logging while the cluster startup preps files
logger.setLevel(Level.OFF);
PatternLayout layout = new PatternLayout("%m%n");
RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
logger.addAppender(appender);
}
FreedomLogger.java 文件源码
项目:erp
阅读 22
收藏 0
点赞 0
评论 0
public static Logger getLogger(final Class<?> cl, final String initFile, final String property) {
Properties properties;
Logger c = null;
try {
ManagerIni mi = initFile != null ? ManagerIni.createManagerIniFile(initFile) : ManagerIni.createManagerIniParameter();
properties = mi.getSession("FreedomLogger");
c = Logger.getLogger(cl.getCanonicalName(), myFactory);
Layout layout = new PatternLayout(LAYOUT_DEFAULT);
c.addAppender(new FileAppender(layout, properties.get(property).toString(), true));
}
catch (Exception e) {
e.printStackTrace();
}
return c;
}
TestUtil.java 文件源码
项目:Vitruv
阅读 24
收藏 0
点赞 0
评论 0
/**
* Initializes console logger for tests. Sets the logger level to
* {@link Level#ERROR} by default. If the VM property <i>logOutputLevel</i>
* is specified, it is used to determine the logger level.
*/
public static void initializeLogger() {
Logger.getRootLogger().setLevel(Level.ERROR);
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger()
.addAppender(new ConsoleAppender(new PatternLayout("[%-5p] %d{HH:mm:ss,SSS} %-30C{1} - %m%n")));
String outputLevelProperty = System.getProperty(VM_ARGUMENT_LOG_OUTPUT_LEVEL);
if (outputLevelProperty != null) {
if (!Logger.getRootLogger().getAllAppenders().hasMoreElements()) {
Logger.getRootLogger().addAppender(new ConsoleAppender());
}
Logger.getRootLogger().setLevel(Level.toLevel(outputLevelProperty));
} else {
Logger.getRootLogger().setLevel(Level.ERROR);
}
}
LogfileHandlerTest.java 文件源码
项目:bktail2
阅读 21
收藏 0
点赞 0
评论 0
@Before
public void setUp() throws Exception {
try {
Files.delete(Paths.get(FILEPATH));
} catch (Exception e) {
// TODO: handle exception
}
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile(FILEPATH);
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(true);
fa.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(fa);
}
MDCLoggingTest.java 文件源码
项目:flowable-engine
阅读 17
收藏 0
点赞 0
评论 0
private void setCustomLogger() {
String PATTERN = "Modified Log *** ProcessDefinitionId=%X{mdcProcessDefinitionID} executionId=%X{mdcExecutionId} mdcProcessInstanceID=%X{mdcProcessInstanceID} mdcBusinessKey=%X{mdcBusinessKey} mdcTaskId=%X{mdcTaskId} %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
console.setName("MemoryAppender");
appenders = new ArrayList<Appender>();
Enumeration<?> appendersEnum = Logger.getRootLogger().getAllAppenders();
while (appendersEnum.hasMoreElements()) {
Appender object = (Appender) appendersEnum.nextElement();
appenders.add(object);
}
removeAppenders();
Logger.getRootLogger().addAppender(console);
}
MDCLoggingTest.java 文件源码
项目:flowable-engine
阅读 16
收藏 0
点赞 0
评论 0
private void setCustomLogger() {
String PATTERN = "Modified Log *** ProcessDefinitionId=%X{mdcProcessDefinitionID} executionId=%X{mdcExecutionId} mdcProcessInstanceID=%X{mdcProcessInstanceID} mdcBusinessKey=%X{mdcBusinessKey} mdcTaskId=%X{mdcTaskId} %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.DEBUG);
console.activateOptions();
console.setName("MemoryAppender");
appenders = new ArrayList<>();
Enumeration<?> appendersEnum = Logger.getRootLogger().getAllAppenders();
while (appendersEnum.hasMoreElements()) {
Appender object = (Appender) appendersEnum.nextElement();
appenders.add(object);
}
removeAppenders();
Logger.getRootLogger().addAppender(console);
LogMDC.setMDCEnabled(true);
}