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


Java ConsoleAppender.setTarget方法代碼示例

本文整理匯總了Java中ch.qos.logback.core.ConsoleAppender.setTarget方法的典型用法代碼示例。如果您正苦於以下問題:Java ConsoleAppender.setTarget方法的具體用法?Java ConsoleAppender.setTarget怎麽用?Java ConsoleAppender.setTarget使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ch.qos.logback.core.ConsoleAppender的用法示例。


在下文中一共展示了ConsoleAppender.setTarget方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wrongTarget

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
@Test
  public void wrongTarget() {
    ConsoleAppender<Object> ca = (ConsoleAppender<Object>) getAppender();
    EchoEncoder<Object> encoder = new EchoEncoder<Object>();
    encoder.setContext(context);
    ca.setContext(context);
    ca.setTarget("foo");
    ca.setEncoder(encoder);
    ca.start();
    ca.doAppend("a");
    StatusChecker checker = new StatusChecker(context);
    //21:28:01,246 + WARN in ch.qos.logback.core.ConsoleAppender[null] - [foo] should be one of [SystemOut, SystemErr]
    //21:28:01,246   |-WARN in ch.qos.logback.core.ConsoleAppender[null] - Using previously set target, System.out by default.
//    StatusPrinter.print(context);

    checker.assertContainsMatch(Status.WARN, "\\[foo\\] should be one of \\[SystemOut, SystemErr\\]");

  }
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:19,代碼來源:ConsoleAppenderTest.java

示例2: doFailSafeConfiguration

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
private void doFailSafeConfiguration() {
    // Not really fail-safe, just less likely to fail
    final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    rootLogger.addAppender(appender);
    appender.setContext(context);
    appender.setTarget("System.err");

    PatternLayout layout = new PatternLayout();
    appender.setLayout(layout);
    layout.setPattern("%msg%n%ex");
    layout.setContext(context);

    layout.start();
    appender.start();
}
 
開發者ID:Pushjet,項目名稱:Pushjet-Android,代碼行數:21,代碼來源:LogbackLoggingConfigurer.java

示例3: getStdErrAppender

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
/**
 * Create a stderr appender.
 *
 * @param context The logger context to use.
 * @return An appender writing to stderr.
 */
private static Appender<ILoggingEvent> getStdErrAppender(final LoggerContext context) {

  // Setup format
  final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(context);
  encoder.setPattern(
      "%date{HH:mm:ss.SSS} %property{ident}[%property{pid}]: %-5level [%thread] %logger{0}: %msg%n");
  encoder.setCharset(Charsets.UTF_8);
  encoder.start();

  // Setup stderr appender
  final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
  appender.setTarget("System.err");
  appender.setName("stderr");
  appender.setEncoder(encoder);
  appender.setContext(context);
  appender.start();

  return appender;
}
 
開發者ID:spotify,項目名稱:logging-java,代碼行數:27,代碼來源:LoggingConfigurator.java

示例4: createLogger

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的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: createConsoleAppender

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
protected ConsoleAppender<ILoggingEvent> createConsoleAppender(LoggerContext context, String defaultLogFormat) {
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
    appender.setName("console");
    appender.setContext(context);
    appender.setTarget(target.getLogbackTarget());

    LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
    layoutEncoder.setLayout(createLayout(context, defaultLogFormat));
    appender.setEncoder(layoutEncoder);

    appender.start();

    return appender;
}
 
開發者ID:bootique,項目名稱:bootique-logback,代碼行數:15,代碼來源:ConsoleAppenderFactory.java

示例6: setupAppender

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
private ConsoleAppender setupAppender(String target, LoggerContext ctx, Encoder enc) {
    ConsoleAppender appender = new ConsoleAppender();
    appender.setTarget(target);
    appender.setContext(ctx);
    appender.setEncoder(enc);

    appender.start();

    return appender;
}
 
開發者ID:Evolveum,項目名稱:midpoint,代碼行數:11,代碼來源:Log.java

示例7: writeTo

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
void writeTo(Outstream target) {
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
    appender.setTarget(target.target.getName());
    appender.setEncoder(LogHelper.encoder("%date{ISO8601} [" + target.marker + "] - %msg%n"));
    appender.start();
    appenders.add(appender);
}
 
開發者ID:gocd,項目名稱:gocd,代碼行數:8,代碼來源:AgentOutputAppender.java

示例8: initLogback

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
/**
 * Initialize Logback
 */
