當前位置: 首頁>>代碼示例>>Java>>正文


Java Logger.setAdditive方法代碼示例

本文整理匯總了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);
}
 
開發者ID:spinscale,項目名稱:maxcube-java,代碼行數:26,代碼來源:Cli.java

示例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);
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:42,代碼來源:LogbackContainer.java

示例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;
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:12,代碼來源:LogImpl.java

示例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;
}
 
開發者ID:PearXTeam,項目名稱:Botico2,代碼行數:29,代碼來源:Botico.java

示例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);
	}
}
 
開發者ID:Bleuzen,項目名稱:Blizcord,代碼行數:32,代碼來源:Log.java

示例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);
    }
}
 
開發者ID:secondbase,項目名稱:secondbase,代碼行數:45,代碼來源:SecondBaseLogger.java


注:本文中的ch.qos.logback.classic.Logger.setAdditive方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。