本文整理匯總了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) {
}
}
示例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) {
}
}
示例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;
}
示例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();
}
示例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) {
}
}
示例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) {
}
}
示例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) {
}
}
示例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));
}
示例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;
}
示例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());
}
示例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;
}
示例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());
}
示例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;
}
示例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;
}
示例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());
}