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


Java FileAppender.setLayout方法代码示例

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


在下文中一共展示了FileAppender.setLayout方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupLogging

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
private void setupLogging() {
    LogManager.getLogManager().reset();
    Logger.getRootLogger().getLoggerRepository().resetConfiguration();

    final Logger rootLogger = Logger.getRootLogger();
    final PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
    final Level level = endPointHealthConfiguration.logLevel();

    final ConsoleAppender consoleAppender = new ConsoleAppender(layout, ConsoleAppender.SYSTEM_ERR);

    consoleAppender.setThreshold(level);
    consoleAppender.activateOptions();

    final FileAppender fileAppender = new FileAppender();

    fileAppender.setFile(endPointHealthConfiguration.logFile().getAbsolutePath());
    fileAppender.setLayout(layout);
    fileAppender.setThreshold(level);
    fileAppender.setAppend(true);
    fileAppender.setErrorHandler(new FallbackAppenderErrorHandler(rootLogger, fileAppender, consoleAppender));

    rootLogger.addAppender(fileAppender);

    fileAppender.activateOptions();
}
 
开发者ID:spypunk,项目名称:endpoint-health,代码行数:26,代码来源:EndPointHealthServiceImpl.java

示例2: addAppender

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
public static void addAppender() {
	FileAppender fa = new FileAppender();
	fa.setName("FileLogger");
	String logFile = getConfHome() + System.getProperty("file.separator") + "zoofx.log";
	fa.setFile(logFile);
	
	Enumeration<Appender> allAppenders = Logger.getRootLogger().getAllAppenders();
	if(allAppenders.hasMoreElements()){
		Appender appender = allAppenders.nextElement();
		if(appender instanceof ConsoleAppender){
			ConsoleAppender ca = (ConsoleAppender)appender;
			fa.setLayout(ca.getLayout());
			fa.setThreshold(ca.getThreshold());
		}
		fa.setAppend(true);
	}
	fa.activateOptions();
	
	Logger.getRootLogger().addAppender(fa);
}
 
开发者ID:ajiniesta,项目名称:zoofx,代码行数:21,代码来源:ZFXConf.java

示例3: setUp

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
	try {
		Files.delete(Paths.get(FILEPATH));
	} catch (Exception e) {
		// TODO: handle exception
	}
	
	FileAppender fa = new FileAppender();
	fa.setName("FileLogger");
	fa.setFile(FILEPATH);
	fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
	fa.setThreshold(Level.DEBUG);
	fa.setAppend(true);
	fa.activateOptions();

	//add appender to any Logger (here is root)
	Logger.getRootLogger().addAppender(fa);
}
 
开发者ID:bkusche,项目名称:bktail2,代码行数:20,代码来源:LogfileHandlerTest.java

示例4: getLogger

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
public Logger getLogger(Logger logger, JEVisObject dataSource) {
    String loggerFileName = dataSource.getName().replace(" ", "_") + "_ID(" + dataSource.getID() + ").log";
    String loggerName = dataSource.getID().toString();
    MDC.put(KEY, "" + loggerName);

    FileAppender appender = new FileAppender();
    appender.setLayout(new PatternLayout("[%d{dd MMM yyyy HH:mm:ss}][%c{2}]: %-10m%n"));
    appender.setFile(loggerFileName);
    appender.setAppend(true);
    appender.setImmediateFlush(true);
    appender.activateOptions();
    appender.setName(loggerName);
    ThreadFilter threadFilter = new ThreadFilter(loggerName);
    appender.addFilter(threadFilter);
    logger.setAdditivity(false);    //<--do not use default root logger
    logger.addAppender(appender);
    return logger;
}
 
开发者ID:OpenJEVis,项目名称:JECommons,代码行数:19,代码来源:DriverLoggerFactory.java

示例5: init

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
private static void init() {
    ConsoleAppender console = new ConsoleAppender(); //create appender
    //configure the appender
    String PATTERN = "%d [%p|%c|%C{1}] %m%n";
    console.setLayout(new PatternLayout(PATTERN));
    console.setThreshold(Level.TRACE);
    console.activateOptions();
    //add appender to any Logger (here is root)
    Logger.getRootLogger().addAppender(console);

    FileAppender fa = new FileAppender();
    fa.setName("FileLogger");
    fa.setFile("log.log");
    fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
    fa.setThreshold(Level.TRACE);
    fa.setAppend(true);
    fa.activateOptions();

    //add appender to any Logger (here is root)
    Logger.getRootLogger().addAppender(fa);

}
 
开发者ID:miho,项目名称:PiOnWheels,代码行数:23,代码来源:Main.java

示例6: initializeAnalysisLog

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
/**
 * Initialize the log4j logging infrastructure for the analysis run.
 */
