本文整理汇总了Java中ch.qos.logback.core.ConsoleAppender.setTarget方法的典型用法代码示例。如果您正苦于以下问题:Java ConsoleAppender.setTarget方法的具体用法?Java ConsoleAppender.setTarget怎么用?Java ConsoleAppender.setTarget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.ConsoleAppender
的用法示例。
在下文中一共展示了ConsoleAppender.setTarget方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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\\]");
}
示例2: doFailSafeConfiguration
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
private void doFailSafeConfiguration() {
// Not really fail-safe, just less likely to fail
final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
Logger rootLogger = context.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.INFO);
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
rootLogger.addAppender(appender);
appender.setContext(context);
appender.setTarget("System.err");
PatternLayout layout = new PatternLayout();
appender.setLayout(layout);
layout.setPattern("%msg%n%ex");
layout.setContext(context);
layout.start();
appender.start();
}
示例3: getStdErrAppender
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
/**
* Create a stderr appender.
*
* @param context The logger context to use.
* @return An appender writing to stderr.
*/
private static Appender<ILoggingEvent> getStdErrAppender(final LoggerContext context) {
// Setup format
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(
"%date{HH:mm:ss.SSS} %property{ident}[%property{pid}]: %-5level [%thread] %logger{0}: %msg%n");
encoder.setCharset(Charsets.UTF_8);
encoder.start();
// Setup stderr appender
final ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
appender.setTarget("System.err");
appender.setName("stderr");
appender.setEncoder(encoder);
appender.setContext(context);
appender.start();
return appender;
}
示例4: createLogger
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的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;
}
示例5: createConsoleAppender
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
protected ConsoleAppender<ILoggingEvent> createConsoleAppender(LoggerContext context, String defaultLogFormat) {
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setName("console");
appender.setContext(context);
appender.setTarget(target.getLogbackTarget());
LayoutWrappingEncoder<ILoggingEvent> layoutEncoder = new LayoutWrappingEncoder<>();
layoutEncoder.setLayout(createLayout(context, defaultLogFormat));
appender.setEncoder(layoutEncoder);
appender.start();
return appender;
}
示例6: setupAppender
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
private ConsoleAppender setupAppender(String target, LoggerContext ctx, Encoder enc) {
ConsoleAppender appender = new ConsoleAppender();
appender.setTarget(target);
appender.setContext(ctx);
appender.setEncoder(enc);
appender.start();
return appender;
}
示例7: writeTo
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
void writeTo(Outstream target) {
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setTarget(target.target.getName());
appender.setEncoder(LogHelper.encoder("%date{ISO8601} [" + target.marker + "] - %msg%n"));
appender.start();
appenders.add(appender);
}
示例8: initLogback
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
/**
* Initialize Logback
*/
private static void initLogback() {
// reset logger context
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
context.reset();
// shared console appender
ConsoleAppender.setContext(context);
ConsoleAppender.setTarget("System.out");
PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
consoleEncoder.setContext(context);
consoleEncoder.setPattern(LogPattern);
consoleEncoder.start();
ConsoleAppender.setEncoder(consoleEncoder);
ConsoleAppender.start();
// rolling file
String logFile = getFilePath() + File.separatorChar + getFileName();
FileAppender.setContext(context);
FileAppender.setFile(logFile);
// log pattern
PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
fileEncoder.setContext(context);
fileEncoder.setPattern(LogPattern);
fileEncoder.start();
FileAppender.setEncoder(fileEncoder);
// rolling policy
FixedWindowRollingPolicy rollingPolicy = new FixedWindowRollingPolicy();
rollingPolicy.setContext(context);
rollingPolicy.setParent(FileAppender);
rollingPolicy.setFileNamePattern(logFile + "%i.zip");
rollingPolicy.setMinIndex(1);
rollingPolicy.setMaxIndex(1);
rollingPolicy.start();
// file max size - if fileLimit is 0, set max file size to maximum allowed
long fileLimit = getFileLimitInKBytes() != 0 ? getFileLimitInKBytes() * 1024 : Long.MAX_VALUE;
SizeBasedTriggeringPolicy<ILoggingEvent> triggeringPolicy = new SizeBasedTriggeringPolicy<ILoggingEvent>(String.valueOf(fileLimit));
triggeringPolicy.start();
FileAppender.setRollingPolicy(rollingPolicy);
FileAppender.setTriggeringPolicy(triggeringPolicy);
FileAppender.start();
}
示例9: configureStdOutLogging
import ch.qos.logback.core.ConsoleAppender; //导入方法依赖的package包/类
public static void configureStdOutLogging( String loglevel ) {
if (!(LoggerFactory.getILoggerFactory() instanceof LoggerContext)) {
System.err.println("Logger is not using logback, skipping logging configuration");
return;
}
try {
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
lc.reset();
Logger rootLogger = getRootLogger( loglevel );
PatternLayoutEncoder ple = getPatternLayoutEncoder( lc );
// ops would like us to log to console unless an app
// has a specific need not to
ConsoleAppender<ILoggingEvent> stdOutAppender = new ConsoleAppender<ILoggingEvent>();
stdOutAppender.setContext( lc );
stdOutAppender.setName( "stdlib-console-out" );
stdOutAppender.setTarget( "System.out" );
stdOutAppender.setEncoder( ple );
Filter<ILoggingEvent> stdOutFilter = new StdOutFilter();
stdOutAppender.addFilter( stdOutFilter );
stdOutFilter.start();
stdOutAppender.start();
ple = getPatternLayoutEncoder( lc );
ConsoleAppender<ILoggingEvent> errorAppender = new ConsoleAppender<ILoggingEvent>();
errorAppender.setContext( lc );
errorAppender.setName( "stdlib-console-err" );
errorAppender.setTarget( "System.err" );
errorAppender.setEncoder( ple );
Filter<ILoggingEvent> stdErrFilter = new ErrOutFilter();
errorAppender.addFilter( stdErrFilter );
stdErrFilter.start();
errorAppender.start();
// Wrap the console appenders in an async appenders
AsyncAppender asyncStdOutWrapper = new AsyncAppender();
asyncStdOutWrapper.setContext( lc );
asyncStdOutWrapper.setDiscardingThreshold( 0 );
asyncStdOutWrapper.setQueueSize( 500 );
asyncStdOutWrapper.addAppender( stdOutAppender );
asyncStdOutWrapper.setName( "stdlib-async-out" );
asyncStdOutWrapper.start();
// Wrap the console appenders in an async appenders
AsyncAppender asyncStdErrWrapper = new AsyncAppender();
asyncStdErrWrapper.setContext( lc );
asyncStdErrWrapper.setDiscardingThreshold( 0 );
asyncStdErrWrapper.setQueueSize( 500 );
asyncStdErrWrapper.addAppender( errorAppender );
asyncStdErrWrapper.setName( "stdlib-async-err-2" );
asyncStdErrWrapper.start();
// Add the appenders to root logger
rootLogger.addAppender( asyncStdOutWrapper );
rootLogger.addAppender( asyncStdErrWrapper );
} catch ( Exception e ) {
System.err.println( "Failed to add appender!!" );
e.printStackTrace();
}
// wrap stdout & stderr in log4j appenders
StdOutErrLog.tieSystemOutAndErrToLog();
}