本文整理汇总了Java中ch.qos.logback.classic.Logger.setAdditive方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.setAdditive方法的具体用法?Java Logger.setAdditive怎么用?Java Logger.setAdditive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.Logger
的用法示例。
在下文中一共展示了Logger.setAdditive方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureInMemoryLogging
import ch.qos.logback.classic.Logger; //导入方法依赖的package包/类
private static void configureInMemoryLogging() {
org.slf4j.Logger rootLogger = LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
Logger logbackRootLogger = (Logger) rootLogger;
logbackRootLogger.setLevel(Level.INFO);
OutputStreamAppender<ILoggingEvent> appender = new OutputStreamAppender<>();
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("[%date] [%level] [%logger{10}] %msg%n");
ple.setContext(lc);
ple.start();
try {
ple.init(bos);
} catch (IOException e) {
}
appender.setContext(lc);
appender.setOutputStream(bos);
appender.setName("buffered");
appender.setEncoder(ple);
appender.start();
logbackRootLogger.detachAppender("console");
logbackRootLogger.addAppender(appender);
logbackRootLogger.setAdditive(true);
}
示例2: doInitializer
import ch.qos.logback.classic.Logger; //导入方法依赖的package包/类
/**
* Initializer logback
*
* @param file
* @param level
* @param maxHistory
*/
private void doInitializer(String file, String level, int maxHistory) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.detachAndStopAllAppenders();
// appender
RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
fileAppender.setContext(loggerContext);
fileAppender.setName("application");
fileAppender.setFile(file);
fileAppender.setAppend(true);
// policy
TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<ILoggingEvent>();
policy.setContext(loggerContext);
policy.setMaxHistory(maxHistory);
policy.setFileNamePattern(file + ".%d{yyyy-MM-dd}");
policy.setParent(fileAppender);
policy.start();
fileAppender.setRollingPolicy(policy);
// encoder
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%date [%thread] %-5level %logger (%file:%line\\) - %msg%n");
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.start();
rootLogger.addAppender(fileAppender);
rootLogger.setLevel(Level.toLevel(level));
rootLogger.setAdditive(false);
}
示例3: getLogger
import ch.qos.logback.classic.Logger; //导入方法依赖的package包/类
@Override
public Logger getLogger(String context) {
Logger logger = (Logger) LoggerFactory.getLogger(context);
MemoryAppender memoryAppender = new MemoryAppender(this);
PersistentAppender persistentAppender = new PersistentAppender(logFile);
logger.addAppender(memoryAppender);
logger.addAppender(persistentAppender);
logger.setLevel(Level.DEBUG);
logger.setAdditive(true); /* set to true if root should log too */
return logger;
}
示例4: createLogger
import ch.qos.logback.classic.Logger; //导入方法依赖的package包/类
public static Logger createLogger(Path pathLogs, String clientName)
{
Logger log = (Logger) LoggerFactory.getLogger("Botico-" + clientName);
log.setLevel(Level.DEBUG);
LoggerContext cont = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder pat = new PatternLayoutEncoder();
pat.setPattern("[%date] [%logger{10}|%thread] [%level] %msg%n");
pat.setContext(cont);
pat.start();
FileAppender<ILoggingEvent> fapp = new FileAppender<>();
fapp.setFile(pathLogs.resolve("botico-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd_HH-mm-ss")) + ".log").toString());
fapp.setEncoder(pat);
fapp.setContext(cont);
fapp.start();
ConsoleAppender<ILoggingEvent> capp = new ConsoleAppender<>();
capp.setTarget("System.out");
capp.setContext(cont);
capp.setEncoder(pat);
capp.start();
log.addAppender(fapp);
log.addAppender(capp);
log.setAdditive(false);
return log;
}
示例5: setupOwnLogger
import ch.qos.logback.classic.Logger; //导入方法依赖的package包/类
private static void setupOwnLogger() {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
logger = (Logger) LoggerFactory.getLogger(Values.BOT_NAME);
ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
consoleAppender.setContext(lc);
consoleAppender.setName("console");
LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
PatternLayout layout = new PatternLayout();
layout.setPattern("[%d{HH:mm:ss}] [%level] [%logger] %msg%n");
layout.setContext(lc);
layout.start();
encoder.setLayout(layout);
consoleAppender.setEncoder(encoder);
consoleAppender.start();
// disable default appender
logger.setAdditive(false);
// enable custom console appender
logger.addAppender(consoleAppender);
// set logging level
if(a.isDebug()) {
logger.setLevel(Level.DEBUG);
} else {
logger.setLevel(Level.INFO);
}
}
示例6: setupLoggingStdoutOnly
import ch.qos.logback.classic.Logger; //导入方法依赖的package包/类
/**
* Set up logback logging for service and request logs. We use only ONE appender here to write
* normal log lines to stdout for both types. Logging context is set from the keys and values
* parameters. They must be corresponding in length and all elements must be non-null and
* non-empty. However, the request logger is set up slightly differently. To guarantee that
* everything works as expected this method must be called with the fully qualified class name
* of the request logger that will be used in jetty.
* @param keys to add to all log lines
* @param values to add to all log lines
* @param requestLoggerName the request logger class name
* @param json true for json output, false for plain test
*/
public static void setupLoggingStdoutOnly(
final String[] keys,
final String[] values,
final String requestLoggerName,
final boolean json) {
if(!parametersOk(keys, values)) {
throw new IllegalArgumentException(
"Context keys and/or values are not properly formatted.");
}
final LoggerContext loggerContext = getLoggerContext(keys, values);
final Appender<ILoggingEvent> consoleAppender = json
? createJsonConsoleAppender(SERVICE_CONSOLE_APPENDER, loggerContext, true)
: createPatternLayoutConsoleAppender(SERVICE_CONSOLE_APPENDER, loggerContext, true);
// specifically cast to logback version so we set it up
final Logger rootLogger = (Logger) LoggerFactory.getLogger(
org.slf4j.Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(consoleAppender);
rootLogger.setLevel(LOG_LEVEL);
if (!Strings.isNullOrEmpty(requestLoggerName)) {
final Logger requestLogger = (Logger) LoggerFactory.getLogger(requestLoggerName);
requestLogger
.addAppender(json
? createJsonConsoleAppender(
REQUESTLOG_CONSOLE_APPENDER, loggerContext, false)
: createPatternLayoutConsoleAppender(
REQUESTLOG_CONSOLE_APPENDER, loggerContext, false));
requestLogger.setAdditive(false);
requestLogger.setLevel(LOG_LEVEL);
}
}