本文整理汇总了Java中ch.qos.logback.core.FileAppender.setName方法的典型用法代码示例。如果您正苦于以下问题:Java FileAppender.setName方法的具体用法?Java FileAppender.setName怎么用?Java FileAppender.setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.core.FileAppender
的用法示例。
在下文中一共展示了FileAppender.setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAppender
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
/**
* Start a specific file logging, typically for the processing of a given book.
*
* @param name appender name (typically the book radix)
* @param logFolder target folder where the log file is to be written
*/
public static void addAppender (String name,
Path logFolder)
{
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
Logger.ROOT_LOGGER_NAME);
FileAppender fileAppender = new FileAppender();
PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
fileAppender.setName(name);
fileAppender.setContext(loggerContext);
fileAppender.setAppend(false);
String now = new SimpleDateFormat("yyyyMMdd'T'HHmm").format(new Date());
Path logFile = logFolder.resolve(name + "-" + now + ".log");
fileAppender.setFile(logFile.toAbsolutePath().toString());
fileEncoder.setContext(loggerContext);
fileEncoder.setPattern("%date %level [%X{BOOK}%X{SHEET}] %25file:%-4line | %msg%n%ex");
fileEncoder.start();
fileAppender.setEncoder(fileEncoder);
fileAppender.start();
root.addAppender(fileAppender);
}
示例2: addFileAppender
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
/**
* Add a specific appender meant for FILE.
*/
public static void addFileAppender ()
{
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(
Logger.ROOT_LOGGER_NAME);
FileAppender fileAppender = new FileAppender();
PatternLayoutEncoder fileEncoder = new PatternLayoutEncoder();
fileAppender.setName("FILE");
fileAppender.setContext(loggerContext);
fileAppender.setAppend(false);
String now = new SimpleDateFormat("yyyyMMdd'T'HHmmss").format(new Date());
Path logPath = WellKnowns.LOG_FOLDER.resolve(now + ".log").toAbsolutePath();
fileAppender.setFile(logPath.toString());
fileEncoder.setContext(loggerContext);
fileEncoder.setPattern("%date %-5level [%X{BOOK}%X{SHEET}] %25replace(%file){'\\.java$',''} %-4line | %msg%n%ex");
fileEncoder.start();
fileAppender.setEncoder(fileEncoder);
fileAppender.start();
root.addAppender(fileAppender);
System.out.println("LogUtil. Logging to " + logPath);
}
示例3: createLogger
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
private Logger createLogger(File logFile) {
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
ch.qos.logback.classic.Logger log = loggers.get();
log.setAdditive(false);
FileAppender fileAppender = new FileAppender();
fileAppender.setContext(context);
fileAppender.setName(Thread.currentThread().getName());
fileAppender.setFile(logFile.getAbsolutePath());
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern(LOG_PATTERN);
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.start();
log.detachAndStopAllAppenders();
log.addAppender(fileAppender);
return log;
}
示例4: smoke
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Test
public void smoke() {
String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + "/fat-smoke.log";
FileAppender<Object> appender = new FileAppender<Object>();
appender.setEncoder(new DummyEncoder<Object>());
appender.setAppend(false);
appender.setFile(filename);
appender.setName("smoke");
appender.setContext(context);
appender.start();
appender.doAppend(new Object());
appender.stop();
File file = new File(filename);
assertTrue(file.exists());
assertTrue("failed to delete " + file.getAbsolutePath(), file.delete());
}
示例5: testCreateParentFolders
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Test
public void testCreateParentFolders() {
String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + "/fat-testCreateParentFolders-" + diff
+ "/testCreateParentFolders.txt";
File file = new File(filename);
assertFalse(file.getParentFile().exists());
assertFalse(file.exists());
FileAppender<Object> appender = new FileAppender<Object>();
appender.setEncoder(new DummyEncoder<Object>());
appender.setAppend(false);
appender.setFile(filename);
appender.setName("testCreateParentFolders");
appender.setContext(context);
appender.start();
appender.doAppend(new Object());
appender.stop();
assertTrue(file.getParentFile().exists());
assertTrue(file.exists());
// cleanup
assertTrue("failed to delete " + file.getAbsolutePath(), file.delete());
File parent = file.getParentFile();
assertTrue("failed to delete " + parent.getAbsolutePath(), parent.delete());
}
示例6: IOPerformance
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public IOPerformance(boolean _immediateFlush, long _len) {
this.len = _len;
this.immediateFlush = _immediateFlush;
context = new LoggerContext();
logger = context.getLogger("logger-" + getName());
// A FileAppender is created according to the buffering and
// immediate flush setting of this IO instance.
FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
fa.setName("FILE");
PatternLayoutEncoder pa = new PatternLayoutEncoder();
pa.setPattern("%r %5p %c [%t] - %m%n");
pa.setContext(context);
pa.start();
fa.setEncoder(pa);
fa.setFile(LOG_FILE);
fa.setAppend(true);
fa.setContext(context);
fa.start();
((ch.qos.logback.classic.Logger) logger).addAppender(fa);
StatusPrinter.print(context);
}
示例7: initializeLogFile
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
private static void initializeLogFile() {
final LoggerContext loggerContext = ROOT_LOGGER.getLoggerContext();
final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n");
encoder.setContext(loggerContext);
encoder.start();
final FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
fileAppender.setFile("migration.log");
fileAppender.setName("file");
fileAppender.setEncoder(encoder);
fileAppender.setContext(loggerContext);
fileAppender.start();
ROOT_LOGGER.addAppender(fileAppender);
}
示例8: logToFile
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
/**
* Configure file logging and stop console logging.
*
* @param filename
* Log to this file.
*/
@SuppressWarnings("unchecked")
static void logToFile(String filename) {
Logger rootLogger = (Logger) LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
FileAppender<ILoggingEvent> fileappender = new FileAppender<>();
fileappender.setContext(rootLogger.getLoggerContext());
fileappender.setFile(filename);
fileappender.setName("FILE");
ConsoleAppender<?> console = (ConsoleAppender<?>) rootLogger.getAppender("STDOUT");
fileappender.setEncoder((Encoder<ILoggingEvent>) console.getEncoder());
fileappender.start();
rootLogger.addAppender(fileappender);
console.stop();
}
示例9: createAppender
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
private Appender<ILoggingEvent> createAppender(String loggerName, String prefix) {
Appender<ILoggingEvent> appender;
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
fileAppender.setName(loggerName);
File file = new File(logDir, prefix + "-" + loggerName + ".log");
fileAppender.setFile(file.getPath());
fileAppender.setContext(loggerFactory);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerFactory);
encoder.setPattern("%-5level %d{HH:mm:ss.SSS} [%t] %logger{36} - %msg%n%rEx");
fileAppender.setEncoder(encoder);
appender = fileAppender;
encoder.start();
appender.start();
return appender;
}
示例10: addFileAppender
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public static void addFileAppender(String filePath, boolean append) {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
fileAppender.setContext(loggerContext);
fileAppender.setName("css-analyzer");
// set the file name
fileAppender.setFile(filePath);
fileAppender.setAppend(append);
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(loggerContext);
//encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level - %msg [%C{1}]%n");
encoder.setPattern("%d{HH:mm:ss.SSS} [%thread] %-5level - %msg%n");
encoder.start();
fileAppender.setEncoder(encoder);
fileAppender.start();
appenders.add(fileAppender);
logBackLogger.addAppender(fileAppender);
}
示例11: configure
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Override
public void configure(LoggerContext lc) {
addInfo("Setting up robot logging configuration.");
FileAppender<ILoggingEvent> fa = new FileAppender<>();
fa.setFile("tct.log");
fa.setAppend(true);
ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<>();
ca.setContext(lc);
ca.setName("console");
fa.setContext(lc);
fa.setName("logfile");
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();
fa.setEncoder(encoder);
fa.start();
Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);
// rootLogger.addAppender(ca);
rootLogger.addAppender(fa);
rootLogger.setLevel(Level.WARN);
}
示例12: getConfiguredAppender
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
protected Appender<Object> getConfiguredAppender() {
FileAppender<Object> appender = new FileAppender<Object>();
appender.setEncoder(new NopEncoder<Object>());
appender.setFile(CoreTestConstants.OUTPUT_DIR_PREFIX+"temp.log");
appender.setName("test");
appender.setContext(context);
appender.start();
return appender;
}
示例13: testPrudentModeLogicalImplications
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
@Test
public void testPrudentModeLogicalImplications() {
String filename = CoreTestConstants.OUTPUT_DIR_PREFIX + diff + "fat-testPrudentModeLogicalImplications.txt";
File file = new File(filename);
FileAppender<Object> appender = new FileAppender<Object>();
appender.setEncoder(new DummyEncoder<Object>());
appender.setFile(filename);
appender.setName("testPrudentModeLogicalImplications");
appender.setContext(context);
appender.setAppend(false);
appender.setPrudent(true);
appender.start();
assertTrue(appender.isAppend());
StatusManager sm = context.getStatusManager();
//StatusPrinter.print(context);
StatusChecker statusChecker = new StatusChecker(context);
assertEquals(Status.WARN, statusChecker.getHighestLevel(0));
List<Status> statusList = sm.getCopyOfStatusList();
assertTrue("Expecting status list size to be 2 or larger, but was "
+ statusList.size(), statusList.size() >= 2);
String msg1 = statusList.get(1).getMessage();
assertTrue("Got message [" + msg1 + "]", msg1
.startsWith("Setting \"Append\" property"));
appender.doAppend(new Object());
appender.stop();
assertTrue(file.exists());
assertTrue("failed to delete " + file.getAbsolutePath(), file.delete());
}
示例14: createFileAppender
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
public static OutputStreamAppender<ILoggingEvent> createFileAppender(Path path) {
FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();
fa.setFile(path.toString());
fa.setAppend(true);
fa.setName("FileLogger");
return fa;
}
示例15: init
import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
/**
* Programatically configures Logback initially.
*/
private static void init() {
LoggerContext context = LOG.getLoggerContext();
context.reset();
PatternLayoutEncoder encoder = new PatternLayoutEncoder();
encoder.setContext(context);
encoder.setPattern("[%d{HH:mm:ss} %level] %msg%n");
encoder.start();
ConsoleAppender<ILoggingEvent> cAppender = new ConsoleAppender<ILoggingEvent>();
cAppender.setName("STDOUT");
cAppender.setContext(context);
cAppender.setLayout(encoder.getLayout());
cAppender.start();
FileAppender<ILoggingEvent> fAppender = new FileAppender<ILoggingEvent>();
fAppender.setName("FILE");
fAppender.setFile("log.log");
fAppender.setEncoder(encoder);
fAppender.setContext(context);
fAppender.start();
LOG.addAppender(cAppender);
LOG.addAppender(fAppender);
LOG.setLevel(Boolean.parseBoolean(CONFIG.get("debug", "false")) ? Level.DEBUG : Level.INFO);
}