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


Java FileAppender类代码示例

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


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

示例1: Log4jLoggerAdapter

import org.apache.log4j.FileAppender; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Log4jLoggerAdapter() {
	try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
           if (logger != null) {
               Enumeration<Appender> appenders = logger.getAllAppenders();
               if (appenders != null) {
                   while (appenders.hasMoreElements()) {
                       Appender appender = appenders.nextElement();
                       if (appender instanceof FileAppender) {
                           FileAppender fileAppender = (FileAppender)appender;
                           String filename = fileAppender.getFile();
                           file = new File(filename);
                           break;
                       }
                   }
               }
           }
       } catch (Throwable t) {
       }
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:22,代码来源:Log4jLoggerAdapter.java

示例2: LogPageHandler

import org.apache.log4j.FileAppender; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public LogPageHandler() {
    try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
        if (logger != null) {
            Enumeration<Appender> appenders = logger.getAllAppenders();
            if (appenders != null) {
                while (appenders.hasMoreElements()) {
                    Appender appender = appenders.nextElement();
                    if (appender instanceof FileAppender) {
                        FileAppender fileAppender = (FileAppender)appender;
                        String filename = fileAppender.getFile();
                        file = new File(filename);
                        break;
                    }
                }
            }
        }
    } catch (Throwable t) {
    }
   }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:LogPageHandler.java

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

示例4: Notifier

