当前位置: 首页>>代码示例>>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;未经允许,请勿转载。