当前位置: 首页>>代码示例>>Java>>正文


Java AsyncAppender.start方法代码示例

本文整理汇总了Java中ch.qos.logback.classic.AsyncAppender.start方法的典型用法代码示例。如果您正苦于以下问题:Java AsyncAppender.start方法的具体用法?Java AsyncAppender.start怎么用?Java AsyncAppender.start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.classic.AsyncAppender的用法示例。


在下文中一共展示了AsyncAppender.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";
    
    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:xetys,项目名称:jhipster-ribbon-hystrix,代码行数:26,代码来源:LoggingConfiguration.java

示例2: setupFileLogging

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
private static void setupFileLogging(Logger root, ThresholdFilter filter, String logfilePath) {
    MinimalLayout formatter = new MinimalLayout(root.getLoggerContext());
    formatter.start();

    // setup the file appender
    FileAppender<ILoggingEvent> appender = new FileAppender<>();
    appender.setFile(logfilePath);
    appender.setContext(root.getLoggerContext());
    appender.setLayout(formatter);
    appender.start();

    // wrap it in an async appender
    final AsyncAppender asyncAppender = new AsyncAppender();
    asyncAppender.setContext(root.getLoggerContext());
    asyncAppender.addAppender(appender);
    asyncAppender.addFilter(filter);
    asyncAppender.start();

    // now, add it to the root logger
    root.addAppender(asyncAppender);
}
 
开发者ID:redbooth,项目名称:baseline,代码行数:22,代码来源:Logging.java

示例3: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:oktadeveloper,项目名称:jhipster-microservices-example,代码行数:33,代码来源:LoggingConfiguration.java

示例4: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:Microsoft,项目名称:MTC_Labrat,代码行数:32,代码来源:LoggingConfiguration.java

