當前位置: 首頁>>代碼示例>>Java>>正文


Java FileAppender.start方法代碼示例

本文整理匯總了Java中ch.qos.logback.core.FileAppender.start方法的典型用法代碼示例。如果您正苦於以下問題:Java FileAppender.start方法的具體用法?Java FileAppender.start怎麽用?Java FileAppender.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ch.qos.logback.core.FileAppender的用法示例。


在下文中一共展示了FileAppender.start方法的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);
}
 
開發者ID:Audiveris,項目名稱:audiveris,代碼行數:29,代碼來源:LogUtil.java

示例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);
}
 
開發者ID:Audiveris,項目名稱:audiveris,代碼行數:27,代碼來源:LogUtil.java

示例3: buildFileAppender

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
public FileAppender<ILoggingEvent> buildFileAppender(LoggerContext context, String file) {
  FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
  fileAppender.setFile(file);
  fileAppender.setContext(context);
  fileAppender.setPrudent(true);

  PatternLayoutEncoder encoder = new PatternLayoutEncoder();
  encoder.setContext(context);
  encoder.setPattern(primaryConfiguration.getLoggingPattern().or(baseConfiguration.getLoggingPattern()).or(JavaUtils.LOGBACK_LOGGING_PATTERN));
  encoder.start();

  fileAppender.setEncoder(encoder);
  fileAppender.start();

  return fileAppender;
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:17,代碼來源:SingularityRunnerBaseLogging.java

示例4: logToFile

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
static void logToFile(Parameters parameters) {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    PatternLayoutEncoder ple = new PatternLayoutEncoder();

    ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
    ple.setContext(lc);
    ple.start();
    FileAppender<ILoggingEvent> fileAppender = new FileAppender<>();
    fileAppender.setFile(parameters.getWorkingDirectory() + "/jlineup.log");
    fileAppender.setEncoder(ple);
    fileAppender.setContext(lc);
    fileAppender.start();

    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    logger.addAppender(fileAppender);
    logger.setLevel(Level.DEBUG);
}
 
開發者ID:otto-de,項目名稱:jlineup,代碼行數:18,代碼來源:Util.java

示例5: 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;
}
 
開發者ID:dmart28,項目名稱:gcplot,代碼行數:24,代碼來源:DefaultLogsProcessorService.java

示例6: createLogger

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
/**
 * Creates a new logger.
 *
 * @param name a name for the logger
 * @param level the logging level for the logger
 * @param file the file to output all logging to
 * @return the created logger
 */
public static Logger createLogger(String name, Level level, String file) {
  LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
  PatternLayoutEncoder ple = new PatternLayoutEncoder();
  ple.setPattern("%date %level [%thread] %logger{10} [%file:%line]%n%msg%n%n");
  ple.setContext(lc);
  ple.start();
  FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
  fileAppender.setFile(file);
  fileAppender.setEncoder(ple);
  fileAppender.setAppend(false);
  fileAppender.setContext(lc);
  fileAppender.start();
  logger = (Logger) LoggerFactory.getLogger(name);
  logger.detachAndStopAllAppenders(); // detach console (doesn't seem to work)
  logger.addAppender(fileAppender); // attach file appender
  logger.setLevel(level);
  logger.setAdditive(true); // set to true if root should log too

  return logger;
}
 
開發者ID:agentsoz,項目名稱:jill,代碼行數:29,代碼來源:Log.java

示例7: 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());
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:19,代碼來源:FileAppenderTest.java

示例8: 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());
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:26,代碼來源:FileAppenderTest.java

