本文整理汇总了Java中org.apache.log4j.RollingFileAppender类的典型用法代码示例。如果您正苦于以下问题:Java RollingFileAppender类的具体用法?Java RollingFileAppender怎么用?Java RollingFileAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RollingFileAppender类属于org.apache.log4j包,在下文中一共展示了RollingFileAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
private RollingFileAppender initLogger(String loggerName, String filePrefix) {
String fileName = Paths.get(rootPath, filePrefix + "." + loggerName + ".dat").toString();
RollingFileAppender fileAppender = new RollingFileAppender();
fileAppender.setName(loggerName);
fileAppender.setFile(fileName);
fileAppender.setLayout(new PatternLayout("%m%n"));
fileAppender.setAppend(true);
fileAppender.setMaxFileSize(maxFileSize);
fileAppender.setMaxBackupIndex(maxFileCount);
fileAppender.activateOptions();
return fileAppender;
}
示例2: initLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
private static void initLogger() {
Logger rootLogger = Logger.getRootLogger();
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
try {
RollingFileAppender fileAppender = new RollingFileAppender(layout, System.getProperty("log.file", "./vnt.log"));
fileAppender.setImmediateFlush(true);
fileAppender.setThreshold(Level.DEBUG);
fileAppender.setAppend(true);
fileAppender.setMaxFileSize("5MB");
fileAppender.setMaxBackupIndex(2);
rootLogger.addAppender(fileAppender);
} catch (IOException e) {
log.error("Failed to add appender !!", e);
}
}
示例3: configureAuditLogs
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
private void configureAuditLogs() throws IOException {
// Shutdown the LogManager to release all logger open file handles.
// Unfortunately, Apache commons logging library does not provide
// means to release underlying loggers. For additional info look up
// commons library FAQ.
LogManager.shutdown();
File file = new File(auditLogFile);
if (file.exists()) {
assertTrue(file.delete());
}
Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
// disable logging while the cluster startup preps files
logger.setLevel(Level.OFF);
PatternLayout layout = new PatternLayout("%m%n");
RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
logger.addAppender(appender);
}
示例4: configureLoggers
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
/**
* Configures rolling file loggers.
*
* @param filename the filename to output logging to.
* @param loggers the logger names.
*/
private void configureLoggers( String filename, List<String> loggers )
{
String file = getLogFile( filename );
RollingFileAppender appender = getRollingFileAppender( file );
for ( String loggerName : loggers )
{
Logger logger = Logger.getRootLogger().getLoggerRepository().getLogger( loggerName );
logger.addAppender( appender );
log.info( "Added logger: " + loggerName + " using file: " + file );
}
}
示例5: tieSystemOutAndErrToLog
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
@SuppressWarnings("UseOfSystemOutOrSystemErr")
public static void tieSystemOutAndErrToLog()
{
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
Appender appender = rootLogger.getAppender(DT_LOG_APPENDER);
if (appender instanceof RollingFileAppender) {
RollingFileAppender rfa = (RollingFileAppender)appender;
if (rfa.getFile() == null || rfa.getFile().isEmpty()) {
rfa.setFile(System.getProperty(DT_LOGDIR));
rfa.activateOptions();
}
} else if (appender != null) {
logger.warn("found appender {} instead of RollingFileAppender", appender);
}
LoggerUtil.addAppenders();
System.setOut(createLoggingProxy(System.out));
System.setErr(createLoggingProxy(System.err));
}
示例6: setupAuditLogs
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
/** Sets up log4j logger for auditlogs */
private void setupAuditLogs() throws IOException {
// Shutdown the LogManager to release all logger open file handles.
// Unfortunately, Apache commons logging library does not provide
// means to release underlying loggers. For additional info look up
// commons library FAQ.
LogManager.shutdown();
File file = new File(auditLogFile);
if (file.exists()) {
assertTrue(file.delete());
}
Logger logger = ((Log4JLogger) FSNamesystem.auditLog).getLogger();
logger.setLevel(Level.INFO);
PatternLayout layout = new PatternLayout("%m%n");
RollingFileAppender appender = new RollingFileAppender(layout, auditLogFile);
logger.addAppender(appender);
}
示例7: testRolloverLogfile
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
@Test
public void testRolloverLogfile() throws Exception {
Log4jUtils.rolloverLogfile();
// add appender to cover more
Logger.getLogger("somelogger");
Logger.getRootLogger().addAppender(new ConsoleAppender());
final RollingFileAppender rollingFileAppender = new RollingFileAppender();
File file = File.createTempFile("log4j", ".log");
rollingFileAppender.setFile(file.getAbsolutePath());
Logger.getRootLogger().addAppender(rollingFileAppender);
Log4jUtils.rolloverLogfile();
file.deleteOnExit();
new File(file.getAbsoluteFile() + ".1").deleteOnExit();
}
示例8: CreateRollingFileAppender
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
/**
* Create File appender, This appender is responsible to write stream of data when invoked, in our case, this appender is handeled my the Bufferappender
*
* @param cacheName Name of the file appender
* @param fileName Filename to which is to write logs
* @return returns the created appender
*/
private Appender CreateRollingFileAppender(String fileName)
{
RollingFileAppender appender = new RollingFileAppender();
appender.setName("RollingFileAppender" + _loggerName);
appender.setFile(fileName);
//doesnt matter since all files are created with a new name
appender.setAppend(false);
appender.setMaxBackupIndex(Integer.MAX_VALUE);
appender.setMaxFileSize("5MB");
String str = "%-27d{ISO8601}" /*+ "\t%-45.42appdomain" + "\t%-45.42l"*/ + "\t%-42t" + "\t%-9p" + "\t%m" + "%n";
appender.setThreshold(Level.ALL);
return appender;
}
示例9: createRATSpecificLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
/**
* This create log4j logger for resource access tool using root logger.
* It adds file appender with specified filename to the logger which creates separate
* log file for each resource access tool.
*
* @param clazz Class object for Resource Access Tool
* @param logFile String containing name of log file.
* @return log4j Logger object
*/
@SuppressWarnings("unchecked")
public static Logger createRATSpecificLogger(Class clazz, String logFile) {
Enumeration<Appender> appenders = Logger.getRootLogger()
.getAllAppenders();
// Add all appenders of root logger
while (appenders.hasMoreElements()) {
Appender appender = appenders.nextElement();
// For file appender create new appender with different log file
if (appender instanceof RollingFileAppender) {
try {
// Creates new file appender
((RollingFileAppender) appender).setFile(FileResourceParameters.resourceLogFolder() + logFile);
((RollingFileAppender) appender).activateOptions();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return Logger.getLogger(clazz);
}
示例10: initLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
private static void initLogger() {
// This is the root logger provided by log4j
Logger rootLogger = Logger.getRootLogger();
// Define log pattern layout
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n");
try {
// Define file appender with layout and output log file name
RollingFileAppender fileAppender = new RollingFileAppender(layout, "./scplayer.log");
fileAppender.setImmediateFlush(true);
fileAppender.setThreshold(Level.DEBUG);
fileAppender.setAppend(true);
fileAppender.setMaxFileSize("5MB");
fileAppender.setMaxBackupIndex(2);
// Add the appender to root logger
rootLogger.addAppender(fileAppender);
} catch (IOException e) {
System.out.println("Failed to add appender !!");
System.exit(-1);
}
}
示例11: internalInit
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
/**
* initializes the log system using the logfile argument
*/
private void internalInit( String logfile )
throws Exception
{
/*
* do it by our classname to avoid conflicting with anything else
* that might be used...
*/
logger = Category.getInstance(this.getClass().getName());
logger.setAdditivity(false);
/*
* Priority is set for DEBUG becouse this implementation checks
* log level.
*/
logger.setPriority(Priority.DEBUG);
RollingFileAppender appender = new RollingFileAppender( new PatternLayout( "%d - %m%n"), logfile, true);
appender.setMaxBackupIndex( 1 );
appender.setMaximumFileSize( 100000 );
logger.addAppender(appender);
}
示例12: createLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
private void createLogger() {
// Create logger
synchronized (logCreatorLock) {
String loggerName = System.currentTimeMillis() + "." + this.executionId + "." + this.jobId;
logger = Logger.getLogger(loggerName);
// Create file appender
String logName = createLogFileName(node);
logFile = new File(workingDir, logName);
String absolutePath = logFile.getAbsolutePath();
jobAppender = null;
try {
RollingFileAppender fileAppender = new RollingFileAppender(loggerLayout, absolutePath, true);
fileAppender.setMaxBackupIndex(jobLogBackupIndex);
fileAppender.setMaxFileSize(jobLogChunkSize);
jobAppender = fileAppender;
logger.addAppender(jobAppender);
logger.setAdditivity(false);
}
catch (IOException e) {
flowLogger.error("Could not open log file in " + workingDir + " for job " + this.jobId, e);
}
}
}
示例13: createFileLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
public void createFileLogger(String file) throws IOException {
//----
ConsoleAppender console = new ConsoleAppender();
String PATTERN = "%m%n";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.INFO);
console.activateOptions();
Logger.getRootLogger().getLoggerRepository().resetConfiguration();
Logger.getRootLogger().removeAllAppenders();
Logger.getRootLogger().addAppender(console);
//----
org.apache.log4j.RollingFileAppender rfa =
new RollingFileAppender(new org.apache.log4j.PatternLayout(),file);
Logger.getRootLogger().addAppender(rfa);
}
示例14: createCustomFileLogger
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
public Logger createCustomFileLogger(String file) throws IOException {
//----
ConsoleAppender console = new ConsoleAppender();
String PATTERN = "%m%n-%c: ";
console.setLayout(new PatternLayout(PATTERN));
console.setThreshold(Level.INFO);
console.activateOptions();
Logger log = Logger.getLogger(Thread.currentThread().getName());
log.getLoggerRepository().resetConfiguration();
log.removeAllAppenders();
log.addAppender(console);
//----
org.apache.log4j.RollingFileAppender rfa =
new RollingFileAppender(new org.apache.log4j.PatternLayout(PATTERN),file);
log.addAppender(rfa);
rfa.setImmediateFlush(true);
return log;
}
示例15: setup
import org.apache.log4j.RollingFileAppender; //导入依赖的package包/类
public static void setup(Level level, String logLocation) {
if (logLocation != null) {
RollingFileAppender fa = new RollingFileAppender();
fa.setName("FileLogger");
fa.setFile(logLocation);
fa.setMaxFileSize("5MB");
fa.setMaxBackupIndex(1);
fa.setLayout(new PatternLayout("%d | %-5p| %c{1} | %m%n"));
fa.setThreshold(level);
fa.setAppend(true);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
LOGGER.info("File Handler set");
} else {
System.out.println("Log location is not set, not logging to file");
}
}