本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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");
}
示例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")));
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
}