本文整理汇总了Java中org.apache.log4j.DailyRollingFileAppender类的典型用法代码示例。如果您正苦于以下问题:Java DailyRollingFileAppender类的具体用法?Java DailyRollingFileAppender怎么用?Java DailyRollingFileAppender使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DailyRollingFileAppender类属于org.apache.log4j包,在下文中一共展示了DailyRollingFileAppender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public static void setupLogger(Config config) throws IOException {
Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");
Appender appender = new DailyRollingFileAppender(
layout, config.getString("logger.file"), "'.'yyyyMMdd");
LogManager.resetConfiguration();
LogManager.getRootLogger().addAppender(new NullAppender());
logger = Logger.getLogger(LOGGER_NAME);
logger.addAppender(appender);
logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));
// Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
@Override
public InternalLogger newInstance(String string) {
return new NettyInternalLogger();
}
});
Log.logSystemInfo();
Log.info("Version: " + getAppVersion());
}
示例2: getLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
/**
*
* @param prop
* @param clazz
* @return
*/
public static Logger getLogger(Properties prop, Class<?> clazz) {
Logger LOG = Logger.getLogger(clazz);
String appName = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.APP_NAME);
String fileDir = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_DIR);
String patternLayout = PropertiesUtils.getRequiredProperty(prop,
PropertiesUtils.LOG_PATTERN);
String level = PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.LOG_LEVEL);
LOG.setLevel(Level.toLevel(level, Level.INFO));
DailyRollingFileAppender rollingAppender = new DailyRollingFileAppender();
rollingAppender.setFile(fileDir + "/" + appName + ".log");
rollingAppender.setLayout(new PatternLayout(patternLayout));
rollingAppender.setDatePattern("'.'yyyy-MM-dd");
rollingAppender.activateOptions();
LOG.addAppender(rollingAppender);
LOG.setAdditivity(false);
return LOG;
}
示例3: setLevel
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public void setLevel(DailyRollingFileAppender fa){
if (CmdLineParams.hasOptionTrace()) {
fa.setThreshold(Level.TRACE);
Logger.getRootLogger().setLevel(Level.TRACE);
} else if (CmdLineParams.hasOptionDebug()) {
fa.setThreshold(Level.DEBUG);
} else if (CmdLineParams.hasOptionInfo()) {
fa.setThreshold(Level.INFO);
} else if(CmdLineParams.hasOptionWarn()){
fa.setThreshold(Level.WARN);
}else if(CmdLineParams.hasOptionError()){
fa.setThreshold(Level.ERROR);
}else {
fa.setThreshold(Level.WARN);
}
}
示例4: configureLogging
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
/**
* Configures the logger.
*/
private static void configureLogging() {
PatternLayout layout = new PatternLayout("%d{yyyy-MM-dd' 'HH:mm:ss.SSS} [%-5p] [%c] - %m%n");
ConsoleAppender console = new ConsoleAppender();
console.setLayout(layout);
console.setThreshold(Level.INFO);
console.activateOptions();
DailyRollingFileAppender file = new DailyRollingFileAppender();
file.setFile("log/app.log");
file.setDatePattern("'.'yyyy-MM-dd");
file.setLayout(layout);
file.activateOptions();
org.apache.log4j.Logger logger = org.apache.log4j.Logger.getRootLogger();
logger.addAppender(console);
logger.addAppender(file);
}
示例5: init
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
boolean init(FairSchedulerConfiguration conf) {
try {
logDir = conf.getEventlogDir();
File logDirFile = new File(logDir);
if (!logDirFile.exists()) {
if (!logDirFile.mkdirs()) {
throw new IOException(
"Mkdirs failed to create " + logDirFile.toString());
}
}
String username = System.getProperty("user.name");
logFile = String.format("%s%shadoop-%s-fairscheduler.log",
logDir, File.separator, username);
logDisabled = false;
PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n");
appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd");
appender.activateOptions();
LOG.info("Initialized fair scheduler event log, logging to " + logFile);
} catch (IOException e) {
LOG.error(
"Failed to initialize fair scheduler event log. Disabling it.", e);
logDisabled = true;
}
return !(logDisabled);
}
示例6: init
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
void init() {
String rootLoggerDirectory = getRootLoggerDirectory();
if (rootLoggerDirectory == null) {
return;
}
String absolutePath = new File(rootLoggerDirectory, failedMessageFile).getAbsolutePath();
try {
DailyRollingFileAppender failedLogFilesAppender = new DailyRollingFileAppender(
new PatternLayout(PATTERN_SPEC_TIMESTAMP_MESSAGE_NEWLINE), absolutePath, DATE_PATTERN);
logger.addAppender(failedLogFilesAppender);
logger.setLevel(Level.ERROR);
logger.setAdditivity(false);
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: createRATSpecificLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的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 DailyRollingFileAppender) {
try {
// Creates new file appender
((DailyRollingFileAppender) appender).setFile(FileParameters.obrLogFolder() + logFile);
((DailyRollingFileAppender) appender).activateOptions();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return Logger.getLogger(clazz);
}
示例8: createOBSLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
/**
* This create log4j logger for OBS work flow 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
* @param logFile String containing name of log file.
* @return log4j Logger object
*/
@SuppressWarnings("unchecked")
public static Logger createOBSLogger(Class clazz) {
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 DailyRollingFileAppender) {
try {
// Creates new file appender
((DailyRollingFileAppender) appender).setFile(FileParameters.obsLogFolder() + OBS_LOG_FILE);
((DailyRollingFileAppender) appender).activateOptions();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return Logger.getLogger(clazz);
}
示例9: setupLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public static void setupLogger(Properties properties) throws IOException {
Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} %5p: %m%n");
Appender appender = new DailyRollingFileAppender(
layout, properties.getProperty("logger.file"), "'.'yyyyMMdd");
LogManager.resetConfiguration();
logger = Logger.getLogger(LOGGER_NAME);
logger.addAppender(appender);
logger.setLevel(Level.ALL);
// Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
@Override
public InternalLogger newInstance(String string) {
return new NettyInternalLogger();
}
});
}
示例10: getServerLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public static Logger getServerLogger() {
if (serverLogger == null) {
// Initialise le gestionnaire de logs
try {
DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
new PatternLayout("%-5p %d{HH:mm:ss} %m%n"),
Config.getServerLogFile(), "'.'yyyy-MM-dd");
serverLogger = Logger.getLogger("server");
serverLogger.addAppender(fileAppender);
serverLogger.setLevel(Level.toLevel(Config.getServerLogLevel()));
if (Config.isDebug()) {
ConsoleAppender consoleAppender = new ConsoleAppender(
new PatternLayout("%-5p %d{HH:mm:ss} %m [%C#%M, line %L]%n"));
serverLogger.addAppender(consoleAppender);
}
} catch (IOException e) {
System.err.println("Could not initialize server logging!");
e.printStackTrace();
}
serverLogger.info("Server logging initialized.");
}
return serverLogger;
}
示例11: getPremiumLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public static Logger getPremiumLogger() {
if (premiumLogger == null) {
// Initialise le gestionnaire de logs
try {
DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
new PatternLayout("%-5p %d{HH:mm:ss} %m%n"),
Config.getPremiumLogFile(), "'.'yyyy-MM-dd");
premiumLogger = Logger.getLogger("premium");
premiumLogger.addAppender(fileAppender);
premiumLogger.setLevel(Level.DEBUG);
if (Config.isDebug()) {
ConsoleAppender consoleAppender = new ConsoleAppender(
new PatternLayout("%-5p %d{HH:mm:ss} %m [%C#%M, line %L]%n"));
premiumLogger.addAppender(consoleAppender);
}
} catch (IOException e) {
System.err.println("Could not initialize premium transactions logging!");
e.printStackTrace();
}
premiumLogger.info("Premium transactions logging initialized.");
}
return premiumLogger;
}
示例12: getChatLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public static Logger getChatLogger() {
if (chatLogger == null) {
try {
DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
new PatternLayout("%d{HH:mm:ss} %m%n"),
Config.getChatLogFile(), "'.'yyyy-MM-dd");
chatLogger = Logger.getLogger("chat");
chatLogger.addAppender(fileAppender);
chatLogger.setLevel(Level.DEBUG);
// if (Config.isDebug()) {
// ConsoleAppender consoleAppender = new ConsoleAppender(
// new PatternLayout("%d{HH:mm:ss} %m%n"));
// chatLogger.addAppender(consoleAppender);
// }
} catch (IOException e) {
System.err.println("Could not initialize chat logging!");
e.printStackTrace();
}
}
return chatLogger;
}
示例13: getActionLogger
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
public static Logger getActionLogger() {
if (actionLogger == null) {
try {
DailyRollingFileAppender fileAppender = new DailyRollingFileAppender(
new PatternLayout("%d{HH:mm:ss} %m%n"),
Config.getActionLogFile(), "'.'yyyy-MM-dd");
actionLogger = Logger.getLogger("action");
actionLogger.addAppender(fileAppender);
actionLogger.setLevel(Level.DEBUG);
// if (Config.isDebug()) {
// ConsoleAppender consoleAppender = new ConsoleAppender(
// new PatternLayout("%d{HH:mm:ss} %m%n"));
// actionLogger.addAppender(consoleAppender);
// }
} catch (IOException e) {
System.err.println("Could not initialize action logging!");
e.printStackTrace();
}
}
return actionLogger;
}
示例14: SecureLog
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
/**
* Constructs a log which writes log entries to the given log file.
*
* @param title Identifies the log entries
* @param logfile Location of the log file
*/
public SecureLog(String title, String logfile) throws IOException {
defaultLog = new FileOutputStream(logfile);
logAppender = new DailyRollingFileAppender(defaultLayout, logfile, rotationInterval);
logAppender.setName(defaultLogName);
// Configure the logging options
//logRoot = new SecureCategory(title);
logRoot = (SecureCategory)SecureCategory.getLogger(title);
logRoot.addAppender(logAppender);
setLogLevel(DEBUG);
logEntry(this, DEBUG,
"Constructing " + title + " log. Initial log level is DEBUG. " +
"Output will be sent to: " + logfile);
}
示例15: init
import org.apache.log4j.DailyRollingFileAppender; //导入依赖的package包/类
boolean init(FairSchedulerConfiguration conf) {
if (conf.isEventLogEnabled()) {
try {
logDir = conf.getEventlogDir();
File logDirFile = new File(logDir);
if (!logDirFile.exists()) {
if (!logDirFile.mkdirs()) {
throw new IOException(
"Mkdirs failed to create " + logDirFile.toString());
}
}
String username = System.getProperty("user.name");
logFile = String.format("%s%shadoop-%s-fairscheduler.log",
logDir, File.separator, username);
logDisabled = false;
PatternLayout layout = new PatternLayout("%d{ISO8601}\t%m%n");
appender = new DailyRollingFileAppender(layout, logFile, "'.'yyyy-MM-dd");
appender.activateOptions();
LOG.info("Initialized fair scheduler event log, logging to " + logFile);
} catch (IOException e) {
LOG.error(
"Failed to initialize fair scheduler event log. Disabling it.", e);
logDisabled = true;
}
} else {
logDisabled = true;
}
return !(logDisabled);
}