當前位置: 首頁>>代碼示例>>Java>>正文


Java FileAppender.getFile方法代碼示例

本文整理匯總了Java中org.apache.log4j.FileAppender.getFile方法的典型用法代碼示例。如果您正苦於以下問題:Java FileAppender.getFile方法的具體用法?Java FileAppender.getFile怎麽用?Java FileAppender.getFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.log4j.FileAppender的用法示例。


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

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
 * Get the root logger file location under which the failed log messages will be written.
 *
 * Since this class is used in Hooks which run within JVMs of other components like Hive,
 * we want to write the failed messages file under the same location as where logs from
 * the host component are saved. This method attempts to get such a location from the
 * root logger's appenders. It will work only if at least one of the appenders is a {@link FileAppender}
 *
 * @return directory under which host component's logs are stored.
 */
private String getRootLoggerDirectory() {
    String rootLoggerDirectory = null;
    org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();

    Enumeration allAppenders = rootLogger.getAllAppenders();
    if (allAppenders != null) {
        while (allAppenders.hasMoreElements()) {
            Appender appender = (Appender) allAppenders.nextElement();
            if (appender instanceof FileAppender) {
                FileAppender fileAppender = (FileAppender) appender;
                String rootLoggerFile = fileAppender.getFile();
                rootLoggerDirectory = new File(rootLoggerFile).getParent();
                break;
            }
        }
    }
    return rootLoggerDirectory;
}
 
開發者ID:apache,項目名稱:incubator-atlas,代碼行數:29,代碼來源:FailedMessagesLogger.java

示例4: addHostToFilename

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void addHostToFilename(FileAppender fileApp) {
    String hostID = Math.abs(UniqueID.getCurrentVMID().hashCode() % 100000) + "-" +
                    ProActiveInet.getInstance().getHostname();
    String fileName = fileApp.getFile();
    File filePath = new File(fileName);
    String hostFileName;
    String name = filePath.getName();
    String pathToFile = filePath.getParent();
    int point = name.indexOf('.');
    if (point == -1) {
        hostFileName = fileName + "-" + hostID;
    } else {
        String extension = name.substring(point + 1);
        String nameNoExtension = name.substring(0, point);
        hostFileName = (pathToFile != null ? pathToFile : "") + File.separator + nameNoExtension + "-" + hostID +
                       "." + extension;
    }
    System.out.println("New output file:" + hostFileName);
    fileApp.setFile(hostFileName);
    fileApp.activateOptions();
}
 
開發者ID:ow2-proactive,項目名稱:scheduling,代碼行數:22,代碼來源:ActiveActor.java

示例5: 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:loye168,項目名稱:tddl5,代碼行數:22,代碼來源:Log4jLoggerAdapter.java

示例6: 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:hufeng,項目名稱:dubbo2.js,代碼行數:22,代碼來源:LogPageHandler.java

示例7: 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:hufeng,項目名稱:dubbo2.js,代碼行數:22,代碼來源:Log4jLoggerAdapter.java

示例8: SystemLogPage

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public SystemLogPage() {
	super();
	
	WebMarkupContainer cssContainer = new WebMarkupContainer("cssPath");
       cssContainer.add(new AttributeModifier("href", ThemesManager.getInstance().getThemeRelativePathCss()));
       add(cssContainer);
	
	FileAppender appender = (FileAppender) LogManager.getRootLogger().getAppender("FILE");
	File logFile = new File(appender.getFile());
	
	String content;
	try {
		content = FileUtils.readFileToString(logFile);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		content = e.toString();
	}
	
	add(new Label("size", FileUtils.byteCountToDisplaySize(logFile.length())));
	add(new Label("lastModified", new Date(logFile.lastModified()).toString()));
	add(new MultiLineLabel("log", content));
}
 
開發者ID:nextreports,項目名稱:nextreports-server,代碼行數:24,代碼來源:SystemLogPage.java

