public class Log4jManagerImpl implements LogManager {
private static final String FILE_APPENDER_ID = "D";
private static FileAppender getFileAppender() {
Appender appender = Logger.getRootLogger()
.getAppender(FILE_APPENDER_ID);
return (appender instanceof FileAppender ? (FileAppender) appender
: null);
}
public String getLogFile() {
return getFileAppender() == null ? null : getFileAppender().getFile();
}
}
import java.io.File;
import org.
apache.log4j.Appender;
import org.apache.log4j.DailyRollingFileAppender;
import org.apache.log4j.Logger;
public class DcsLog {
// protected transient Log logger = LogFactory.getLog(getClass());
protected transient Logger logger = Logger.getLogger(getClass());
private static DcsLog instance;
private static final String FILE_APPENDER_ID = "R";
private DcsLog() {
}
public synchronized static DcsLog getInstance() {
if (instance == null) {
instance = new DcsLog();
}
return instance;
}
public Appender getFileAppender() {
DailyRollingFileAppender appender = (DailyRollingFileAppender) Logger
.getRootLogger().getAppender(FILE_APPENDER_ID);
return appender;
}
public File getFile() {
return new File(((DailyRollingFileAppender) getFileAppender())
.getFile());
}
public static void main(String[] args) {
DcsLog o = DcsLog.getInstance();
System.out.println(o.getFile().getName());
System.out.println(o.getFile().getAbsolutePath());
}
}