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


Java LogManager类代码示例

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


LogManager类属于org.apache.log4j包,在下文中一共展示了LogManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 *  Loads the test-specific Log4J configuration and resets the environment.
 */
public void setUp(String propertiesName)
throws Exception
{
    URL config = ClassLoader.getSystemResource(propertiesName);
    assertNotNull("missing configuration: " + propertiesName, config);

    LogManager.resetConfiguration();
    PropertyConfigurator.configure(config);

    localLogger = Logger.getLogger(getClass());

    runId = String.valueOf(System.currentTimeMillis());
    resourceName = "SNSAppenderIntegrationTest-" + runId;
    System.setProperty("SNSAppenderIntegrationTest.resourceName", resourceName);

    localSNSclient = AmazonSNSClientBuilder.defaultClient();
    localSQSclient = AmazonSQSClientBuilder.defaultClient();
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:22,代码来源:SNSAppenderIntegrationTest.java

示例2: Log4jLoggerAdapter

import org.apache.log4j.LogManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public Log4jLoggerAdapter() {
	try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
           if (logger != null) {
               Enumeration<Appender> appenders = logger.getAllAppenders();
               if (appenders != null) {
                   while (appenders.hasMoreElements()) {
                       Appender appender = appenders.nextElement();
                       if (appender instanceof FileAppender) {
                           FileAppender fileAppender = (FileAppender)appender;
                           String filename = fileAppender.getFile();
                           file = new File(filename);
                           break;
                       }
                   }
               }
           }
       } catch (Throwable t) {
       }
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:22,代码来源:Log4jLoggerAdapter.java

示例3: configureLogger

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 * Configures root logger, either for FILE output or just console.
 */
public static void configureLogger() {
    LogManager.shutdown();
    String logFile;
    if (getConfigBoolean("log.save", false)) {
        logFile = "log4j.file.properties";
    }
    else {
        logFile = "log4j.properties";
    }
    InputStream stream = Utils.class.getClassLoader().getResourceAsStream(logFile);
    if (stream == null) {
        PropertyConfigurator.configure("src/main/resources/" + logFile);
    } else {
        PropertyConfigurator.configure(stream);
    }
    logger.info("Loaded " + logFile);
    try {
        stream.close();
    } catch (IOException e) { }
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:24,代码来源:Utils.java

示例4: handleOnChange

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 * On change event
 */
void handleOnChange(File logFile) {
    try {
        long lastModif = logFile.lastModified();
        if (lastModif > logFileLastModified) {
            logFileLastModified = lastModif;
            logger.debug("Reload log4j configuration from "
                    + logFile.getAbsolutePath());
            new PropertyConfigurator().doConfigure(
                    logFile.getAbsolutePath(),
                    LogManager.getLoggerRepository());
            logFileWarning = false;
        }
    } catch (Exception e) {
        if (!logFileWarning) {
            logFileWarning = true;
            logger.error(logFile.getAbsolutePath(), e);
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:Initializer.java

示例5: testSlowness

import org.apache.log4j.LogManager; //导入依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testSlowness() throws Throwable {
  ch = new SlowMemoryChannel(2000);
  Configurables.configure(ch, new Context());
  configureSource();
  props.put("log4j.appender.out2.Timeout", "1000");
  props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
  props.put("log4j.appender.out2.layout.ConversionPattern",
      "%-5p [%t]: %m%n");
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  Thread.currentThread().setName("Log4jAppenderTest");
  int level = 10000;
  String msg = "This is log message number" + String.valueOf(1);
  try {
    logger.log(Level.toLevel(level), msg);
  } catch (FlumeException ex) {
    throw ex.getCause();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestLog4jAppender.java

示例6: initLog

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 * Initializes Log4j logging.
 *
 * @throws ServerException thrown if Log4j could not be initialized.
 */
protected void initLog() throws ServerException {
  verifyDir(logDir);
  LogManager.resetConfiguration();
  File log4jFile = new File(configDir, name + "-log4j.properties");
  if (log4jFile.exists()) {
    PropertyConfigurator.configureAndWatch(log4jFile.toString(), 10 * 1000); //every 10 secs
    log = LoggerFactory.getLogger(Server.class);
  } else {
    Properties props = new Properties();
    try {
      InputStream is = getResource(DEFAULT_LOG4J_PROPERTIES);
      try {
        props.load(is);
      } finally {
        is.close();
      }
    } catch (IOException ex) {
      throw new ServerException(ServerException.ERROR.S03, DEFAULT_LOG4J_PROPERTIES, ex.getMessage(), ex);
    }
    PropertyConfigurator.configure(props);
    log = LoggerFactory.getLogger(Server.class);
    log.warn("Log4j [{}] configuration file not found, using default configuration from classpath", log4jFile);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:Server.java

示例7: setup

import org.apache.log4j.LogManager; //导入依赖的package包/类
@Before
public void setup() {
    initMocks(this);

    lifeCycleListener.setServerId("1");
    lifeCycleListener.setServerName("testJvm");
    lifeCycleListener.setJgroupsPreferIpv4Stack("true");
    lifeCycleListener.setJgroupsConfigXml("tcp.xml");
    lifeCycleListener.setJgroupsCoordinatorIp(prop.getProperty("coordinator.ip"));
    lifeCycleListener.setJgroupsCoordinatorHostname("testHostname");
    lifeCycleListener.setJgroupsCoordinatorPort("30000");
    lifeCycleListener.setJgroupsClusterName("testCluster");
    lifeCycleListener.setSchedulerDelayInitial("1");
    lifeCycleListener.setSchedulerDelaySubsequent("1");
    lifeCycleListener.setSchedulerDelayUnit("SECONDS");
    lifeCycleListener.setSchedulerThreadCount("1");

    LogManager.getRootLogger().addAppender(mockAppender);
}
 
开发者ID:cerner,项目名称:jwala,代码行数:20,代码来源:JGroupsReportingLifeCycleListenerImplTest.java

示例8: testRunWithLevelDebug

import org.apache.log4j.LogManager; //导入依赖的package包/类
@Test(timeout = 10000)
public void testRunWithLevelDebug() {
  // remember current level
  Level originalLevel = LogManager.getRootLogger().getLevel();
  try {
    // set logging to TRACE
    LogManager.getRootLogger().setLevel(Level.DEBUG);

    // execute run method
    testRun();

  } finally {
    // restore level
    LogManager.getRootLogger().setLevel(originalLevel);
  }
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:17,代码来源:PublicationObserverTest.java

示例9: testRunWithLevelTrace

import org.apache.log4j.LogManager; //导入依赖的package包/类
@Test(timeout = 10000)
public void testRunWithLevelTrace() {
  // remember current level
  Level originalLevel = LogManager.getRootLogger().getLevel();
  try {
    // set logging to TRACE
    LogManager.getRootLogger().setLevel(Level.TRACE);

    // execute run method
    testRun();

  } finally {
    // restore level
    LogManager.getRootLogger().setLevel(originalLevel);
  }
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:17,代码来源:PublicationObserverTest.java

示例10: configureAuditLogs

import org.apache.log4j.LogManager; //导入依赖的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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestAuditLogs.java

示例11: LogPageHandler

import org.apache.log4j.LogManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public LogPageHandler() {
    try {
		org.apache.log4j.Logger logger = LogManager.getRootLogger();
        if (logger != null) {
            Enumeration<Appender> appenders = logger.getAllAppenders();
            if (appenders != null) {
                while (appenders.hasMoreElements()) {
                    Appender appender = appenders.nextElement();
                    if (appender instanceof FileAppender) {
                        FileAppender fileAppender = (FileAppender)appender;
                        String filename = fileAppender.getFile();
                        file = new File(filename);
                        break;
                    }
                }
            }
        }
    } catch (Throwable t) {
    }
   }
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:22,代码来源:LogPageHandler.java

示例12: main

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 * @param args Command line args
 */
public static void main(String[] args) {
  boolean result = false;
  try {
    ApplicationMaster appMaster = new ApplicationMaster();
    LOG.info("Initializing ApplicationMaster");
    boolean doRun = appMaster.init(args);
    if (!doRun) {
      System.exit(0);
    }
    appMaster.run();
    result = appMaster.finish();
  } catch (Throwable t) {
    LOG.fatal("Error running ApplicationMaster", t);
    LogManager.shutdown();
    ExitUtil.terminate(1, t);
  }
  if (result) {
    LOG.info("Application Master completed successfully. exiting");
    System.exit(0);
  } else {
    LOG.info("Application Master failed. exiting");
    System.exit(2);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:28,代码来源:ApplicationMaster.java

示例13: setUp

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 *  Loads the test-specific Log4J configuration and resets the environment.
 */
public void setUp(String propertiesName, String streamName) throws Exception
{
    URL config = ClassLoader.getSystemResource(propertiesName);
    assertNotNull("missing configuration: " + propertiesName, config);

    LogManager.resetConfiguration();
    PropertyConfigurator.configure(config);

    localLogger = Logger.getLogger(getClass());

    localClient = AmazonKinesisClientBuilder.defaultClient();

    deleteStreamIfExists(streamName);
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:18,代码来源:KinesisAppenderIntegrationTest.java

示例14: log

import org.apache.log4j.LogManager; //导入依赖的package包/类
private void log(LogMessage logMessage, LogLevel level, String loggerName) {
	String logMessageString;
	if (config.getLogInPlainString()) {
		StringBuilder sb = new StringBuilder();
		sb.append("[CID: ").append(logMessage.getCorrelationId());
		if (StringUtils.isNotBlank(logMessage.getCorrelationIdLocal())) {
			sb.append(" CID.Local: ").append(logMessage.getCorrelationIdLocal());
		}
		sb.append("] ").append(logMessage.getMessage());
		String varsInString = LogHelper.variablesToString(logMessage.getVariables(), config.getLogVariableType());
		if (varsInString.length() > 0) {
			sb.append(" [").append(varsInString).append("]");
		}
		if (logMessage.getThrowable() != null) {
			Throwable t = logMessage.getThrowable();
			sb.append("\nException: ").append(ExceptionUtils.getMessage(t)).append(" ")
					.append(ExceptionUtils.getStackTrace(logMessage.getThrowable()));
			sb.append("");
		}
		logMessageString = sb.toString();
	} else {
		TimeZone tz = TimeZone.getTimeZone("UTC");
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		df.setTimeZone(tz);
		logMessage.setTimestamp(df.format(new Date()));
		logMessage.setLevel(level.toString());
		logMessage.setLogger(loggerName);
		logMessage.setThread(Thread.currentThread().toString());
		Gson gson = new GsonBuilder().disableHtmlEscaping().disableHtmlEscaping().create();
		logMessageString = gson.toJson(logMessage);
	}

	Logger logger = LogManager.getLogger(loggerName);
	switch (level) {
	case INFO:
		logger.info(logMessageString);
		break;
	case ERROR:
		logger.error(logMessageString);
		break;
	case FATAL:
		logger.fatal(logMessageString);
		break;
	case DEBUG:
		logger.debug(logMessageString);
		break;
	}
}
 
开发者ID:iac-m,项目名称:mule-json-logger,代码行数:49,代码来源:JsonLogger.java

示例15: handleOnChange

import org.apache.log4j.LogManager; //导入依赖的package包/类
/**
 * On change event
 */
void handleOnChange(File logFile) {
	try {
		long lastModif = logFile.lastModified();
		if (lastModif > logFileLastModified) {
			logFileLastModified = lastModif;
			LOGGER.debug("Reload log4j configuration from " + logFile.getAbsolutePath());
			new PropertyConfigurator().doConfigure(logFile.getAbsolutePath(), LogManager.getLoggerRepository());
			logFileWarning = false;
		}
	} catch (Exception e) {
		if (!logFileWarning) {
			logFileWarning = true;
			LOGGER.error(logFile.getAbsolutePath(), e);
		}
	}
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:Initializer.java


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