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


Java Logger.setLevel方法代碼示例

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


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

示例1: loggerajax

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
public Response loggerajax(Request request) {
    Map<String, Object> body = request.getBodyAsJsonMap();
    if (body != null && body.size() > 0) {
        String clazz = body.get("class").toString();
        String level = body.get("level").toString();
        if (StringUtils.isNotBlank(clazz) && StringUtils.isNotBlank(level)) {
            LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
            for (Logger logger : loggerContext.getLoggers()) { //NOSONAR
                if (clazz.equals(logger.getName())) {
                    logger.setLevel(Level.getLevel(level));
                    break;
                }
            }
        }
    }
    
    return Response.withOk().andEmptyBody();
}
 
開發者ID:svenkubiak,項目名稱:mangooio,代碼行數:19,代碼來源:AdminController.java

示例2: preInit

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Mod.EventHandler
   public void preInit(FMLPreInitializationEvent event)
   {
       // logging stuff.
       if (!FMLForgePlugin.RUNTIME_DEOBF) // not runtime deobf = dev env
       {
           String packageName = this.getClass().getPackage().getName();
           Logger baseLogger = (Logger) LogManager.getLogger(packageName);
           ConsoleAppender appender = ConsoleAppender.createAppender(null, null, Target.SYSTEM_OUT.toString(), "console", "true", "false");
           baseLogger.addAppender(appender);
           baseLogger.setLevel(Level.DEBUG);
           appender.start();

           // testing levels..
           for (Level l : Level.values())
           {
               baseLogger.log(l, "TESTING {} on level {}", baseLogger.getName(), l);
               LogManager.getLogger().log(l, "TESTING {} on level {}", this.getClass().getName(), l);
           }
       }

	Configuration c = new Configuration(event.getSuggestedConfigurationFile());
	OUR_SERVER = c.get("main", "globalbloodstain", 1, "Turn on global bloodstains?0=no, 1=yes").getInt() == 0 ? false : true;
	c.save();
}
 
開發者ID:Ubiquitous-Spice,項目名稱:ModJam-4,代碼行數:26,代碼來源:BloodStains.java

示例3: call

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
public Object call() throws Exception {
  // Setup for capturing logger messages
  Appender mockAppender = mock(Appender.class);
  when(mockAppender.getName()).thenReturn("MockAppender");
  when(mockAppender.isStarted()).thenReturn(true);
  when(mockAppender.isStopped()).thenReturn(false);
  Logger logger = (Logger) LogManager.getLogger(ColocationLogger.class);
  logger.addAppender(mockAppender);
  logger.setLevel(Level.WARN);
  loggingEventCaptor = ArgumentCaptor.forClass(LogEvent.class);

  // Logger interval may have been hooked by the test, so adjust test delays here
  int logInterval = ColocationLogger.getLogInterval();
  List<LogEvent> logEvents = Collections.emptyList();

  AtomicBoolean isDone = new AtomicBoolean(false);
  try {
    createPR(PR_REGION_NAME, true);
    // Let this thread continue running long enough for the missing region to be logged a
    // couple times.
    // Child regions do not get created by this thread.
    await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> {
      verify(mockAppender, times(numExpectedLogMessages))
          .append(loggingEventCaptor.capture());
    });
    // createPR("region2", PR_REGION_NAME, true); // This child region is never created
  } finally {
    logEvents = loggingEventCaptor.getAllValues();
    assertEquals(String.format("Expected %d messages to be logged, got %d.",
        numExpectedLogMessages, logEvents.size()), numExpectedLogMessages,
        logEvents.size());
    String logMsg = logEvents.get(0).getMessage().getFormattedMessage();
    logger.removeAppender(mockAppender);
    numExpectedLogMessages = 1;
    return logMsg;
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:38,代碼來源:PersistentColocatedPartitionedRegionDUnitTest.java

示例4: testStructured

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Test
public void testStructured() throws InterruptedException, IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost",
            testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents,
            null, "false", "Avro", null, "1000", "1000", "1", "1000",
            "avro", "false", null, null, null, "ReqCtx_", null, "true",
            "1", null, null, null, null);
    avroAppender.start();
    final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
    Assert.assertNotNull(eventLogger);
    eventLogger.addAppender(avroAppender);
    eventLogger.setLevel(Level.ALL);

    final StructuredDataMessage msg = new StructuredDataMessage("Transfer",
            "Success", "Audit");
    msg.put("memo", "This is a memo");
    msg.put("acct", "12345");
    msg.put("amount", "100.00");
    ThreadContext.put("id", UUID.randomUUID().toString());
    ThreadContext.put("memo", null);
    ThreadContext.put("test", "123");

    EventLogger.logEvent(msg);

    final Transaction transaction = channel.getTransaction();
    transaction.begin();

    final Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue("Channel contained event, but not expected message",
            getBody(event).endsWith("Success"));
    transaction.commit();
    transaction.close();

    eventSource.stop();
    eventLogger.removeAppender(avroAppender);
    avroAppender.stop();
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:40,代碼來源:FlumeAppenderTest.java