private static void initLogback() {
    // reset logger context
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    
    // shared console appender
    ConsoleAppender.setContext(context);
    ConsoleAppender.setTarget("System.out");
    
    PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
    consoleEncoder.setContext(context);
    consoleEncoder.setPattern(LogPattern);
    consoleEncoder.start();
    ConsoleAppender.setEncoder(consoleEncoder);
    ConsoleAppender.start();
    
    // rolling file
    String logFile = getFilePath() + File.separatorChar + getFileName();
    FileAppender.setContext(context);
    FileAppender.setFile(logFile);
    
    // log pattern
    PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
    fileEncoder.setContext(context);
    fileEncoder.setPattern(LogPattern);
    fileEncoder.start();
    FileAppender.setEncoder(fileEncoder);
    
    // rolling policy
    FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
    rollingPolicy.setContext(context);
    rollingPolicy.setParent(FileAppender);
    rollingPolicy.setFileNamePattern(logFile + "%i.zip");
    rollingPolicy.setMinIndex(1);
    rollingPolicy.setMaxIndex(1);
    rollingPolicy.start();
    
    // file max size - if fileLimit is 0, set max file size to maximum allowed
    long fileLimit = getFileLimitInKBytes() != 0 ? getFileLimitInKBytes() * 1024 : Long.MAX_VALUE;
    SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>(String.valueOf(fileLimit));
    triggeringPolicy.start();
    
    FileAppender.setRollingPolicy(rollingPolicy);
    FileAppender.setTriggeringPolicy(triggeringPolicy);
    FileAppender.start();
}
 
開發者ID:RicardoJTSantos,項目名稱:ScriptAgentNewRelicPlugin,代碼行數:50,代碼來源:Logger.java

示例9: configureStdOutLogging

import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
public static void configureStdOutLogging( String loglevel ) {

        if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
            System.err.println("Logger is not using logback, skipping logging configuration");
            return;
        }

        try {
            LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
            lc.reset();
            Logger rootLogger = getRootLogger( loglevel );
            PatternLayoutEncoder ple = getPatternLayoutEncoder( lc );

            // ops would like us to log to console unless an app
            // has a specific need not to
            ConsoleAppender<ILoggingEvent> stdOutAppender = new ConsoleAppender<ILoggingEvent>();
            stdOutAppender.setContext( lc );
            stdOutAppender.setName( "stdlib-console-out" );
            stdOutAppender.setTarget( "System.out" );
            stdOutAppender.setEncoder( ple );
            
            Filter<ILoggingEvent> stdOutFilter = new StdOutFilter();
            stdOutAppender.addFilter( stdOutFilter );
            stdOutFilter.start();
            stdOutAppender.start();

            ple = getPatternLayoutEncoder( lc );
            
            ConsoleAppender<ILoggingEvent> errorAppender = new ConsoleAppender<ILoggingEvent>();
            errorAppender.setContext( lc );
            errorAppender.setName( "stdlib-console-err" );
            errorAppender.setTarget( "System.err" );
            errorAppender.setEncoder( ple );
            
            Filter<ILoggingEvent> stdErrFilter = new ErrOutFilter();
            errorAppender.addFilter( stdErrFilter );
            stdErrFilter.start();
            errorAppender.start();

            // Wrap the console appenders in an async appenders
            AsyncAppender asyncStdOutWrapper = new AsyncAppender();
            asyncStdOutWrapper.setContext( lc );
            asyncStdOutWrapper.setDiscardingThreshold( 0 );
            asyncStdOutWrapper.setQueueSize( 500 );
            asyncStdOutWrapper.addAppender( stdOutAppender );
            asyncStdOutWrapper.setName( "stdlib-async-out" );
            asyncStdOutWrapper.start();
            
            // Wrap the console appenders in an async appenders
            AsyncAppender asyncStdErrWrapper = new AsyncAppender();
            asyncStdErrWrapper.setContext( lc );
            asyncStdErrWrapper.setDiscardingThreshold( 0 );
            asyncStdErrWrapper.setQueueSize( 500 );
            asyncStdErrWrapper.addAppender( errorAppender ); 
            asyncStdErrWrapper.setName( "stdlib-async-err-2" );
            asyncStdErrWrapper.start();

            // Add the appenders to root logger
            rootLogger.addAppender( asyncStdOutWrapper );
            rootLogger.addAppender( asyncStdErrWrapper );

        } catch ( Exception e ) {
            System.err.println( "Failed to add appender!!" );
            e.printStackTrace();
        }

        // wrap stdout & stderr in log4j appenders 
        StdOutErrLog.tieSystemOutAndErrToLog();

    }
 
開發者ID:krux,項目名稱:java-stdlib,代碼行數:71,代碼來源:LoggerConfigurator.java


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