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


Java Logger.addAppender方法代碼示例

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


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

示例1: setUp

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    final Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    logger.addAppender(mockAppender);
    logger.setLevel(Level.INFO);

    signature = Optional.of(SignatureBuilder.aSignature().build());
    SignatureImpl signatureImpl = ((SignatureImpl) signature.get());
    signatureImpl.setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_RSASHA256, DIGEST_SHA256));

    signatureWithUnknownSignatureAlgorithm = Optional.of(SignatureBuilder.aSignature().withSignatureAlgorithm(SIGNATURE_RSASHA1).build());
    SignatureImpl signatureWithUnknownSignatureAlgorithmImpl = ((SignatureImpl) signatureWithUnknownSignatureAlgorithm.get());
    signatureWithUnknownSignatureAlgorithmImpl.setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_RSASHA1, DIGEST_SHA256));

    signatureWithUnknownDigestAlgorithm = Optional.of(SignatureBuilder.aSignature().withDigestAlgorithm(ID, DIGEST_SHA1).build());
    SignatureImpl signatureWithUnknownDigestAlgorithmImpl = ((SignatureImpl) signatureWithUnknownDigestAlgorithm.get());
    signatureWithUnknownDigestAlgorithmImpl.setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_RSASHA256, DIGEST_SHA1));

    signatureWithUnknownSignatureAndDigestAlgorithms = Optional.of(SignatureBuilder.aSignature().withSignatureAlgorithm(SIGNATURE_RSASHA1).withDigestAlgorithm(ID, DIGEST_SHA1).build());
    SignatureImpl signatureWithUnknownSignatureAndDigestAlgorithmsImpl = ((SignatureImpl) signatureWithUnknownSignatureAndDigestAlgorithms.get());
    signatureWithUnknownSignatureAndDigestAlgorithmsImpl.setXMLSignature(BuilderHelper.createXMLSignature(SIGNATURE_RSASHA1, DIGEST_SHA1));
}
 
開發者ID:alphagov,項目名稱:verify-hub,代碼行數:23,代碼來源:UnknownMethodAlgorithmLoggerTest.java

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

示例3: configure

import ch.qos.logback.classic.Logger; //導入方法依賴的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

示例4: configure

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@Override
public void configure(LoggerContext loggerContext) {
    addInfo("Setting up default configuration.");

    NonMetricsConsoleAppender nonMetricsConsoleAppender = new NonMetricsConsoleAppender();
    nonMetricsConsoleAppender.setContext(loggerContext);
    nonMetricsConsoleAppender.setName("CONSOLE");
    nonMetricsConsoleAppender.start();

    MetricsConsoleAppender metricsConsoleAppender = new MetricsConsoleAppender();
    metricsConsoleAppender.setContext(loggerContext);
    metricsConsoleAppender.setName("METRICS");
    metricsConsoleAppender.start();

    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(nonMetricsConsoleAppender);
    rootLogger.addAppender(metricsConsoleAppender);
}
 
開發者ID:symphoniacloud,項目名稱:lambda-monitoring,代碼行數:20,代碼來源:DefaultMetricsLogbackConfigurator.java

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

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

示例7: setUp

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
    logger.info("Initializing test Logger");
    testLogger = (Logger) LoggerFactory.getLogger("TEST_LOGGER");
    log = new LogImpl(new File(tmpdir, "log"));
    //Initialize Logger
    logger.info("Adding transformation appender");
    MemoryAppender appender = new MemoryAppender(log);
    appender.start();
    appender.setContext(testLogger.getLoggerContext());
    testLogger.addAppender(appender);
    logger.info("Initialization done");
}
 
開發者ID:StuPro-TOSCAna,項目名稱:TOSCAna,代碼行數:14,代碼來源:MemoryAppenderTest.java