private void initializeAnalysisLog() {

    // build the path of the log file
    // inside a log directory of the analysis workflow
    DateFormat logDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
    String logFile = WorkspaceUtil.getAbsoluteFromProjectRelativePath(
            "logs/vpm-analysis-" + (logDateFormat.format(new Date())) + ".csv",
            config.getSplevoProjectEditor().getSplevoProject());
    
    FileAppender fa = new FileAppender();
    fa.setName(CloseAnalysisTraceLogAppenderJob.LOG_APPENDER_NAME);
    fa.setFile(logFile);
    fa.setLayout(new PatternLayout("%m%n"));
    fa.setThreshold(Level.DEBUG);
    fa.setAppend(false);
    fa.activateOptions();
    Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).removeAllAppenders();
    Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).addAppender(fa);

    // insert header row
    Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).info("Analyzer,VP1, VP2, SourceInfo, TargetInfo, Remark");

}
 
开发者ID:kopl,项目名称:SPLevo,代码行数:27,代码来源:VPMAnalysisWorkflowDelegate.java

示例7: setupLogging

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
private void setupLogging() {
	// add in our custom per-file logging appender. anything that happens for this particular
	// file should go in this log file
	FileAppender appender = new FileAppender();

	File file = fileService.getById(getServiceContext(), getFileId());

	appender.setName("batch-" + getFileId());
	appender.setLayout(new PatternLayout("%d %-5p %c %x - %m%n"));
	appender.setFile(file.getPath() + java.io.File.separator + file.getFilename() + ".log");
	appender.setAppend(true);
	appender.activateOptions();

	Logger logger = Logger.getRootLogger();
	logger.addAppender(appender);
}
 
开发者ID:SmarterApp,项目名称:TechnologyReadinessTool,代码行数:17,代码来源:JobCompletionListener.java

示例8: testSourcePath

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
@Test
public void testSourcePath() throws Exception {
    logger.info("Hello World!");
    with(consoleWriter.toString()).assertThat("$.path", nullValue());

    // for the file appender there must be log file path in the json
    StringWriter fileWriter = new StringWriter();

    LogStashJsonLayout fileLayout = new LogStashJsonLayout();
    fileLayout.activateOptions();

    FileAppender fileAppender = spy(new FileAppender());
    doNothing().when(fileAppender).activateOptions();
    fileAppender.setWriter(fileWriter);
    fileAppender.setFile("/tmp/logger.log");
    fileAppender.setLayout(fileLayout);
    fileAppender.activateOptions();

    logger.addAppender(fileAppender);

    logger.info("Hello World!");
    with(fileWriter.toString())
        .assertThat("$.path", equalTo(new File(fileAppender.getFile()).getCanonicalPath()));
}
 
开发者ID:szhem,项目名称:log4j-json-layout,代码行数:25,代码来源:LogStashJsonLayoutTest.java

示例9: addFileAppender

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
private void addFileAppender(Logger rootLogger) {
	FileAppender fa = new FileAppender();
	  fa.setName("FileLogger");
	  fa.setFile("rubus.log");
	  fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
	  fa.setThreshold(Level.DEBUG);
	  fa.setAppend(true);
	  fa.activateOptions();

	  //add appender to any Logger (here is root)
	  Logger.getRootLogger().addAppender(fa);
	
}
 
开发者ID:adnanmitf09,项目名称:Rubus,代码行数:14,代码来源:Rubus.java

示例10: getLogger

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
/**
    * 
    * Get logger for logging execution status of the running job
    * 
    * @param jobID
    * @param fileLogLocation
    * @return {@link Logger}
    */
public Logger getLogger(String jobID,String fileLogLocation) {
	
	if (executionTrackingLoggers.containsKey(jobID)) {
		return executionTrackingLoggers.get(jobID);
	}
	
	//creates pattern layout
	PatternLayout layout = new PatternLayout();
	layout.setConversionPattern("%m%n");
	
	//create file appender
	FileAppender fileAppender = new FileAppender();
	fileAppender.setFile(fileLogLocation);
	fileAppender.setLayout(layout);
	fileAppender.activateOptions();
	//configures the root logger
	
	Logger logger = Logger.getLogger(jobID);
	logger.setLevel(Level.DEBUG);
	logger.addAppender(fileAppender);
	logger.getRootLogger().setAdditivity(false);
	logger.setAdditivity(false);
	executionTrackingLoggers.put(jobID, logger);
	
       return logger;
   }
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:35,代码来源:ExecutionTrackingLogger.java

