本文整理匯總了Java中org.apache.log4j.FileAppender.setFile方法的典型用法代碼示例。如果您正苦於以下問題:Java FileAppender.setFile方法的具體用法?Java FileAppender.setFile怎麽用?Java FileAppender.setFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.log4j.FileAppender
的用法示例。
在下文中一共展示了FileAppender.setFile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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();
}
示例3: 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);
}
示例4: 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);
}
示例5: 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();
}
示例6: getLogger
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
public Logger getLogger(Logger logger, JEVisObject dataSource) {
String loggerFileName = dataSource.getName().replace(" ", "_") + "_ID(" + dataSource.getID() + ").log";
String loggerName = dataSource.getID().toString();
MDC.put(KEY, "" + loggerName);
FileAppender appender = new FileAppender();
appender.setLayout(new PatternLayout("[%d{dd MMM yyyy HH:mm:ss}][%c{2}]: %-10m%n"));
appender.setFile(loggerFileName);
appender.setAppend(true);
appender.setImmediateFlush(true);
appender.activateOptions();
appender.setName(loggerName);
ThreadFilter threadFilter = new ThreadFilter(loggerName);
appender.addFilter(threadFilter);
logger.setAdditivity(false); //<--do not use default root logger
logger.addAppender(appender);
return logger;
}
示例7: init
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private static void init() {
ConsoleAppender console = new ConsoleAppender(); //create appender
//configure the appender
String PATTERN = "%d [%p|%c|%C{1}] %m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.TRACE);
console.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(console);
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile("log.log");
fa.setLayout(new PatternLayout("%d %-5p [%c{1}] %m%n"));
fa.setThreshold(Level.TRACE);
fa.setAppend(true);
fa.activateOptions();
//add appender to any Logger (here is root)
Logger.getRootLogger().addAppender(fa);
}
示例8: initializeAnalysisLog
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Initialize the log4j logging infrastructure for the analysis run.
*/
private void initializeAnalysisLog() {
// build the path of the log file
// inside a log directory of the analysis workflow
DateFormat logDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
String logFile = WorkspaceUtil.getAbsoluteFromProjectRelativePath(
"logs/vpm-analysis-" + (logDateFormat.format(new Date())) + ".csv",
config.getSplevoProjectEditor().getSplevoProject());
FileAppender fa = new FileAppender();
fa.setName(CloseAnalysisTraceLogAppenderJob.LOG_APPENDER_NAME);
fa.setFile(logFile);
fa.setLayout(new PatternLayout("%m%n"));
fa.setThreshold(Level.DEBUG);
fa.setAppend(false);
fa.activateOptions();
Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).removeAllAppenders();
Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).addAppender(fa);
// insert header row
Logger.getLogger(VPMAnalyzer.LOG_CATEGORY).info("Analyzer,VP1, VP2, SourceInfo, TargetInfo, Remark");
}
示例9: setupLogging
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void setupLogging() {
// add in our custom per-file logging appender. anything that happens for this particular
// file should go in this log file
FileAppender appender = new FileAppender();
File file = fileService.getById(getServiceContext(), getFileId());
appender.setName("batch-" + getFileId());
appender.setLayout(new PatternLayout("%d %-5p %c %x - %m%n"));
appender.setFile(file.getPath() + java.io.File.separator + file.getFilename() + ".log");
appender.setAppend(true);
appender.activateOptions();
Logger logger = Logger.getRootLogger();
logger.addAppender(appender);
}
示例10: LogMonitor
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Create a new LogMonitor on the specified file if the file does not exist
* or the value is null then a new Log4j appender will be added and
* monitoring set up on that appender.
*
* NOTE: for the appender to receive any value the RootLogger will need to
* have the level correctly configured.ng
*
* @param file the file to monitor
*
* @throws IOException if there is a problem creating a temporary file
*/
public LogMonitor(File file) throws IOException
{
if (file != null && file.exists())
{
_logfile = file;
}
else
{
// This is mostly for running the test outside of the ant setup
_logfile = File.createTempFile("LogMonitor", ".log");
_appender = new FileAppender(new SimpleLayout(),
_logfile.getAbsolutePath());
_appender.setFile(_logfile.getAbsolutePath());
_appender.setImmediateFlush(true);
Logger.getRootLogger().addAppender(_appender);
}
}
示例11: initLogger
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void initLogger(HConfig config) {
String logLevel = config.getValue("bypshttp.log.level", "WARN");
String logFile = config.getValue("bypshttp.log.file", null);
if (logFile != null) {
logFile = logFile.replace('/', File.separatorChar);
Logger rootLogger = Logger.getRootLogger();
Appender ap = rootLogger.getAppender("FI");
if (ap != null) {
FileAppender fap = (FileAppender) ap;
fap.setFile(logFile);
fap.activateOptions();
}
if (logLevel.equalsIgnoreCase("DEBUG")) rootLogger.setLevel(Level.DEBUG);
if (logLevel.equalsIgnoreCase("INFO")) rootLogger.setLevel(Level.INFO);
if (logLevel.equalsIgnoreCase("WARN")) rootLogger.setLevel(Level.WARN);
if (logLevel.equalsIgnoreCase("ERROR")) rootLogger.setLevel(Level.ERROR);
if (log.isDebugEnabled()) log.debug("Logger opened.");
}
}
示例12: testSourcePath
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
@Test
public void testSourcePath() throws Exception {
logger.info("Hello World!");
with(consoleWriter.toString()).assertThat("$.path", nullValue());
// for the file appender there must be log file path in the json
StringWriter fileWriter = new StringWriter();
LogStashJsonLayout fileLayout = new LogStashJsonLayout();
fileLayout.activateOptions();
FileAppender fileAppender = spy(new FileAppender());
doNothing().when(fileAppender).activateOptions();
fileAppender.setWriter(fileWriter);
fileAppender.setFile("/tmp/logger.log");
fileAppender.setLayout(fileLayout);
fileAppender.activateOptions();
logger.addAppender(fileAppender);
logger.info("Hello World!");
with(fileWriter.toString())
.assertThat("$.path", equalTo(new File(fileAppender.getFile()).getCanonicalPath()));
}
示例13: setup
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Sets ripper's:
* Working directory
* Logger (for debugging)
* FileAppender
* Threadpool
* @throws IOException
* Always be prepared.
*/
public void setup() throws IOException {
setWorkingDir(this.url);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
fa.setFile(this.workingDir + File.separator + "log.txt");
fa.activateOptions();
}
this.threadPool = new DownloadThreadPool();
}
示例14: checkIfComplete
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
/**
* Notifies observers and updates state if all files have been ripped.
*/
void checkIfComplete() {
if (observer == null) {
logger.debug("observer is null");
return;
}
if (!completed) {
completed = true;
logger.info(" Rip completed!");
RipStatusComplete rsc = new RipStatusComplete(workingDir, getCount());
RipStatusMessage msg = new RipStatusMessage(STATUS.RIP_COMPLETE, rsc);
observer.update(this, msg);
Logger rootLogger = Logger.getRootLogger();
FileAppender fa = (FileAppender) rootLogger.getAppender("FILE");
if (fa != null) {
logger.debug("Changing log file back to 'ripme.log'");
fa.setFile("ripme.log");
fa.activateOptions();
}
if (Utils.getConfigBoolean("urls_only.save", false)) {
String urlFile = this.workingDir + File.separator + "urls.txt";
try {
Desktop.getDesktop().open(new File(urlFile));
} catch (IOException e) {
logger.warn("Error while opening " + urlFile, e);
}
}
}
}
示例15: addFileAppender
import org.apache.log4j.FileAppender; //導入方法依賴的package包/類
private void addFileAppender(Logger rootLogger) {
FileAppender fa = new FileAppender();
fa.setName("FileLogger");
fa.setFile("rubus.log");
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);
}