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


Java ConsoleAppender類代碼示例

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


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

示例1: configure

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@Override
public void configure(final LoggerContext lc) {

    final ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
    ca.setContext(lc);
    ca.setName("console");
    final LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
    encoder.setContext(lc);
    final TTLLLayout layout = new TTLLLayout();
    layout.setContext(lc);
    layout.start();
    encoder.setLayout(layout);
    ca.setEncoder(encoder);
    ca.start();
    final Logger rootLogger = lc.getLogger("ROOT");
    rootLogger.setLevel(Level.WARN);
    rootLogger.addAppender(ca);
}
 
開發者ID:trajano,項目名稱:app-ms,代碼行數:19,代碼來源:LogConfigurator.java

示例2: init

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@Before
public void init()
{
    LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();

    ctx.reset();

    this.layoutProducer = new LayoutProducer();
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
    appender.setLayout(layoutProducer);
    appender.setContext(ctx);
    appender.start();

    Logger basicLogger = ctx.getLogger(LogFmtTest.class);
    basicLogger.addAppender(appender);
    this.logger = LogFmt.from(basicLogger);

    ctx.start();
}
 
開發者ID:BatchLabs,項目名稱:escalog,代碼行數:20,代碼來源:LogFmtTest.java

示例3: createJsonConsoleAppender

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
/**
 * Set up a {@link ConsoleAppender} using a {@link LoggingEventCompositeJsonEncoder} to log to
 * stdout. Package-private for testing.
 * @param loggerContext to use for setup
 * @param appenderName name of the appender
 * @param serviceLog return appender for service logs if true, else return one for request logs
 * @return console appender
 */
static ConsoleAppender<ILoggingEvent> createJsonConsoleAppender(
        final String appenderName,
        final LoggerContext loggerContext,
        final boolean serviceLog) {

    final LoggingEventCompositeJsonEncoder jsonEncoder = getEncoder(loggerContext, serviceLog);

    final ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
    consoleAppender.setContext(loggerContext);
    consoleAppender.setName(appenderName);
    consoleAppender.setEncoder(jsonEncoder);
    consoleAppender.start();

    return consoleAppender;
}
 
開發者ID:secondbase,項目名稱:secondbase,代碼行數:24,代碼來源:SecondBaseLogger.java

示例4: configure

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@Override
public void configure(LoggerContext lc) {
  addInfo("Setting up robot logging configuration.");

  ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
  ca.setContext(lc);
  ca.setName("console");
  LayoutWrappingEncoder<ILoggingEvent> encoder = new LayoutWrappingEncoder<>();
  encoder.setContext(lc);

  PatternLayout layout = new PatternLayout();
  layout.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");

  layout.setContext(lc);
  layout.start();
  encoder.setLayout(layout);

  ca.setEncoder(encoder);
  ca.start();

  Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
  rootLogger.addAppender(ca);
  rootLogger.setLevel(Level.DEBUG);
}
 
開發者ID:strykeforce,項目名稱:thirdcoast,代碼行數:25,代碼來源:LoggingConfigurator.java

示例5: log

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@Test
public void log() throws Exception {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext context = logger.getLoggerContext();
    context.reset();

    Map<String, String> ruleRegistry = (Map) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
    if (ruleRegistry == null) {
        ruleRegistry = new HashMap<String, String>();
        context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, ruleRegistry);
    }
    ruleRegistry.put("ex1L", OnelineThrowableProxyConverter.class.getCanonicalName());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%d{yyyy/MM/dd HH:mm:ss:SSS}\\t%-5level\\t%msg\\t%ex1L");
    encoder.start();

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setEncoder(encoder);
    appender.start();
    logger.addAppender(appender);

    logger.error("error", new RuntimeException("foo"));
}
 
開發者ID:roundrop,項目名稱:logback-oneline-converter,代碼行數:27,代碼來源:OnelineThrowableProxyConverterTest.java

