当前位置: 首页>>代码示例>>Java>>正文


Java FileAppender.setAppend方法代码示例

本文整理汇总了Java中ch.qos.logback.core.FileAppender.setAppend方法的典型用法代码示例。如果您正苦于以下问题:Java FileAppender.setAppend方法的具体用法?Java FileAppender.setAppend怎么用?Java FileAppender.setAppend使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.core.FileAppender的用法示例。


在下文中一共展示了FileAppender.setAppend方法的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: 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

示例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());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:19,代码来源:FileAppenderTest.java

示例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());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:26,代码来源:FileAppenderTest.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: setOutput

import ch.qos.logback.core.FileAppender; //导入方法依赖的package包/类
private static void setOutput(final String... paths) throws IOException {
    LOG_ROOT.getLoggerContext().reset();

    final PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setPattern("%date %level [%thread] [%file:%line] %msg%n");
    encoder.setContext(LOG_ROOT.getLoggerContext());
    encoder.start();

    for (final String path : paths) {
        // create FileAppender
        final FileAppender<ILoggingEvent> logfileOut = new FileAppender<>();
        logfileOut.setAppend(false);
        logfileOut.setFile(path);
        logfileOut.setContext(LOG_ROOT.getLoggerContext());
        logfileOut.setEncoder(encoder);
        logfileOut.start();

        // attach the rolling file appender to the root logger
        LOG_ROOT.addAppender(logfileOut);
    }
}
 
开发者ID:opendaylight,项目名称:yangtools,代码行数:22,代码来源:Main.java

示例13: 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);
}
 
开发者ID:dmazinanian,项目名称:css-analyser,代码行数:23,代码来源:FileLogger.java

示例14: 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:openhab,项目名称:openhab1-addons,代码行数:18,代码来源:LoggingPersistenceService.java

示例15: 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);
}
 
开发者ID:strykeforce,项目名称:thirdcoast,代码行数:33,代码来源:LoggingConfigurator.java


注:本文中的ch.qos.logback.core.FileAppender.setAppend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。