當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。