示例6: log

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@Test
public void log() throws Exception {
    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext context = logger.getLoggerContext();
    context.reset();

    Map<String, String> ruleRegistry = (Map) context.getObject(CoreConstants.PATTERN_RULE_REGISTRY);
    if (ruleRegistry == null) {
        ruleRegistry = new HashMap<String, String>();
        context.putObject(CoreConstants.PATTERN_RULE_REGISTRY, ruleRegistry);
    }
    ruleRegistry.put("xEx1L", OnelineExtendedThrowableProxyConverter.class.getCanonicalName());

    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(context);
    encoder.setPattern("%d{yyyy/MM/dd HH:mm:ss:SSS}\\t%-5level\\t%msg\\t%xEx1L");
    encoder.start();

    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(context);
    appender.setEncoder(encoder);
    appender.start();
    logger.addAppender(appender);

    logger.error("error", new RuntimeException());
}
 
開發者ID:roundrop,項目名稱:logback-oneline-converter,代碼行數:27,代碼來源:OnelineExtendedThrowableProxyConverterTest.java

示例7: configure

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
public static void configure(KonkerLoggerContext lc) {
    StatusManager sm = lc.getStatusManager();
    if(sm != null) {
        sm.add(new InfoStatus("Setting up default configuration.", lc));
    }

    ConsoleAppender ca = new ConsoleAppender();
    ca.setContext(lc);
    ca.setName("console");
    PatternLayoutEncoder pl = new PatternLayoutEncoder();
    pl.setContext(lc);
    pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
    pl.start();
    ca.setEncoder(pl);
    ca.start();
    KonkerLogger rootLogger = lc.getLogger("ROOT");
    rootLogger.addAppender(ca);
}
 
開發者ID:KonkerLabs,項目名稱:konker-platform,代碼行數:19,代碼來源:KonkerLoggerBasicConfigurator.java

示例8: build

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
public Appender<ILoggingEvent> build(
    LoggerContext context,
    String applicationName,
    LayoutFactory<ILoggingEvent> layoutFactory,
    LevelFilterFactory<ILoggingEvent> levelFilterFactory,
    AsyncAppenderFactory<ILoggingEvent> asyncAppenderFactory
  ) {

  final LoggingEventCompositeJsonEncoder encoder = new LoggingEventCompositeJsonEncoder();
  encoder.setContext(context);

  encoder.getProviders().addProvider(withPattern("{ \"type\": \"system\" }", new LoggingEventPatternJsonProvider(), context));
  encoder.getProviders().addProvider(withName("timestamp", new LoggingEventFormattedTimestampJsonProvider(), context));
  encoder.getProviders().addProvider(new LogLevelJsonProvider() );
  encoder.getProviders().addProvider(new MessageJsonProvider() );
  encoder.getProviders().addProvider(new StackTraceJsonProvider() );

  encoder.start();

  final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
  appender.setContext(context);
  appender.setEncoder(encoder);
  appender.start();

  return wrapAsync(appender, asyncAppenderFactory);
}
 
開發者ID:atgse,項目名稱:sam,代碼行數:27,代碼來源:JsonLogAppender.java

示例9: startLogback

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
public static void startLogback() {
    long startTime = System.nanoTime();
    Config config = Configs.DEFAULT.logging();
    LogbackConfig logbackConfig = getLogbackConfig(config);
    LogbackManager logbackMgr = LogbackManager.INSTANCE;
    RollingFileAppender<ILoggingEvent> fileAppender = logbackMgr.createRollingFileAppender(logbackConfig);
    ConsoleAppender<ILoggingEvent> consoleAppender = logbackMgr
            .createConsoleAppender(APPENDER_CONSOLE, config.getString(KEY_LOG_PATTERN_CONSOLE));
    List<Appender<ILoggingEvent>> appenderList = new ArrayList<>();
    appenderList.add(consoleAppender);
    appenderList.add(fileAppender);
    logbackMgr.getAppenders().addAll(appenderList);
    LoggerContext context = logbackMgr.getLoggerContext();
    initRootLogger(context, consoleAppender, config);
    addLoggers(config, appenderList);
    addAsyncAppender(config, fileAppender);
    context.start();
    context.getLogger(LogbackInitializer.class).info(INIT_MSG, elapsedMillis(startTime));
}
 
