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


Java DailyRollingFileAppender.activateOptions方法代码示例

本文整理汇总了Java中org.apache.log4j.DailyRollingFileAppender.activateOptions方法的典型用法代码示例。如果您正苦于以下问题:Java DailyRollingFileAppender.activateOptions方法的具体用法?Java DailyRollingFileAppender.activateOptions怎么用?Java DailyRollingFileAppender.activateOptions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.DailyRollingFileAppender的用法示例。


在下文中一共展示了DailyRollingFileAppender.activateOptions方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:26,代码来源:FairSchedulerEventLog.java

示例4: 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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:FairSchedulerEventLog.java

示例5: 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

示例6: init

import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
boolean init(Configuration conf, String jobtrackerHostname) {
  try {
    logDir = conf.get("mapred.fairscheduler.eventlog.location",
        new File(System.getProperty("hadoop.log.dir")).getAbsolutePath()
        + File.separator + "fairscheduler");
    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-%s.log",
        logDir, File.separator, username, jobtrackerHostname);
    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);
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:28,代码来源:FairSchedulerEventLog.java

示例7: 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

示例8: 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

示例9: createOBRLogger

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 createOBRLogger(Class clazz) {

    Logger logger = Logger.getLogger(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 newFileAppender = new DailyRollingFileAppender(
                        appender.getLayout(), FileParameters.obrLogFolder() + OBR_LOG_FILE,
                        ((DailyRollingFileAppender) appender)
                                .getDatePattern());
                newFileAppender.activateOptions();

                logger.addAppender(newFileAppender);

            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            logger.addAppender(appender);
        }
    }

    logger.setAdditivity(false);

    return logger;

}
 
开发者ID:ncbo,项目名称:resource_access_tools,代码行数:46,代码来源:LoggerUtils.java

示例10: 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

示例11: init

import org.apache.log4j.DailyRollingFileAppender; //导入方法依赖的package包/类
boolean init(Configuration conf, String jobtrackerHostname) {
  try {
    logDir = conf.get("mapred.fairscheduler.eventlog.location",
        new File(System.getProperty("hadoop.log.dir")).getAbsolutePath()
        + File.separator + "fairscheduler");
    Path logDirPath = new Path(logDir);
    FileSystem fs = logDirPath.getFileSystem(conf);
    if (!fs.exists(logDirPath)) {
      if (!fs.mkdirs(logDirPath)) {
        throw new IOException(
            "Mkdirs failed to create " + logDirPath.toString());
      }
    }
    String username = System.getProperty("user.name");
    logFile = String.format("%s%shadoop-%s-fairscheduler-%s.log",
        logDir, File.separator, username, jobtrackerHostname);
    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);
}
 
开发者ID:Seagate,项目名称:hadoop-on-lustre,代码行数:29,代码来源:FairSchedulerEventLog.java

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