示例8: testWriteXxxxxResult

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@Test
public void testWriteXxxxxResult() throws TechnicalException {
    final OutputConsoleDataProvider outputConsoleDataProvider = new OutputConsoleDataProvider();
    outputConsoleDataProvider.prepare("hello");
    Assert.assertTrue(true);

    Logger logger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    final TestAppender<ILoggingEvent> appender = new TestAppender<>();
    appender.start();
    logger.addAppender(appender);
    outputConsoleDataProvider.writeFailedResult(1, "UT Failed Message");
    List<ILoggingEvent> log = appender.getLog();
    Assert.assertEquals(Level.ERROR, log.get(0).getLevel());
    Assert.assertTrue(log.get(0).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_FAILED_AT_LINE"), 1, "UT Failed Message")));

    outputConsoleDataProvider.writeSuccessResult(2);
    log = appender.getLog();
    Assert.assertEquals(Level.INFO, log.get(1).getLevel());
    Assert.assertTrue(log.get(1).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_SUCCESS_AT_LINE"), 2)));

    outputConsoleDataProvider.writeWarningResult(3, "UT Warning Message");
    log = appender.getLog();
    Assert.assertEquals(Level.WARN, log.get(2).getLevel());
    Assert.assertTrue(log.get(2).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_WARNING_AT_LINE"), 3, "UT Warning Message")));

    outputConsoleDataProvider.writeDataResult("title", 4, "UT title");
    log = appender.getLog();
    Assert.assertEquals(Level.INFO, log.get(3).getLevel());
    Assert.assertTrue(log.get(3).getMessage().toString().endsWith(String.format(Messages.getMessage("OUTPUT_CONSOLE_DATA_PROVIDER_RESULT_AT_LINE"), 4, "title", "UT title")));
}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:32,代碼來源:OutputConsoleDataProviderUT.java

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

示例10: captureLogEventsAsync

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
public static <T> LogCapture<T> captureLogEventsAsync(Supplier<T> codeBlock, Duration duration, ExpectedLoggingMessage expectedLoggingMessage) {
  StubAppender logAppender = new StubAppender();
  Logger root = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);

  root.addAppender(logAppender);
  try {
    T result = codeBlock.get();
    awaitForLogMessage(duration, hasLoggedMessage(logAppender.events(), expectedLoggingMessage));
    return new LogCapture<>(logAppender.events(), result);
  } finally {
    root.detachAppender(logAppender);
  }
}
 
開發者ID:mustaine,項目名稱:logcapture,代碼行數:14,代碼來源:LogbackInterceptor.java

示例11: TestLogAppender

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
public TestLogAppender() {
    sb = new StringBuilder();
    logger = (Logger) LoggerFactory.getLogger("com.intuit.karate");
    setName("karate-test");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    setContext(lc);
    encoder = new PatternLayoutEncoder();
    encoder.setPattern("%msg");
    encoder.setContext(context);
    encoder.start();
    start();
    logger.addAppender(this);
    logger.setLevel(Level.DEBUG);
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:15,代碼來源:TestLogAppender.java

示例12: TextAreaLogAppender

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
public TextAreaLogAppender(TextArea textArea) {
    this.textArea = textArea;
    logger = (Logger) LoggerFactory.getLogger("com.intuit.karate");
    setName("karate-ui");
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    setContext(lc);
    encoder = new PatternLayoutEncoder();
    encoder.setPattern("%d{HH:mm:ss.SSS} %-5level - %msg%n");
    encoder.setContext(context);
    encoder.start();
    start();
    logger.addAppender(this);
    logger.setLevel(Level.DEBUG);
}
 
開發者ID:intuit,項目名稱:karate,代碼行數:15,代碼來源:TextAreaLogAppender.java

示例13: configure

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
@Override
public void configure(LoggerContext loggerContext) {
    addInfo("Setting up default configuration.");

    DefaultConsoleAppender consoleAppender = new DefaultConsoleAppender();
    consoleAppender.setContext(loggerContext);
    consoleAppender.setName("CONSOLE");
    consoleAppender.start();

    Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);
    rootLogger.addAppender(consoleAppender);
}
 
開發者ID:symphoniacloud,項目名稱:lambda-monitoring,代碼行數:14,代碼來源:DefaultLogbackConfigurator.java

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

示例15: decodeLogPacketIfTraceLogging

import ch.qos.logback.classic.Logger; //導入方法依賴的package包/類
/**
 * If logging is set to `DEBUG` then a hexdump of the entire captured packet
 * should be logged
 */
@Test
@Tag("fast")
public void decodeLogPacketIfTraceLogging() {
    // Setup the mock logger.
    Logger root = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    Appender mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    // Save the current default logging level
    Level defaultLevel = root.getLevel();
    try {
        // Change the logging to TRACE.
        root.setLevel(Level.TRACE);

        // Do some deserialization
        EmbeddedChannel channel = new EmbeddedChannel(new IsoOnTcpProtocol());
        channel.writeInbound(Unpooled.wrappedBuffer(new byte[]{IsoOnTcpProtocol.ISO_ON_TCP_MAGIC_NUMBER,
            (byte) 0x00, (byte) 0x00, (byte) 0x0D,
            (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04, (byte) 0x05, (byte) 0x06, (byte) 0x07, (byte) 0x08, (byte) 0x09}));
        channel.checkException();
        Object obj = channel.readInbound();
        assertNotNull(obj, "Something should have been decoded");

        // Check that the packet dump was logged.
        verify(mockAppender).doAppend(argThat(argument ->
            ((LoggingEvent) argument).getFormattedMessage().contains("Got Data: 0300000d010203040506070809")));
    } finally {
        // Reset the log level to the default.
        root.setLevel(defaultLevel);
    }
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:36,代碼來源:IsoOnTcpProtocolTest.java


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