示例5: testLayoutNormalApi

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
static void testLayoutNormalApi(final Logger root, final AbstractCsvLayout layout, final boolean messageApi)
        throws Exception {
    removeAppenders(root);
    // set up appender
    final ListAppender appender = new ListAppender("List", null, layout, true, false);
    appender.start();

    appender.countDownLatch = new CountDownLatch(4);

    // set appender on root and set level to debug
    root.addAppender(appender);
    root.setLevel(Level.DEBUG);

    // output messages
    if (messageApi) {
        logDebugObjectArrayMessage(root);
    } else {
        logDebugNormalApi(root);
    }
    final int msgCount = 4;
    if (appender.getMessages().size() < msgCount) {
        // wait until background thread finished processing
        appender.countDownLatch.await(10, TimeUnit.SECONDS);
    }
    assertEquals("Background thread did not finish processing: msg count", msgCount, appender.getMessages().size());

    // don't stop appender until background thread is done
    appender.stop();

    final List<String> list = appender.getMessages();
    final char d = layout.getFormat().getDelimiter();
    Assert.assertEquals("1" + d + "2" + d + "3", list.get(0));
    Assert.assertEquals("2" + d + "3", list.get(1));
    Assert.assertEquals("5" + d + "6", list.get(2));
    Assert.assertEquals("7" + d + "8" + d + "9" + d + "10", list.get(3));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:37,代碼來源:CsvParameterLayoutTest.java

示例6: testStructured

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Test
public void testStructured() throws IOException {
    final Agent[] agents = new Agent[] { Agent.createAgent("localhost",
            testPort) };
    final FlumeAppender avroAppender = FlumeAppender.createAppender(agents,
            null, null, "false", "Avro", null, "1000", "1000", "1", "1000",
            "avro", "false", null, null, null, "ReqCtx_", null, "true",
            "1", null, null, null, null);
    avroAppender.start();
    final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
    Assert.assertNotNull(eventLogger);
    eventLogger.addAppender(avroAppender);
    eventLogger.setLevel(Level.ALL);

    final StructuredDataMessage msg = new StructuredDataMessage("Transfer",
            "Success", "Audit");
    msg.put("memo", "This is a memo");
    msg.put("acct", "12345");
    msg.put("amount", "100.00");
    ThreadContext.put("id", UUID.randomUUID().toString());
    ThreadContext.put("memo", null);
    ThreadContext.put("test", "123");

    EventLogger.logEvent(msg);

    final Transaction transaction = channel.getTransaction();
    transaction.begin();

    final Event event = channel.take();
    Assert.assertNotNull(event);
    Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Success"));
    transaction.commit();
    transaction.close();

    eventSource.stop();
    eventLogger.removeAppender(avroAppender);
    avroAppender.stop();
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:39,代碼來源:FlumeAppenderTest.java

示例7: testDelivery

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Test
public void testDelivery() {
    final SMTPAppender appender = SMTPAppender.createAppender("Test",
            "[email protected]", "[email protected]", "[email protected]",
            "[email protected]", "[email protected]", "Subject", null,
            HOST, PORT, null, null, "false", "3", null, null, "true");
    appender.start();

    final LoggerContext context = (LoggerContext) LogManager.getContext();
    final Logger root = context.getLogger("SMTPAppenderTest");
    root.addAppender(appender);
    root.setAdditive(false);
    root.setLevel(Level.DEBUG);

    final SimpleSmtpServer server = SimpleSmtpServer.start(PORTNUM);

    root.debug("Debug message #1");
    root.debug("Debug message #2");
    root.debug("Debug message #3");
    root.debug("Debug message #4");
    root.error("Error with exception", new RuntimeException(
            "Exception message"));
    root.error("Error message #2");

    server.stop();
    assertTrue(server.getReceivedEmailSize() == 2);
    final Iterator<SmtpMessage> messages = server.getReceivedEmail();
    final SmtpMessage email = messages.next();

    assertEquals("[email protected]", email.getHeaderValue("To"));
    assertEquals("[email protected]", email.getHeaderValue("Cc"));
    // assertEquals("[email protected]", email.getHeaderValue("Bcc")); // BCC
    // can't be tested with Dumpster 1.6
    assertEquals("[email protected]", email.getHeaderValue("From"));
    assertEquals("[email protected]", email.getHeaderValue("Reply-To"));
    assertEquals("Subject", email.getHeaderValue("Subject"));

    final String body = email.getBody();
    assertFalse(body.contains("Debug message #1"));
    assertTrue(body.contains("Debug message #2"));
    assertTrue(body.contains("Debug message #3"));
    assertTrue(body.contains("Debug message #4"));
    assertTrue(body.contains("Error with exception"));
    assertTrue(body.contains("RuntimeException"));
    assertTrue(body.contains("Exception message"));
    assertFalse(body.contains("Error message #2"));

    final SmtpMessage email2 = (SmtpMessage) messages.next();
    final String body2 = email2.getBody();
    assertFalse(body2.contains("Debug message #4"));
    assertFalse(body2.contains("Error with exception"));
    assertTrue(body2.contains("Error message #2"));
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:54,代碼來源:SMTPAppenderTest.java

示例8: testDelivery

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Test
public void testDelivery() {
    final String subjectKey = getClass().getName();
    final String subjectValue = "SubjectValue1";
    ThreadContext.put(subjectKey, subjectValue);
    final SmtpAppender appender = SmtpAppender.createAppender(null, "Test", "[email protected]", "[email protected]",
            "[email protected]", "[email protected]", "[email protected]", "Subject Pattern %X{" + subjectKey + "}",
            null, HOST, PORT, null, null, "false", "3", null, null, "true");
    appender.start();

    final LoggerContext context = LoggerContext.getContext();
    final Logger root = context.getLogger("SMTPAppenderTest");
    root.addAppender(appender);
    root.setAdditive(false);
    root.setLevel(Level.DEBUG);

    final SimpleSmtpServer server = SimpleSmtpServer.start(PORTNUM);

    root.debug("Debug message #1");
    root.debug("Debug message #2");
    root.debug("Debug message #3");
    root.debug("Debug message #4");
    root.error("Error with exception", new RuntimeException("Exception message"));
    root.error("Error message #2");

    server.stop();
    assertTrue(server.getReceivedEmailSize() == 2);
    final Iterator<SmtpMessage> messages = server.getReceivedEmail();
    final SmtpMessage email = messages.next();

    assertEquals("[email protected]", email.getHeaderValue("To"));
    assertEquals("[email protected]", email.getHeaderValue("Cc"));
    // assertEquals("[email protected]", email.getHeaderValue("Bcc")); // BCC
    // can't be tested with Dumpster 1.6
    assertEquals("[email protected]", email.getHeaderValue("From"));
    assertEquals("[email protected]", email.getHeaderValue("Reply-To"));
    final String headerValue = email.getHeaderValue("Subject");
    assertEquals(headerValue, "Subject Pattern " + subjectValue);

    final String body = email.getBody();
    assertFalse(body.contains("Debug message #1"));
    assertTrue(body.contains("Debug message #2"));
    assertTrue(body.contains("Debug message #3"));
    assertTrue(body.contains("Debug message #4"));
    assertTrue(body.contains("Error with exception"));
    assertTrue(body.contains("RuntimeException"));
    assertTrue(body.contains("Exception message"));
    assertFalse(body.contains("Error message #2"));

    final SmtpMessage email2 = messages.next();
    final String body2 = email2.getBody();
    assertFalse(body2.contains("Debug message #4"));
    assertFalse(body2.contains("Error with exception"));
    assertTrue(body2.contains("Error message #2"));
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:56,代碼來源:SmtpAppenderTest.java

示例9: testTcpAppender

import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
static void testTcpAppender(final TcpSocketTestServer tcpTestServer, final Logger logger, final int bufferSize)
        throws Exception {
    // @formatter:off
    final SocketAppender appender = SocketAppender.newBuilder()
            .withHost("localhost")
            .withPort(tcpTestServer.getLocalPort())
            .withReconnectDelayMillis(-1)
            .withName("test")
            .withImmediateFail(false)
            .withBufferSize(bufferSize)
            .withLayout(JsonLayout.newBuilder().setProperties(true).build())
            .build();
    // @formatter:on
    appender.start();
    Assert.assertEquals(bufferSize, appender.getManager().getByteBuffer().capacity());

    // set appender on root and set level to debug
    logger.addAppender(appender);
    logger.setAdditive(false);
    logger.setLevel(Level.DEBUG);
    final String tcKey = "UUID";
    final String expectedUuidStr = UUID.randomUUID().toString();
    ThreadContext.put(tcKey, expectedUuidStr);
    ThreadContext.push(expectedUuidStr);
    final String expectedExMsg = "This is a test";
    try {
        logger.debug("This is a test message");
        final Throwable child = new LoggingException(expectedExMsg);
        logger.error("Throwing an exception", child);
        logger.debug("This is another test message");
    } finally {
        ThreadContext.remove(tcKey);
        ThreadContext.pop();
    }
    Thread.sleep(250);
    LogEvent event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
    assertNotNull("No event retrieved", event);
    assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("This is a test message"));
    assertTrue("Message not delivered via TCP", tcpTestServer.getCount() > 0);
    assertEquals(expectedUuidStr, event.getContextData().getValue(tcKey));
    event = tcpTestServer.getQueue().poll(3, TimeUnit.SECONDS);
    assertNotNull("No event retrieved", event);
    assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("Throwing an exception"));
    assertTrue("Message not delivered via TCP", tcpTestServer.getCount() > 1);
    assertEquals(expectedUuidStr, event.getContextStack().pop());
    assertNotNull(event.getThrownProxy());
    assertEquals(expectedExMsg, event.getThrownProxy().getMessage());
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:49,代碼來源:SocketAppenderTest.java


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