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