本文整理汇总了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());
}