示例11: SetFileLogger

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
public static void SetFileLogger(Level level, String filename) {
    FileAppender fa = new FileAppender();
    fa.setName("FileLogger_Debug");
    fa.setFile(filename);
    fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
    fa.setThreshold(level);
    fa.setAppend(false);
    fa.activateOptions();
    Logger.getRootLogger().addAppender(fa);
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:11,代码来源:ConsoleLogger.java

示例12: CISCoreStandaloneApp

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
public CISCoreStandaloneApp() throws CISConfigException {
	ConsoleAppender console = new ConsoleAppender(); //create appender
	  //configure the appender
	  String PATTERN = "%d [%p|%c|%C{1}] %m%n";
	  console.setLayout(new PatternLayout(PATTERN)); 
	  console.setThreshold(Level.DEBUG);
	  console.activateOptions();
	  //add appender to any Logger (here is root)
	  Logger.getRootLogger().addAppender(console);

	  FileAppender fa = new FileAppender();
	  fa.setName("CISCoreLogger");
	  fa.setFile("./log/CISCore.log");
	  fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
	  fa.setThreshold(Level.DEBUG);
	  fa.setAppend(true);
	  fa.activateOptions();

	  //add appender to any Logger (here is root)
	  Logger.getRootLogger().addAppender((Appender)fa);
	  //repeat with all other desired appenders
	  
	  log = Logger.getLogger(this.getClass());
	  
	  Boolean ignoreError = Boolean.parseBoolean(PropertiesReader.getInstance().getPropertie("startup.ignore.error"));
	  log.info("Ignore Errors on CoreStartup: " + ignoreError);
	  
	  try {
		  CISCoreImpl cisCore = CISCoreImpl.getInstance();
	  } catch (Exception e) {
		  if (!ignoreError) {
			  throw e;
		  }
	  }
	  
	  ConnectorCallbackHandlerImpl callbackHandler = ConnectorCallbackHandlerImpl.getInstance();
	  callbackHandler.registerCallback(new RestConnectorCallback(PropertiesReader.getInstance().getPropertie("core.connector.rest.callback")));
	  
	  log.info("Init. CISCoreStandaloneApp");
}
 
开发者ID:DRIVER-EU,项目名称:CommonInformationSpace,代码行数:41,代码来源:CISCoreStandaloneApp.java

示例13: initLogger

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
private static void initLogger(String filename) {
	final String PATTERN = "[%d{yyyy-MM-dd HH:mm:ss}] [%-5p] [%c{1}] %m%n";
	
	// Stores whether an error has occured
	AppenderSkeleton errorFlagAppender = new ErrorFlagAppender();
	errorFlagAppender.setThreshold(Level.ERROR);
	errorFlagAppender.activateOptions();
	org.apache.log4j.Logger.getRootLogger().addAppender(errorFlagAppender);

	ConsoleAppender consoleAppender = new ConsoleAppender(); 
	consoleAppender.setEncoding("UTF-8");
	consoleAppender.setLayout(new PatternLayout(PATTERN)); 
	consoleAppender.setThreshold(LOG_LEVEL);
	consoleAppender.activateOptions();		
	AsyncAppender asyncConsoleAppender = new AsyncAppender();
	asyncConsoleAppender.addAppender(consoleAppender);
	asyncConsoleAppender.setBufferSize(1024);
	asyncConsoleAppender.activateOptions();
	org.apache.log4j.Logger.getRootLogger().addAppender(asyncConsoleAppender);
	
	FileAppender fileAppender = new FileAppender();
	fileAppender.setEncoding("UTF-8");
	fileAppender.setFile(filename);
	fileAppender.setLayout(new PatternLayout(PATTERN));
	fileAppender.setThreshold(LOG_LEVEL);
	fileAppender.setAppend(false);
	fileAppender.activateOptions();
	AsyncAppender asyncFileAppender = new AsyncAppender();
	asyncFileAppender.addAppender(fileAppender);
	asyncFileAppender.setBufferSize(1024);
	asyncFileAppender.activateOptions();
	org.apache.log4j.Logger.getRootLogger().addAppender(asyncFileAppender);
	
}
 
开发者ID:heindorf,项目名称:cikm16-wdvd-feature-extraction,代码行数:35,代码来源:FeatureExtractor.java

示例14: configureLogger

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
public static void configureLogger(File logFile) {
    Bundle bundle = Platform.getBundle("tools.vitruv.integration");
    URL fileURL = bundle.getEntry("log4j.xml");
    DOMConfigurator.configure(fileURL);

    FileAppender appender = new FileAppender();
    appender.setName("LogFile");
    appender.setFile(logFile.getAbsolutePath());
    appender.setThreshold(Level.INFO);
    appender.setLayout(new PatternLayout("%-5p [%t]: %m%n"));
    appender.setAppend(true);
    appender.activateOptions();

    Logger.getRootLogger().addAppender(appender);
}
 
开发者ID:vitruv-tools,项目名称:Vitruv,代码行数:16,代码来源:LoggerConfigurator.java

示例15: initLogger

import org.apache.log4j.FileAppender; //导入方法依赖的package包/类
public static void initLogger() {
  if (logger == null) {
    long requiredFreeSpace = 1000000;
    String logFolder = getDir(requiredFreeSpace);
    FileAppender update = new FileAppender();

    update.setFile(new File(logFolder, "idea_updater.log").getAbsolutePath());
    update.setLayout(new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-5p %C{1}.%M - %m%n"));
    update.setThreshold(Level.ALL);
    update.setAppend(true);
    update.activateOptions();

    FileAppender updateError = new FileAppender();
    updateError.setFile(new File(logFolder, "idea_updater_error.log").getAbsolutePath());
    updateError.setLayout(new PatternLayout("%d{dd MMM yyyy HH:mm:ss} %-5p %C{1}.%M - %m%n"));
    updateError.setThreshold(Level.ERROR);
    updateError.setAppend(false);
    updateError.activateOptions();

    logger = Logger.getLogger("com.intellij.updater");
    logger.addAppender(updateError);
    logger.addAppender(update);
    logger.setLevel(Level.ALL);

    logger.info("--- Updater started ---");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:Runner.java


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