本文整理汇总了Java中org.apache.log4j.DailyRollingFileAppender.setFile方法的典型用法代码示例。如果您正苦于以下问题:Java DailyRollingFileAppender.setFile方法的具体用法?Java DailyRollingFileAppender.setFile怎么用?Java DailyRollingFileAppender.setFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.DailyRollingFileAppender
的用法示例。
在下文中一共展示了DailyRollingFileAppender.setFile方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: setupLogger
import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
@Override
public void setupLogger() {
String file =checkFile();
DailyRollingFileAppender fa = new DailyRollingFileAppender();
fa.setName("FileLogger");
fa.setFile(file);
fa.setLayout(new PatternLayout(pattern));
setLevel(fa);
fa.setAppend(true);
fa.activateOptions();
Logger.getRootLogger().addAppender(fa);
}
示例4: getFileAppender
import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
private Appender getFileAppender(Level level, String pattern, String file) {
DailyRollingFileAppender appender = new DailyRollingFileAppender();
appender.setFile(file);
appender.setLayout(new PatternLayout(pattern));
appender.setThreshold(level);
appender.setAppend(true);
appender.activateOptions();
return appender;
}
示例5: buildAppender
import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
private Appender buildAppender(String name, String fileName, String pattern) {
DailyRollingFileAppender appender = new DailyRollingFileAppender();
appender.setName(name);
appender.setAppend(true);
appender.setEncoding(getEncoding());
appender.setLayout(new PatternLayout(pattern));
appender.setFile(new File(getLogPath(), fileName).getAbsolutePath());
appender.activateOptions();// 很重要,否则原有日志内容会被清空
return appender;
}
示例6: createAppender
import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
public static Appender createAppender(Path logdir, String name, Layout layout) {
final DailyRollingFileAppender dst = new DailyRollingFileAppender();
dst.setName(name);
dst.setLayout(layout);
dst.setEncoding(UTF_8.name());
dst.setFile(resolve(logdir).resolve(name).toString());
dst.setImmediateFlush(true);
dst.setAppend(true);
dst.setErrorHandler(new DieErrorHandler());
dst.activateOptions();
dst.setErrorHandler(new OnlyOnceErrorHandler());
return dst;
}
示例7: resolveCurrentTenantLogger
import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
@Override
public Logger resolveCurrentTenantLogger() {
if (currentLoggers.containsKey(multiTenantContextResolver.resolveCurrentTenantIdentifier())) {
return currentLoggers.get(multiTenantContextResolver.resolveCurrentTenantIdentifier());
}
try {
Class<?> appenderClass = Class.forName(appender);
Appender appenderObject = (Appender)appenderClass.newInstance();
if (appenderObject instanceof DailyRollingFileAppender) {
DailyRollingFileAppender drfa = new DailyRollingFileAppender();
if (!rootPath.endsWith("/")) rootPath = rootPath + "/";
String logFileName = rootPath + multiTenantContextResolver.resolveCurrentTenantIdentifier();
File logFile = new File(logFileName);
if (!logFile.exists()) logFile.mkdir();
drfa.setFile(logFileName + "/audit.log");
drfa.setDatePattern(datePattern);
PatternLayout layoutObject = null;
try {
layoutObject = (PatternLayout) Class.forName(layout).newInstance();
} catch (ClassCastException cce) {
throw new Exception(layout + " log4j layout not supported!");
}
layoutObject.setConversionPattern(layoutConversionPattern);
drfa.setLayout(layoutObject);
drfa.setAppend(true);
drfa.setName(prefix + "." + multiTenantContextResolver.resolveCurrentTenantIdentifier());
drfa.setThreshold(Level.toLevel(threshold));
drfa.activateOptions();
org.apache.log4j.Logger myLogger = org.apache.log4j.LogManager.getLogger(prefix + "." + multiTenantContextResolver.resolveCurrentTenantIdentifier());
myLogger.addAppender(drfa);
Logger logger = new Log4jLoggerAdapter(myLogger);
currentLoggers.put(multiTenantContextResolver.resolveCurrentTenantIdentifier(), logger);
return logger;
} else {
throw new Exception(appenderClass.getName() + " log4j appender not supported!");
}
} catch (Exception e) {
log.warn("Multitenant logger not initialized for " + prefix + "." + multiTenantContextResolver.resolveCurrentTenantIdentifier(), e);
}
return null;
}