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


Java FileAppender.setName方法代码示例

本文整理汇总了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);
}
 
开发者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包/类
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

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

示例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);
}
 
开发者ID:code-distillery,项目名称:jackrabbit-pm-tools,代码行数:18,代码来源:Main.java

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

示例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;
}
 
开发者ID:mwsobol,项目名称:SORCER,代码行数:17,代码来源:RemoteLoggerManager.java

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

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

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

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

示例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;
}
 
开发者ID:termsuite,项目名称:termsuite-core,代码行数:8,代码来源:LogbackUtils.java

示例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);
}
 
开发者ID:IAreKyleW00t,项目名称:aradiabot,代码行数:30,代码来源:Main.java


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