示例9: buildLoggerContext

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
static LoggerContext buildLoggerContext(String stamp, String filename,
    boolean safetyMode) {
  LoggerContext loggerContext = new LoggerContext();

  FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();

  PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
  patternLayout.setPattern(stamp + " %5p - %m%n");
  patternLayout.setContext(loggerContext);
  patternLayout.start();

  fa.setEncoder(patternLayout);
  fa.setFile(filename);
  fa.setAppend(true);
  fa.setPrudent(safetyMode);
  fa.setContext(loggerContext);
  fa.start();

  ch.qos.logback.classic.Logger root = loggerContext
      .getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(fa);

  return loggerContext;
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:25,代碼來源:SafeModeFileAppender.java

示例10: buildLoggerContext

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
static LoggerContext buildLoggerContext(String filename, boolean safetyMode) {
  LoggerContext loggerContext = new LoggerContext();

  FileAppender<ILoggingEvent> fa = new FileAppender<ILoggingEvent>();

  PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
  patternLayout.setPattern("%5p %c - %m%n");
  patternLayout.setContext(loggerContext);
  patternLayout.start();

  fa.setEncoder(patternLayout);
  fa.setFile(filename);
  fa.setAppend(false);
  fa.setPrudent(safetyMode);
  fa.setContext(loggerContext);
  fa.start();

  ch.qos.logback.classic.Logger root = loggerContext
      .getLogger(Logger.ROOT_LOGGER_NAME);
  root.addAppender(fa);

  return loggerContext;
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:24,代碼來源:FileAppenderPerf.java

示例11: buildLoggerContext

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
static Logger buildLoggerContext(LoggerContext lc) {
  Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME);

  PatternLayoutEncoder patternLayout = new PatternLayoutEncoder();
  patternLayout.setContext(lc);
  patternLayout.setPattern("%d %l [%t] - %msg%n");
  patternLayout.start();
  FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
  fileAppender.setContext(lc);
  fileAppender.setFile("target/lbclassic135.log");
  fileAppender.setEncoder(patternLayout);
  fileAppender.setAppend(false);
  fileAppender.start();
  root.addAppender(fileAppender);
  return lc.getLogger(LoggingToFileThroughput.class);
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:17,代碼來源:LoggingToFileThroughput.java

示例12: 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);
}
 
開發者ID:cscfa,項目名稱:bartleby,代碼行數:26,代碼來源:IOPerformance.java

示例13: createNewAppender

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
protected FileAppender<ILoggingEvent> createNewAppender(String alias) {
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	
	PatternLayoutEncoder encoder = new PatternLayoutEncoder();
	encoder.setContext(context);
	encoder.setPattern(pattern);
	encoder.start();

	FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
	appender.setAppend(true);
	appender.setFile(LOG_FOLDER + File.separator + alias + LOG_FILEEXT);
	appender.setEncoder(encoder);
	appender.setContext(context);
	appender.start();
	
	return appender;
}
 
開發者ID:andrey-desman,項目名稱:openhab-hdl,代碼行數:18,代碼來源:LoggingPersistenceService.java

示例14: buildAppender

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
@Override
public Appender<ILoggingEvent> buildAppender(Context logcingContext, String fileName) throws JoranException {
    // first sets up the paterns for log layout
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern(logTemplate);
    encoder.setContext(logcingContext);
    encoder.start();
    // then create a file appender for the given filename
    FileAppender<ILoggingEvent> appender = new FileAppender<ILoggingEvent>();
    appender.setContext(logcingContext);
    appender.setAppend(false);
    appender.setFile(logFolderName + "/" + fileName + ".log");
    appender.setEncoder(encoder);
    appender.start();

    return appender;
}
 
開發者ID:IRIT-SMAC,項目名稱:agent-tooling,代碼行數:18,代碼來源:AgentLog.java

示例15: getTestCaseLogger

import ch.qos.logback.core.FileAppender; //導入方法依賴的package包/類
/**
 * Finds or creates a logger for the test case called tcName with an appender writing 
 * to file named <tcName>.log
 * 
 * @param tcName
 * @return
 */
private Logger getTestCaseLogger(String tcName, String sutName, String sutDir, String testScheduleName) {
	FileAppender<ILoggingEvent> fileAppender = appenderMap.get(tcName);
	if (fileAppender == null) {
		LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
		PatternLayoutEncoder ple = new PatternLayoutEncoder();

		ple.setPattern("%date %level [%logger{36}] [%file:%line] %X{testcase}: %msg%n");
		ple.setContext(lc);
		ple.start();
		fileAppender = new FileAppender<ILoggingEvent>();
		fileAppender.setFile(sutDir + '/' + testScheduleName + '/' + tcName + ".log");
		fileAppender.setEncoder(ple);
		fileAppender.setContext(lc);
		fileAppender.start();
		appenderMap.put(tcName, fileAppender);
	}

	Logger logger = (Logger) LoggerFactory.getLogger(tcName);
	logger.addAppender(fileAppender);
	return logger;
}
 
開發者ID:MSG134,項目名稱:IVCT_Framework,代碼行數:29,代碼來源:JMSLogSink.java


注:本文中的ch.qos.logback.core.FileAppender.start方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。