當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。