開發者ID:AdeptJ,項目名稱:adeptj-runtime,代碼行數:20,代碼來源:LogbackInitializer.java

示例10: setupConsole

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
private void setupConsole(LogFixtureBuilder builder) {
  drillLogger = (Logger)LoggerFactory.getLogger(DRILL_PACKAGE_NAME);
  if (drillLogger.getAppender("STDOUT") != null) {
    return;
  }
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  ple = new PatternLayoutEncoder();
  ple.setPattern(builder.consoleFormat);
  ple.setContext(lc);
  ple.start();

  appender = new ConsoleAppender<>( );
  appender.setContext(lc);
  appender.setName("Console");
  appender.setEncoder( ple );
  appender.start();

  Logger root = (Logger)LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(appender);
  drillLogger.addAppender(appender);
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:22,代碼來源:LogFixture.java

示例11: 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

示例12: configure

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
public static void configure(LoggerContext lc) {
  StatusManager sm = lc.getStatusManager();
  if(sm != null)  {
   sm.add(new InfoStatus("Setting up default configuration.", lc));
  }
  ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
  ca.setContext(lc);
  ca.setName("console");
  PatternLayoutEncoder pl = new PatternLayoutEncoder();
  pl.setContext(lc);
  pl.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
  pl.start();

  ca.setEncoder(pl);
  ca.start();
  Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
  rootLogger.addAppender(ca);
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:19,代碼來源:BasicConfigurator.java

示例13: encoderCharset

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@Test
public void encoderCharset() throws JoranException, IOException,
        InterruptedException {

  String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
          + "encoderCharset.xml";
  configure(configFileAsStr);

  ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) root.getAppender("CONSOLE");
  assertNotNull(consoleAppender);
  LayoutWrappingEncoder<ILoggingEvent> encoder = (LayoutWrappingEncoder<ILoggingEvent>) consoleAppender.getEncoder();

  assertEquals("UTF-8", encoder.getCharset().displayName());

  StatusChecker checker = new StatusChecker(loggerContext);
  checker.assertIsErrorFree();
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:18,代碼來源:JoranConfiguratorTest.java

示例14: conditionalConsoleApp_IF_THEN_True

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
@Test
public void conditionalConsoleApp_IF_THEN_True() throws JoranException,
        IOException, InterruptedException {
  InetAddress localhost = InetAddress.getLocalHost();
  System.out.println("In conditionalConsoleApp_IF_THEN_True, canonicalHostName=\"" + localhost.getCanonicalHostName() + "] and hostNmae=\"" + localhost.getHostName() + "\"");
  context.putProperty("aHost", localhost.getHostName());

  String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
          + "conditional/conditionalConsoleApp.xml";
  configure(configFileAsStr);
  FileAppender fileAppender = (FileAppender) root.getAppender("FILE");
  assertNotNull(fileAppender);

  ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
  assertNotNull(consoleAppender);
  StatusChecker checker = new StatusChecker(context);
  checker.assertIsErrorFree();
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:20,代碼來源:ConditionalTest.java

示例15: conditionalConsoleApp_IF_THEN_False

import ch.qos.logback.core.ConsoleAppender; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
@Test
public void conditionalConsoleApp_IF_THEN_False() throws JoranException,
        IOException, InterruptedException {

  String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX
          + "conditional/conditionalConsoleApp.xml";
  configure(configFileAsStr);
  FileAppender fileAppender = (FileAppender) root.getAppender("FILE");
  assertNotNull(fileAppender);

  ConsoleAppender consoleAppender = (ConsoleAppender) root.getAppender("CON");
  assertNull(consoleAppender);
  StatusChecker checker = new StatusChecker(context);
  checker.assertIsErrorFree();
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:17,代碼來源:ConditionalTest.java


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