示例9: getActiveLogFiles

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public static Set<File> getActiveLogFiles() throws IOException {
  Set<File> ret = Sets.newHashSet();
  Appender a;
  @SuppressWarnings("unchecked")
  Enumeration<Appender> e = Logger.getRootLogger().getAllAppenders();
  while (e.hasMoreElements()) {
    a = e.nextElement();
    if (a instanceof FileAppender) {
      FileAppender fa = (FileAppender) a;
      String filename = fa.getFile();
      ret.add(new File(filename));
    }
  }
  return ret;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:16,代碼來源:LogMonitoring.java

示例10: setFileAppender

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private static void setFileAppender(FileAppender bizFileAppender, String logName) {
    FileAppender fileAppender = getFileAppender(Logger.getLogger(logName));
    String bizLogDir = new File(bizFileAppender.getFile()).getParent();

    File newLogFile = new File(bizLogDir, fileAppender.getFile());

    fileAppender.setFile(newLogFile.getAbsolutePath());
    fileAppender.activateOptions(); // 很重要,否則原有日誌內容會被清空
    log.warn("成功為" + logName + "添加Appender. 輸出路徑:" + newLogFile.getAbsolutePath());
}
 
開發者ID:lysu,項目名稱:diamond,代碼行數:11,代碼來源:LoggerInit.java

示例11: getLogFileInformation

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public static LogFileInformation getLogFileInformation(Logger logger)
{
  if (logger == null) {
    logger = LogManager.getRootLogger();
  }
  FileAppender fileAppender = getFileAppender(logger);
  if (fileAppender != null) {
    File logFile = new File(fileAppender.getFile());
    LogFileInformation logFileInfo = new LogFileInformation(fileAppender.getFile(), logFile.length());
    return logFileInfo;
  }
  return null;
}
 
開發者ID:apache,項目名稱:apex-core,代碼行數:14,代碼來源:LoggerUtil.java

示例12: setFileAppender

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private static void setFileAppender(FileAppender bizFileAppender, String logName) {
    FileAppender fileAppender = getFileAppender(Logger.getLogger(logName));
    String bizLogDir = new File(bizFileAppender.getFile()).getParent();

    File newLogFile = new File(bizLogDir, fileAppender.getFile());

    fileAppender.setFile(newLogFile.getAbsolutePath());
    fileAppender.activateOptions(); // 很重要,否則原有日誌內容會被清空
    logger.warn("成功為" + logName + "添加Appender. 輸出路徑:" + newLogFile.getAbsolutePath());
}
 
開發者ID:xushaomin,項目名稱:diamond-v2.1.1,代碼行數:11,代碼來源:LoggerInit.java

示例13: getLogFile

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
 * returns the first configured {@link FileAppender} or <code>null</code>.
 * 
 * @return
 */
public static String getLogFile() {
	Enumeration<?> enu = Logger.getRootLogger().getAllAppenders();
	while (enu.hasMoreElements()) {
		Object o = enu.nextElement();
		if (o instanceof FileAppender) {
			FileAppender fa = (FileAppender) o;
			return fa.getFile();
		}
	}
	return null;
}
 
開發者ID:bh4017,項目名稱:mobac,代碼行數:17,代碼來源:Logging.java

示例14: getAppenderPath

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private String getAppenderPath(FileAppender fileAppender) {
    String path = null;
    try {
        String fileName = fileAppender.getFile();
        if (fileName != null && !fileName.isEmpty()) {
            path = new File(fileName).getCanonicalPath();
        }
    } catch (IOException e) {
        LogLog.error("Unable to retrieve appender's file name", e);
    }
    return path;
}
 
開發者ID:szhem,項目名稱:log4j-json-layout,代碼行數:13,代碼來源:LogStashJsonLayout.java

示例15: setFileAppender

import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private static void setFileAppender(FileAppender bizFileAppender, String logName) {
    FileAppender fileAppender = getFileAppender(Logger.getLogger(logName));
    String bizLogDir = new File(bizFileAppender.getFile()).getParent();

    File newLogFile = new File(bizLogDir, fileAppender.getFile());

    fileAppender.setFile(newLogFile.getAbsolutePath());
    fileAppender.activateOptions(); // ����Ҫ������ԭ����־���ݻᱻ���
    log.warn("�ɹ�Ϊ" + logName + "���Appender. ���·��:" + newLogFile.getAbsolutePath());
}
 
開發者ID:weijiahao001,項目名稱:tb_diamond,代碼行數:11,代碼來源:LoggerInit.java


注:本文中的org.apache.log4j.FileAppender.getFile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。