當前位置: 首頁>>代碼示例>>Java>>正文


Java Logger.getLogger方法代碼示例

本文整理匯總了Java中org.apache.log4j.Logger.getLogger方法的典型用法代碼示例。如果您正苦於以下問題:Java Logger.getLogger方法的具體用法?Java Logger.getLogger怎麽用?Java Logger.getLogger使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.log4j.Logger的用法示例。


在下文中一共展示了Logger.getLogger方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: makeNewLoggerInstance

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
public Logger makeNewLoggerInstance(String name) {
    /**
     * The global default appender should only effect
     * the user visible loggers and not the private org.volt loggers
     */
    if (globalDefaultAppender == null) {
        return Logger.getLogger(name);
    } else {
        Logger l = Logger.getLogger(name);
        if(name.startsWith("org.voltdb")) {
            l.setLevel(Level.OFF);
        }
        return l;
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:17,代碼來源:VoltLoggerFactory.java

示例2: log

import org.apache.log4j.Logger; //導入方法依賴的package包/類
/**
 * Log an event, writing a line in the log file of the form
 * <pre>
 * DATE    EVENT_TYPE   PARAM_1   PARAM_2   ...
 * </pre>
 */
synchronized void log(String eventType, Object... params) {
  try {
    if (logDisabled)
      return;
    StringBuffer buffer = new StringBuffer();
    buffer.append(eventType);
    for (Object param: params) {
      buffer.append("\t");
      buffer.append(param);
    }
    String message = buffer.toString();
    Logger logger = Logger.getLogger(getClass());
    appender.append(new LoggingEvent("", logger, Level.INFO, message, null));
  } catch (Exception e) {
    LOG.error("Failed to append to fair scheduler event log", e);
    logDisabled = true;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:FairSchedulerEventLog.java

示例3: write

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Override
public void write(String loggerName, String filePrefix, String content) {
  RollingFileAppender logger = fileAppenders.computeIfAbsent(loggerName, f -> initLogger(loggerName, filePrefix));
  LoggingEvent event = new LoggingEvent(loggerName, Logger.getLogger(loggerName), Level.ALL,
      content, null);
  logger.append(event);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:8,代碼來源:Log4JMetricsFileWriter.java

示例4: initialize

import org.apache.log4j.Logger; //導入方法依賴的package包/類
private void initialize(String propsName)
throws Exception
{
    URL config = ClassLoader.getSystemResource(propsName);
    assertNotNull("was able to retrieve config", config);
    PropertyConfigurator.configure(config);

    logger = Logger.getLogger(getClass());

    Logger rootLogger = Logger.getRootLogger();
    appender = (TestableCloudWatchAppender)rootLogger.getAppender("default");

    appender.setThreadFactory(new InlineThreadFactory());
    appender.setWriterFactory(new MockCloudWatchWriterFactory(appender));
}
 
開發者ID:kdgregory,項目名稱:log4j-aws-appenders,代碼行數:16,代碼來源:TestCloudWatchAppender.java

示例5: BaseAction

import org.apache.log4j.Logger; //導入方法依賴的package包/類
/*******************************************************************/
@SuppressWarnings("unchecked")
public BaseAction() {
	try {
		ParameterizedType type = (ParameterizedType) this.getClass()
				.getGenericSuperclass();
		clazz = (Class<?>) type.getActualTypeArguments()[0];
		model = (T) clazz.newInstance();
		log = Logger.getLogger(clazz);
	} catch (Exception e) {
		log.error(e.getMessage());
	}
}
 
開發者ID:liuxuanhai,項目名稱:WeiXing_xmu-2016-MrCode,代碼行數:14,代碼來源:BaseAction.java

示例6: testDecommissionDeadDN

import org.apache.log4j.Logger; //導入方法依賴的package包/類
/**
 * Verify the support for decommissioning a datanode that is already dead.
 * Under this scenario the datanode should immediately be marked as
 * DECOMMISSIONED
 */
@Test(timeout=120000)
public void testDecommissionDeadDN() throws Exception {
  Logger log = Logger.getLogger(DecommissionManager.class);
  log.setLevel(Level.DEBUG);
  DatanodeID dnID = cluster.getDataNodes().get(0).getDatanodeId();
  String dnName = dnID.getXferAddr();
  DataNodeProperties stoppedDN = cluster.stopDataNode(0);
  DFSTestUtil.waitForDatanodeState(cluster, dnID.getDatanodeUuid(),
      false, 30000);
  FSNamesystem fsn = cluster.getNamesystem();
  final DatanodeManager dm = fsn.getBlockManager().getDatanodeManager();
  DatanodeDescriptor dnDescriptor = dm.getDatanode(dnID);
  decommissionNode(fsn, localFileSys, dnName);
  dm.refreshNodes(conf);
  BlockManagerTestUtil.recheckDecommissionState(dm);
  assertTrue(dnDescriptor.isDecommissioned());

  // Add the node back
  cluster.restartDataNode(stoppedDN, true);
  cluster.waitActive();

  // Call refreshNodes on FSNamesystem with empty exclude file to remove the
  // datanode from decommissioning list and make it available again.
  writeConfigFile(localFileSys, excludeFile, null);
  dm.refreshNodes(conf);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:32,代碼來源:TestDecommissioningStatus.java

示例7: testMultipleThreadsSingleAppender

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Test
public void testMultipleThreadsSingleAppender() throws Exception
{
    final String logGroupName   = "AppenderIntegrationTest-testMultipleThreadsSingleAppender";
    final int messagesPerThread = 200;
    final int rotationCount     = 333;

    setUp("CloudWatchAppenderIntegrationTest-testMultipleThreadsSingleAppender.properties", logGroupName);
    localLogger.info("multi-thread/single-appender: starting");

    Logger testLogger = Logger.getLogger("TestLogger");
    CloudWatchAppender appender = (CloudWatchAppender)testLogger.getAppender("test");

    MessageWriter[] writers = new MessageWriter[]
    {
        new MessageWriter(testLogger, messagesPerThread),
        new MessageWriter(testLogger, messagesPerThread),
        new MessageWriter(testLogger, messagesPerThread),
        new MessageWriter(testLogger, messagesPerThread),
        new MessageWriter(testLogger, messagesPerThread)
    };
    MessageWriter.runOnThreads(writers);

    localLogger.info("multi-thread/single-appender: all threads started; sleeping to give writer chance to run");
    Thread.sleep(3000);

    assertMessages(logGroupName, LOGSTREAM_BASE + "1", rotationCount);
    assertMessages(logGroupName, LOGSTREAM_BASE + "2", rotationCount);
    assertMessages(logGroupName, LOGSTREAM_BASE + "3", rotationCount);
    assertMessages(logGroupName, LOGSTREAM_BASE + "4", (messagesPerThread * writers.length) % rotationCount);

    assertEquals("client factory", "com.amazonaws.services.logs.AWSLogsClientBuilder.defaultClient", getWriter(appender).getClientFactoryUsed());

    localLogger.info("multi-thread/single-appender: finished");
}
 
開發者ID:kdgregory,項目名稱:log4j-aws-appenders,代碼行數:36,代碼來源:CloudWatchAppenderIntegrationTest.java

示例8: OnlineStudentSchedulingGenericUpdater

import org.apache.log4j.Logger; //導入方法依賴的package包/類
public OnlineStudentSchedulingGenericUpdater(RpcDispatcher dispatcher, OnlineStudentSchedulingContainerRemote container) {
	super();
	iDispatcher = dispatcher;
	iContainer = container;
	setDaemon(true);
	setName("Updater[generic]");
	iSleepTimeInSeconds = ApplicationProperty.OnlineSchedulingQueueLoadInterval.intValue(); 
	iLog = Logger.getLogger(OnlineStudentSchedulingGenericUpdater.class + ".updater[generic]"); 
}
 
開發者ID:Jenner4S,項目名稱:unitimes,代碼行數:10,代碼來源:OnlineStudentSchedulingGenericUpdater.java

示例9: setUpLogger

import org.apache.log4j.Logger; //導入方法依賴的package包/類
private Logger setUpLogger(DataSource dataSource, UserInfoProvider userInfoProvider, String name) {
    Logger logger = Logger.getLogger(name);
    DBAppender auditLogAppender = new DBAppender(dataSource, AUDIT_LOG_INSERT_STATEMENT, EVENT_ADAPTER, exceptionHandler,
        userInfoProvider);
    auditLogAppender.setName(name);
    logger.addAppender(auditLogAppender);
    return logger;
}
 
開發者ID:SAP,項目名稱:cf-mta-deploy-service,代碼行數:9,代碼來源:AuditLogManager.java

示例10: error

import org.apache.log4j.Logger; //導入方法依賴的package包/類
/**
 * Error 輸出
 * @param clazz  	目標.Class
 * @param message	輸出信息
 * @param e			異常類
 */
public static void error(Class<? extends Object> clazz ,String message,Exception e){
	Logger logger = Logger.getLogger(clazz);
	if(null == e){
		logger.error(message);
		return ;
	}
	logger.error(message, e);
}
 
開發者ID:butter-fly,項目名稱:belling-admin,代碼行數:15,代碼來源:LoggerUtils.java

示例11: testInvalidIpv6AddressInQuorum

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Test
public void testInvalidIpv6AddressInQuorum() throws Exception {
    assumeIPv6Available();

    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();

        String quorumCfgSection =
                "server.1=127.0.0.1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique()
                + "\nserver.2=[0:0:0:0:0:0:0:1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        q1.start();

        boolean isup =
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        30000);

        Assert.assertFalse("Server never came up", isup);

        q1.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*QuorumPeerConfig\\$ConfigException.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("complains about configuration", found);
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:59,代碼來源:QuorumPeerMainTest.java

示例12: testValidIpv6AddressInQuorum

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Test
public void testValidIpv6AddressInQuorum() throws Exception {
    assumeIPv6Available();

    ClientBase.setupTestEnv();

    // setup the logger to capture all logs
    Layout layout =
            Logger.getRootLogger().getAppender("CONSOLE").getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger qlogger = Logger.getLogger("org.apache.zookeeper.server.quorum");
    qlogger.addAppender(appender);

    try {
        final int CLIENT_PORT_QP1 = PortAssignment.unique();
        final int CLIENT_PORT_QP2 = PortAssignment.unique();

        String quorumCfgSection =
                "server.1=127.0.0.1:" + PortAssignment.unique()
                + ":" + PortAssignment.unique()
                + "\nserver.2=[0:0:0:0:0:0:0:1]:" + PortAssignment.unique()
                + ":" + PortAssignment.unique();

        MainThread q1 = new MainThread(1, CLIENT_PORT_QP1, quorumCfgSection);
        MainThread q2 = new MainThread(2, CLIENT_PORT_QP2, quorumCfgSection);

        q1.start();
        q2.start();

        Assert.assertTrue("waiting for server 1 being up",
                ClientBase.waitForServerUp("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        Assert.assertTrue("waiting for server 2 being up",
                ClientBase.waitForServerUp("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        q1.shutdown();
        q2.shutdown();

        Assert.assertTrue("waiting for server 1 down",
                ClientBase.waitForServerDown("127.0.0.1:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

        Assert.assertTrue("waiting for server 2 down",
                ClientBase.waitForServerDown("[0:0:0:0:0:0:0:1]:" + CLIENT_PORT_QP1,
                        ClientBase.CONNECTION_TIMEOUT));

    } finally {
        qlogger.removeAppender(appender);
    }

    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os.toString()));
    String line;
    boolean found = false;
    Pattern p =
            Pattern.compile(".*Resolved hostname: 0:0:0:0:0:0:0:1.*");
    while ((line = r.readLine()) != null) {
        found = p.matcher(line).matches();
        if (found) {
            break;
        }
    }
    Assert.assertTrue("IPv6 address resolved", found);
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:70,代碼來源:QuorumPeerMainTest.java

示例13: getLogger

import org.apache.log4j.Logger; //導入方法依賴的package包/類
protected Logger getLogger() {
    return Logger.getLogger(ServerAdminClient.class);
}
 
開發者ID:baloise,項目名稱:eZooKeeper,代碼行數:4,代碼來源:ZooKeeperServer.java

示例14: smoketestByName

import org.apache.log4j.Logger; //導入方法依賴的package包/類
@Test
public void smoketestByName() throws Exception
{
    setUp("SNSAppenderIntegrationTest-smoketestByName.properties");
    localLogger.info("smoketest: starting");

    createTopicAndQueue();

    final int numMessages = 11;

    Logger testLogger = Logger.getLogger("TestLogger");
    SNSAppender appender = (SNSAppender)testLogger.getAppender("test");

    (new MessageWriter(testLogger, numMessages)).run();

    localLogger.info("smoketest: reading messages");
    List<String> messages = retrieveMessages(numMessages);

    assertEquals("number of messages", numMessages, messages.size());
    assertMessageContent(messages, "Example");


    assertEquals("client factory called", "com.amazonaws.services.sns.AmazonSNSClientBuilder.defaultClient",
                                          getWriter(appender).getClientFactoryUsed());
}
 
開發者ID:kdgregory,項目名稱:log4j-aws-appenders,代碼行數:26,代碼來源:SNSAppenderIntegrationTest.java

示例15: testSeekForRwServer

import org.apache.log4j.Logger; //導入方法依賴的package包/類
/**
 * Ensures that client seeks for r/w servers while it's connected to r/o
 * server.
 */
@SuppressWarnings("deprecation")
@Test(timeout = 90000)
public void testSeekForRwServer() throws Exception {

    // setup the logger to capture all logs
    Layout layout = Logger.getRootLogger().getAppender("CONSOLE")
            .getLayout();
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    WriterAppender appender = new WriterAppender(layout, os);
    appender.setImmediateFlush(true);
    appender.setThreshold(Level.INFO);
    Logger zlogger = Logger.getLogger("org.apache.zookeeper");
    zlogger.addAppender(appender);

    try {
        qu.shutdown(2);
        CountdownWatcher watcher = new CountdownWatcher();
        ZooKeeper zk = new ZooKeeper(qu.getConnString(),
                CONNECTION_TIMEOUT, watcher, true);
        watcher.waitForConnected(CONNECTION_TIMEOUT);

        // if we don't suspend a peer it will rejoin a quorum
        qu.getPeer(1).peer.suspend();

        // start two servers to form a quorum; client should detect this and
        // connect to one of them
        watcher.reset();
        qu.start(2);
        qu.start(3);
        ClientBase.waitForServerUp(qu.getConnString(), 2000);
        watcher.waitForConnected(CONNECTION_TIMEOUT);
        zk.create("/test", "test".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE,
                CreateMode.PERSISTENT);

        // resume poor fellow
        qu.getPeer(1).peer.resume();
    } finally {
        zlogger.removeAppender(appender);
    }

    os.close();
    LineNumberReader r = new LineNumberReader(new StringReader(os
            .toString()));
    String line;
    Pattern p = Pattern.compile(".*Majority server found.*");
    boolean found = false;
    while ((line = r.readLine()) != null) {
        if (p.matcher(line).matches()) {
            found = true;
            break;
        }
    }
    Assert.assertTrue(
            "Majority server wasn't found while connected to r/o server",
            found);
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:61,代碼來源:ReadOnlyModeTest.java


注:本文中的org.apache.log4j.Logger.getLogger方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。