本文整理匯總了Java中ch.qos.logback.core.ConsoleAppender.setContext方法的典型用法代碼示例。如果您正苦於以下問題:Java ConsoleAppender.setContext方法的具體用法?Java ConsoleAppender.setContext怎麽用?Java ConsoleAppender.setContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ch.qos.logback.core.ConsoleAppender
的用法示例。
在下文中一共展示了ConsoleAppender.setContext方法的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);
}
示例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();
}
示例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;
}
示例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);
}
示例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"));
}
示例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);
}
示例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);
}
示例9: 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\\]");
}
示例10: 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);
}
示例11: main
import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
static public void main(String[] args) throws Exception {
Logger rootLogger = (Logger) LoggerFactory.getLogger("root");
LoggerContext loggerContext = rootLogger.getLoggerContext();
loggerContext.reset();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
encoder.setPattern("%-5level [%thread]: %message%n");
encoder.start();
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
appender.setContext(loggerContext);
appender.setEncoder(encoder);
appender.start();
rootLogger.addAppender(appender);
rootLogger.debug("Message 1");
rootLogger.warn("Message 2");
}
示例12: programmaticConfiguration
import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
static void programmaticConfiguration() {
// Configure logback
LoggerContext loggerContext = (LoggerContext) LoggerFactory
.getILoggerFactory();
loggerContext.reset();
PatternLayoutEncoder layout = new PatternLayoutEncoder();
layout.setContext(loggerContext);
layout.setPattern("%X{first} %X{last} - %m%n");
layout.start();
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
appender.setContext(loggerContext);
appender.setEncoder(layout);
appender.start();
// cast root logger to c.q.logback.classic.Logger so that we can attach
// an appender to it
ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory
.getLogger("root");
root.addAppender(appender);
}
示例13: configureRequestLogImpl
import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
@Override
protected void configureRequestLogImpl() {
NotifyingListAppender appender = new NotifyingListAppender();
appender.setContext(requestLogImpl);
appender.setName("list");
appender.start();
ConsoleAppender<IAccessEvent> console = new ConsoleAppender<IAccessEvent>();
console.setContext(requestLogImpl);
console.setName("console");
PatternLayoutEncoder layout = new PatternLayoutEncoder();
layout.setContext(requestLogImpl);
layout.setPattern("%date %server %clientHost");
console.setEncoder(layout);
layout.start();
console.start();
requestLogImpl.addAppender(appender);
requestLogImpl.addAppender(console);
}
示例14: configure
import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public void configure(LoggerContext loggerContext) {
StatusManager sm = loggerContext.getStatusManager();
if (sm != null) {
sm.add(new InfoStatus("Setting up GreenPepper PHP Runner configuration.", loggerContext));
}
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
ca.setContext(loggerContext);
ca.setName("console");
PatternLayoutEncoder pl = new PatternLayoutEncoder();
pl.setContext(loggerContext);
pl.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %-36logger{36} - %msg%n");
pl.start();
ca.setEncoder(pl);
ca.start();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(ca);
rootLogger.setLevel(Level.INFO);
}
示例15: configure
import ch.qos.logback.core.ConsoleAppender; //導入方法依賴的package包/類
/** {@inheritDoc} */
@Override
public void configure(LoggerContext loggerContext) {
StatusManager sm = loggerContext.getStatusManager();
if (sm != null) {
sm.add(new InfoStatus("Setting up default configuration.", loggerContext));
}
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
ca.setContext(loggerContext);
ca.setName("console");
PatternLayoutEncoder pl = new PatternLayoutEncoder();
pl.setContext(loggerContext);
pl.setPattern("[%-5level] %msg%n");
pl.start();
ca.setEncoder(pl);
ca.start();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.addAppender(ca);
rootLogger.setLevel(Level.WARN);
loggerContext.getLogger("com.greenpepper.maven.plugin").setLevel(Level.INFO);
}