import org.apache.log4j.FileAppender; //导入依赖的package包/类
public Notifier(int port) throws Exception {
    this.port = port;
    Properties properties = new Properties();
    logger.addAppender(new FileAppender(new SimpleLayout(), "notifieroutputlog_" + port
            + ".txt"));

    properties.setProperty("javax.sip.STACK_NAME", "notifier" + port);
    // You need 16 for logging traces. 32 for debug + traces.
    // Your code will limp at 32 but it is best for debugging.
    properties.setProperty("gov.nist.javax.sip.TRACE_LEVEL", "32");
    properties.setProperty("gov.nist.javax.sip.DEBUG_LOG", "notifierdebug_" + port
            + ".txt");
    properties.setProperty("gov.nist.javax.sip.SERVER_LOG", "notifierlog_" + port
            + ".txt");
    if(System.getProperty("enableNIO") != null && System.getProperty("enableNIO").equalsIgnoreCase("true")) {
    	logger.info("\nNIO Enabled\n");
    	properties.setProperty("gov.nist.javax.sip.MESSAGE_PROCESSOR_FACTORY", NioMessageProcessorFactory.class.getName());
    }
    // Create SipStack object
    sipStack = sipFactory.createSipStack(properties);
    logger.info("sipStack = " + sipStack);
    this.createProvider( );
    this.udpProvider.addSipListener(this);
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:25,代码来源:DeliverNotifyBefore202Test.java

示例5: setUpExperimentalLogger

import org.apache.log4j.FileAppender; //导入依赖的package包/类
private static void setUpExperimentalLogger(File pathF) throws IOException {
	
	Logger.getRootLogger().removeAllAppenders();
	log.removeAllAppenders();
	
	PropertyConfigurator.configure("resource/log4jproperties.txt");
	
	FileAppender resultAppender = new FileAppender(
			new PatternLayout("%m"),
			new File(pathF, "result.txt").toString(), false);
	
	LevelRangeFilter infoFilter = new LevelRangeFilter();
	infoFilter.setLevelMin(Level.INFO);
	infoFilter.setLevelMax(Level.FATAL);
	infoFilter.setAcceptOnMatch(true);
	resultAppender.addFilter(infoFilter);
	log.addAppender(resultAppender);
	Logger.getLogger(iBench.class).addAppender(resultAppender);
	
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:21,代码来源:iBenchDriver.java

示例6: setUpConfigLogger

import org.apache.log4j.FileAppender; //导入依赖的package包/类
private static void setUpConfigLogger(File pathF, String configName) throws IOException {
	Logger.getRootLogger().removeAllAppenders();
	
	String nameSuffix = configName.replace(".txt", "");
	
	PropertyConfigurator.configure("resource/log4jproperties.txt");	
	
	FileAppender logFileAppender = new FileAppender(
			new PatternLayout("%-4r [%t] %-5p %c %x - %m%n"),
			new File(pathF, "log_" + nameSuffix + ".txt").toString(), false);
	Logger.getRootLogger().addAppender(logFileAppender);
	
	if (opt.logToConsole)
		Logger.getRootLogger().addAppender(new ConsoleAppender(
				new PatternLayout("%-4r [%t] %-5p %c %x - %m%n")));
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:17,代码来源:iBenchDriver.java

示例7: LogUtil

import org.apache.log4j.FileAppender; //导入依赖的package包/类
public LogUtil(LogConfig config, Object obj){
	this.logConfig = config;
	if(LogConfig.logType == 0){
		report = new ExtentReports(config.getExtentLogPath(),false);
		File configFile = new File(System.getProperty("user.dir") + "\\configs\\extent-config.xml");
		if(configFile.exists()) {
			report.loadConfig(configFile);		
		}		
		testLog = report.startTest(String.valueOf(obj));
	}else{
		logger = Logger.getLogger(String.valueOf(obj));
		Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} [%p] %c:%L �� %m%n");  
		try {
			Appender appender = new FileAppender(layout, config.getLog4jPath());
			logger.addAppender(appender);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
}
 
开发者ID:AlanYangs,项目名称:Log4Reports,代码行数:21,代码来源:LogUtil.java

示例8: setLogerConfig

import org.apache.log4j.FileAppender; //导入依赖的package包/类
/**
 * 设置日志配置
 * @param level
 * @param fileName
 * @param append
 * @return this
 */
public SpiderApp setLogerConfig(int level,String fileName,boolean append,String configFilename){
	logMap.put("level", level);
	logMap.put("fileName", fileName);
	logMap.put("append",append);
	logMap.put("configFilename",configFilename);
	logger = Logger.getLogger(SpiderApp.class);
	Level logLevel = getLogLevel(level);
	try {
		FileAppender appender = new FileAppender(new SimpleLayout(), fileName,append);
		if(null == configFilename){
			BasicConfigurator.configure();
		}else{
			PropertyConfigurator.configure(configFilename);
		}
		logger.addAppender(appender);
		logger.setLevel(logLevel);
	} catch (IOException e) {
		e.printStackTrace(System.err);
	} 
	return this;
}
 
开发者ID:MashiMaroLjc,项目名称:FunnySpider,代码行数:29,代码来源:SpiderApp.java

示例9: reopenLogs

import org.apache.log4j.FileAppender; //导入依赖的package包/类
private void reopenLogs(int counter)
{
  Logger root = Logger.getRootLogger();
  @SuppressWarnings("unchecked")
  Enumeration<Appender> rootAppenders = root.getAllAppenders();
  FileAppender logOutput = (FileAppender) rootAppenders.nextElement();
  // assume there's only the one, and that it's a file appender
  logOutput.setFile("log/broker" + counter + ".trace");
  logOutput.activateOptions();
  
  Logger state = Logger.getLogger("State");
  @SuppressWarnings("unchecked")
  Enumeration<Appender> stateAppenders = state.getAllAppenders();
  FileAppender stateOutput = (FileAppender) stateAppenders.nextElement();
  // assume there's only the one, and that it's a file appender
  stateOutput.setFile("log/broker" + counter + ".state");
  stateOutput.activateOptions();
}
 
开发者ID:LARG,项目名称:TacTex,代码行数:19,代码来源:BrokerRunner.java

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

示例11: getLogger

import org.apache.log4j.FileAppender; //导入依赖的package包/类
public static Logger getLogger(final Class<?> cl, final String initFile, final String property) {

		Properties properties;
		Logger c = null;
		try {
			ManagerIni mi = initFile != null ? ManagerIni.createManagerIniFile(initFile) : ManagerIni.createManagerIniParameter();
			properties = mi.getSession("FreedomLogger");
			c = Logger.getLogger(cl.getCanonicalName(), myFactory);
			Layout layout = new PatternLayout(LAYOUT_DEFAULT);
			c.addAppender(new FileAppender(layout, properties.get(property).toString(), true));
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return c;
	}
 
开发者ID:cams7,项目名称:erp,代码行数:17,代码来源:FreedomLogger.java

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

示例13: initFileLogging

import org.apache.log4j.FileAppender; //导入依赖的package包/类
/**
* Initializes logging to a file.
* @param loggerNames the names of the loggers (usually names of packages
* or classes or ancestors of packages or classes). Can't be null.
* @param argMap command line arguments.
*/
public static synchronized void initFileLogging(String[] loggerNames, ArgumentMap argMap, String filename)
    throws IOException
{
    Level level = DEFAULT_FILE_LOGGING_LEVEL;
    if (argMap.isSet(Argument.LOG_QUIET_SHORT) || argMap.isSet(Argument.LOG_QUIET)) level = Level.ERROR;
    if (argMap.isSet(Argument.LOG_VERBOSE_SHORT) || argMap.isSet(Argument.LOG_VERBOSE)) level = Level.INFO;
    if (argMap.isSet(Argument.LOG_DEBUG_SHORT) || argMap.isSet(Argument.DEBUG)) level = Level.DEBUG;

    FileAppender fileAppender = new FileAppender(new PatternLayout(), filename);

    boolean append = true;
    Writer fileWriter = new FileWriter(filename, append);
    for (String loggerName : loggerNames)
        Log4jInit.setLevel(loggerName, level, fileWriter);
}
 
开发者ID:opencadc,项目名称:caom2,代码行数:22,代码来源:Util.java

示例14: setupLog4jForAction

import org.apache.log4j.FileAppender; //导入依赖的package包/类
/**
 * Setup the Log4J logger for this action thread.
 * @return String path to log file
 * @throws IOException If there's something wrong with the FileAppender.
 */
private void setupLog4jForAction() throws IOException {
    String loggerName = "Action_" + this.id;
    org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger("Action_" + this.id);
    String logRoot = System.getProperty("LOG_ROOT");
    if(logRoot == null) {
        logRoot = ".";
    }
    String logFilePath = logRoot + "/charles-rest/ActionsLogs/" + this.id + ".log";
    
    File logFile = new File(logFilePath);
    logFile.getParentFile().mkdirs();
    logFile.createNewFile();//you have to create the file yourself since FileAppender acts funny under linux if the file doesn't already exist.

    FileAppender fa = new FileAppender(new PatternLayout("%d %p - %m%n"), logFilePath);
    fa.setName(this.id + "_appender");
    fa.setThreshold(Level.DEBUG);
    log4jLogger.addAppender(fa);
    log4jLogger.setLevel(Level.DEBUG);
    
    this.logger = LoggerFactory.getLogger(loggerName);
    
}
 
开发者ID:opencharles,项目名称:charles-rest,代码行数:28,代码来源:Action.java

示例15: configureAuditLogging

import org.apache.log4j.FileAppender; //导入依赖的package包/类
/**
 * Sets up audit logging to log to a file named based on the current time (in
 * ms).
 *
 * The logger is configured to effectively ignore the log level.
 *
 * @throws IOException
 *           if the audit log file could not be opened for writing.
 */
public static void configureAuditLogging() throws IOException {
  PatternLayout layout = new PatternLayout(AUDIT_LOG_FORMAT);
  // This assumes that no other daemon will be started within 1 millisecond.
  String filename = String.format(AUDIT_LOG_FILENAME_FORMAT,
      System.currentTimeMillis(), new Random().nextInt(Integer.MAX_VALUE));
  FileAppender fileAppender = new FileAppender(layout, filename);
  Logger auditLogger = Logger.getLogger(Logging.AUDIT_LOGGER_NAME);
  auditLogger.addAppender(fileAppender);
  auditLogger.setLevel(Level.ALL);
  /*
   * We don't want audit messages to be appended to the main appender, which
   * is intended for potentially user-facing messages.
   */
  auditLogger.setAdditivity(false);
}
 
开发者ID:epfl-labos,项目名称:eagle,代码行数:25,代码来源:Logging.java


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