本文整理匯總了Java中org.apache.logging.log4j.core.Logger.debug方法的典型用法代碼示例。如果您正苦於以下問題:Java Logger.debug方法的具體用法?Java Logger.debug怎麽用?Java Logger.debug使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.Logger
的用法示例。
在下文中一共展示了Logger.debug方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
public static void main(final String[] args) throws IOException
{
final Logger logger = (Logger) LogManager.getLogger("Startup");
final Logger nettyLogger = (Logger) LogManager.getLogger("Netty");
logger.trace("Initializing loggers");
System.setOut(new PrintStream(new Log4j2OutputStream(logger, Level.INFO)));
System.setErr(new PrintStream(new Log4j2OutputStream(logger, Level.ERROR)));
InternalLoggerFactory.setDefaultFactory(new NettyLoggerFactory(nettyLogger));
logger.trace("Parsing argument");
final OptionParser optionParser = new OptionParser()
{{
this.acceptsAll(Arrays.asList("nojline", "j"), "Disable JLine for input");
this.acceptsAll(Arrays.asList("unsafe", "u"), "Allow no SSL connections");
this.acceptsAll(Arrays.asList("help", "?"), "Show this help page");
}};
final OptionSet options;
try
{
options = optionParser.parse(args);
logger.debug("Options parameters = " + options.asMap());
if (options.has("?"))
{
optionParser.printHelpOn(System.out);
return;
}
if (options.has("nojline"))
{
useJLine = false;
}
if (options.has("unsafe"))
{
canUseNoSSL = true;
}
} catch (final Exception e)
{
e.printStackTrace();
return;
}
logger.debug("Arguments = " + options.asMap());
logger.trace("Reading config");
final File configFile = new File("bridge.json");
final BridgeConfig config;
if(!configFile.exists())
{
config = new BridgeConfig();
GsonUtils.saveConfigurationFile(config, configFile);
logger.warn("Config file created, fill it before first run");
return;
}
else
{
config = GsonUtils.readConfigurationFile(BridgeConfig.class, configFile);
GsonUtils.saveConfigurationFile(config, configFile);
}
final Bridge bridge = new BridgeImpl(config);
bridge.start();
new ConsoleReaderThread(bridge, useJLine).start();
}
示例2: 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"));
}
示例3: 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]ple.com", 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"));
}
示例4: logDebugNormalApi
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
private static void logDebugNormalApi(final Logger root) {
root.debug("with placeholders: {}{}{}", 1, 2, 3);
root.debug("without placeholders", 2, 3);
root.debug(null, 5, 6);
root.debug("invalid placeholder count {}", 7, 8, 9, 10);
}
示例5: logDebugObjectArrayMessage
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
private static void logDebugObjectArrayMessage(final Logger root) {
root.debug(new ObjectArrayMessage(1, 2, 3));
root.debug(new ObjectArrayMessage(2, 3));
root.debug(new ObjectArrayMessage(5, 6));
root.debug(new ObjectArrayMessage(7, 8, 9, 10));
}
示例6: 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());
}