当前位置: 首页>>代码示例>>Java>>正文


Java DailyRollingFileAppender.setFile方法代码示例

本文整理汇总了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;
}
 
开发者ID:sap-nocops,项目名称:Jerkoff,代码行数:24,代码来源:LogUtils.java

示例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);
}
 
开发者ID:jpdillingham,项目名称:SeedboxSync,代码行数:22,代码来源:SeedboxSync.java

示例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);
}
 
开发者ID:DTStack,项目名称:jlogstash,代码行数:13,代码来源:Log4jComponent.java

示例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;
}
 
开发者ID:Heapy,项目名称:Heap,代码行数:10,代码来源:LoggingInitializer.java

示例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;
}
 
开发者ID:loye168,项目名称:tddl5,代码行数:11,代码来源:DynamicLog4jLogger.java

示例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;
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:14,代码来源:SystemLog.java

示例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;
	
}
 
开发者ID:keensoft,项目名称:icearchiva,代码行数:57,代码来源:Log4JMultiTenancyLoggerResolver.java


注:本文中的org.apache.log4j.DailyRollingFileAppender.setFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。