本文整理汇总了Java中ch.qos.logback.classic.LoggerContext.getCopyOfPropertyMap方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.getCopyOfPropertyMap方法的具体用法?Java LoggerContext.getCopyOfPropertyMap怎么用?Java LoggerContext.getCopyOfPropertyMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.LoggerContext
的用法示例。
在下文中一共展示了LoggerContext.getCopyOfPropertyMap方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createPatternLayoutConsoleAppender
import ch.qos.logback.classic.LoggerContext; //导入方法依赖的package包/类
/**
* Set up a {@link PatternLayoutEncoder} to log plaintext. Package-private for testing.
* @param loggerContext to use for setup
* @param appenderName name of the appender
* @param serviceLog return appender for service logs if true, else return one for request logs
* @return console appender
*/
static ConsoleAppender<ILoggingEvent> createPatternLayoutConsoleAppender(
final String appenderName,
final LoggerContext loggerContext,
final boolean serviceLog) {
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
final StringBuilder sb = new StringBuilder();
Map<String, String> copyOfPropertyMap = loggerContext.getCopyOfPropertyMap();
for(Entry<String, String> entry : copyOfPropertyMap.entrySet()) {
sb.append("%property{" + entry.getKey()+ "} ");
}
final String logType = serviceLog ? "servicelog" : "requestlog";
final String pattern = sb.toString().trim().length() == 0
? ""
: sb.toString().trim() + " ";
encoder.setPattern(
"%-5level " + "[" + pattern + logType + "] "
+ "[%thread]: %message%n");
encoder.start();
final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setContext(loggerContext);
appender.setEncoder(encoder);
appender.setName(appenderName);
appender.start();
return appender;
}