示例5: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
private static void addLogstashAppender(LoggerContext context, XmLogstashConfig config) {
    LOGGER.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + config.getAppName() + "\",\"app_port\":\"" + config.getAppPort()
        + "\",\"instance_id\":\"" + config.getInstanceId() + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(config.getLogstashHost());
    logstashAppender.setPort(config.getLogstashPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(config.getLogstashQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:xm-online,项目名称:xm-commons,代码行数:33,代码来源:LogstashConfigurer.java

示例6: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName(LOGSTASH_APPENDER_NAME);
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder=new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(),jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName(ASYNC_LOGSTASH_APPENDER_NAME);
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:34,代码来源:LoggingConfiguration.java

示例7: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);

    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:klask-io,项目名称:klask-io,代码行数:33,代码来源:LoggingConfiguration.java

示例8: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + instanceId + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:IBM,项目名称:Microservices-with-JHipster-and-Spring-Boot,代码行数:33,代码来源:LoggingConfiguration.java

示例9: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder=new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(),jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:34,代码来源:LoggingConfiguration.java

示例10: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender() {
    log.info("Initializing Logstash logging");

    LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

    // Set the Logstash appender config from JHipster properties
    logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
    logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
    logstashAppender.setCustomFields(customFields);

    // Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setMaxLength(7500);
    throwableConverter.setRootCauseFirst(true);
    logstashAppender.setThrowableConverter(throwableConverter);

    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:flanciskinho,项目名称:prove.jwt,代码行数:32,代码来源:LoggingConfiguration.java

示例11: get

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
@Override
public SlowQueryLog get() {
    Logger logger = (Logger) LoggerFactory.getLogger("sor.slow-query");
    logger.setAdditive(false);
    LoggerContext context = logger.getLoggerContext();
    logger.detachAndStopAllAppenders();

    PatternLayout logPatternLayout = new PatternLayout();
    logPatternLayout.setPattern("%-5p [%d{ISO8601," + _config.getTimeZone().getID() + "}] %m\n");
    logPatternLayout.setContext(context);
    logPatternLayout.start();

    ConsoleAppenderFactory consoleAppenderFactory = _config.getConsoleAppenderFactory();
    if (consoleAppenderFactory != null) {
        // Console is usually used only in development.  Use a synchronous appender so console output doesn't get re-ordered.
        logger.addAppender(consoleAppenderFactory.build(context, EMODB_APPLICATION_NAME, logPatternLayout));
    }

    FileAppenderFactory fileAppenderFactory = _config.getFileAppenderFactory();
    if (fileAppenderFactory != null) {
        AsyncAppender fileAsyncAppender = new AsyncAppender();
        fileAsyncAppender.addAppender(fileAppenderFactory.build(context, EMODB_APPLICATION_NAME, logPatternLayout));
        fileAsyncAppender.start();
        logger.addAppender(fileAsyncAppender);
    }

    SyslogAppenderFactory syslogAppenderFactory = _config.getSyslogAppenderFactory();
    if (syslogAppenderFactory != null) {
        AsyncAppender sysAsyncAppender = new AsyncAppender();
        sysAsyncAppender.addAppender(syslogAppenderFactory.build(context, EMODB_APPLICATION_NAME, logPatternLayout));
        sysAsyncAppender.start();
        logger.addAppender(sysAsyncAppender);
    }

    return new LogbackSlowQueryLog(logger, _config.getTooManyDeltasThreshold(), _metricRegistry);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:37,代码来源:LogbackSlowQueryLogProvider.java

示例12: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public void addLogstashAppender(LoggerContext context) {
	log.info("Initializing Logstash logging");

	LogstashSocketAppender logstashAppender = new LogstashSocketAppender();
	logstashAppender.setName("LOGSTASH");
	logstashAppender.setContext(context);
	String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"}";

	// Set the Logstash appender config from JHipster properties
	logstashAppender.setSyslogHost(jHipsterProperties.getLogging().getLogstash().getHost());
	logstashAppender.setPort(jHipsterProperties.getLogging().getLogstash().getPort());
	logstashAppender.setCustomFields(customFields);

	// Limit the maximum length of the forwarded stacktrace so that it won't exceed the 8KB UDP limit of logstash
	ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
	throwableConverter.setMaxLength(7500);
	throwableConverter.setRootCauseFirst(true);
	logstashAppender.setThrowableConverter(throwableConverter);

	logstashAppender.start();

	// Wrap the appender in an Async appender for performance
	AsyncAppender asyncLogstashAppender = new AsyncAppender();
	asyncLogstashAppender.setContext(context);
	asyncLogstashAppender.setName("ASYNC_LOGSTASH");
	asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
	asyncLogstashAppender.addAppender(logstashAppender);
	asyncLogstashAppender.start();

	context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:alikemalocalan,项目名称:MicroBlog,代码行数:32,代码来源:LoggingConfiguration.java

示例13: addLogstashAppender

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
private void addLogstashAppender(LoggerContext context) {
    log.info("Initializing Logstash logging");

    LogstashTcpSocketAppender logstashAppender = new LogstashTcpSocketAppender();
    logstashAppender.setName("LOGSTASH");
    logstashAppender.setContext(context);
    String customFields = "{\"app_name\":\"" + appName + "\",\"app_port\":\"" + serverPort + "\"," +
        "\"instance_id\":\"" + eurekaInstanceConfigBean.getInstanceId() + "\"," + "\"version\":\"" + version + "\"}";

    // More documentation is available at: https://github.com/logstash/logstash-logback-encoder
    LogstashEncoder logstashEncoder=new LogstashEncoder();
    // Set the Logstash appender config from JHipster properties
    logstashEncoder.setCustomFields(customFields);
    // Set the Logstash appender config from JHipster properties
    logstashAppender.addDestinations(new InetSocketAddress(jHipsterProperties.getLogging().getLogstash().getHost(),jHipsterProperties.getLogging().getLogstash().getPort()));

    ShortenedThrowableConverter throwableConverter = new ShortenedThrowableConverter();
    throwableConverter.setRootCauseFirst(true);
    logstashEncoder.setThrowableConverter(throwableConverter);
    logstashEncoder.setCustomFields(customFields);

    logstashAppender.setEncoder(logstashEncoder);
    logstashAppender.start();

    // Wrap the appender in an Async appender for performance
    AsyncAppender asyncLogstashAppender = new AsyncAppender();
    asyncLogstashAppender.setContext(context);
    asyncLogstashAppender.setName("ASYNC_LOGSTASH");
    asyncLogstashAppender.setQueueSize(jHipsterProperties.getLogging().getLogstash().getQueueSize());
    asyncLogstashAppender.addAppender(logstashAppender);
    asyncLogstashAppender.start();

    context.getLogger("ROOT").addAppender(asyncLogstashAppender);
}
 
开发者ID:kalnee,项目名称:trivor,代码行数:35,代码来源:LoggingConfiguration.java

示例14: asAsync

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
protected Appender<ILoggingEvent> asAsync(Appender<ILoggingEvent> appender, Context context) {
    AsyncAppender asyncAppender = new AsyncAppender();
    asyncAppender.setIncludeCallerData(false);
    asyncAppender.setQueueSize(AsyncAppenderBase.DEFAULT_QUEUE_SIZE);
    asyncAppender.setDiscardingThreshold(-1);
    asyncAppender.setContext(context);
    asyncAppender.setName(appender.getName());
    asyncAppender.addAppender(appender);
    asyncAppender.start();
    return asyncAppender;
}
 
开发者ID:bootique,项目名称:bootique-logback,代码行数:12,代码来源:AppenderFactory.java

示例15: configureRotatingLogging

import ch.qos.logback.classic.AsyncAppender; //导入方法依赖的package包/类
public static void configureRotatingLogging( String baseLoggingDir, String loglevel, String appName ) {
    
    if ( !baseLoggingDir.endsWith( "/" ) ) {
        baseLoggingDir = baseLoggingDir + "/";
    }
    
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    lc.reset();
    Logger rootLogger = getRootLogger( loglevel );
    PatternLayoutEncoder ple = getPatternLayoutEncoder( lc );
    
    String baseAppLoggingDir = baseLoggingDir;
    // set a system property so other loggers write the correct place
    System.setProperty( "krux-base-app-log-dir", baseAppLoggingDir );

    try {
        // Define file appender with layout and output log file name
        RollingFileAppender<ILoggingEvent> fileAppender = new RollingFileAppender<ILoggingEvent>();
        fileAppender.setContext( lc );
        fileAppender.setName( "krux-file-appender" );
        fileAppender.setFile( baseAppLoggingDir + appName + ".log" );
        fileAppender.setAppend( true );
        fileAppender.setEncoder( ple );
        
        FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
        rollingPolicy.setContext( lc );
        rollingPolicy.setMinIndex( 1 );
        rollingPolicy.setMaxIndex( 9 );
        rollingPolicy.setFileNamePattern( baseAppLoggingDir + appName + ".%i.log.gz" );
        rollingPolicy.setParent( fileAppender );
        rollingPolicy.start();
        
        SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>( "100MB" );
        triggeringPolicy.setContext( lc );
        triggeringPolicy.start();

        fileAppender.setRollingPolicy( rollingPolicy );
        fileAppender.setTriggeringPolicy( triggeringPolicy );
        fileAppender.start();

        // Wrap the console appenders in an async appenders
        AsyncAppender asyncOut = new AsyncAppender();
        asyncOut.setContext( lc );
        asyncOut.setDiscardingThreshold( 0 );
        asyncOut.setQueueSize( 500 );
        asyncOut.addAppender( fileAppender );
        asyncOut.setName( "stdlib-async-out" );
        asyncOut.start();

        // Add the appender to root logger
        rootLogger.addAppender( asyncOut );
        
        // wrap stdout & stderr in log4j appenders 
        StdOutErrLog.tieSystemOutAndErrToLog();
        
    } catch ( Exception e ) {
        System.out.println( "Failed to add appender !!" );
        e.printStackTrace();
    }

}
 
开发者ID:krux,项目名称:java-stdlib,代码行数:62,代码来源:LoggerConfigurator.java


注:本文中的ch.qos.logback.classic.AsyncAppender.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。