本文整理匯總了Java中ch.qos.logback.classic.spi.LoggingEvent類的典型用法代碼示例。如果您正苦於以下問題:Java LoggingEvent類的具體用法?Java LoggingEvent怎麽用?Java LoggingEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LoggingEvent類屬於ch.qos.logback.classic.spi包,在下文中一共展示了LoggingEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sometimesFails
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
public void sometimesFails() {
log.warn("This is a warning.");
log.info("This is purely informational.");
List<LoggingEvent> logs = (List<LoggingEvent>) TestNGLogCollector.getRawLogs();
assertThat(logs)
.hasSize(2)
.anySatisfy(e -> assertThat(e.getLevel()).isEqualTo(Level.WARN))
.anySatisfy(e -> assertThat(e.getLevel()).isEqualTo(Level.INFO));
invocationCount++;
if (invocationCount > 8) {
Assert.fail();
}
}
示例2: testDefaultValues
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void testDefaultValues() {
final Context mockContext = mock(Context.class);
final PutLogEventsResult mockResult = mock(PutLogEventsResult.class);
when(mockResult.getNextSequenceToken()).thenReturn("2");
final AWSLogs mockAwsLogs = mock(AWSLogs.class);
when(mockAwsLogs.putLogEvents(any())).thenReturn(mockResult);
final CloudWatchAppender appender = new CloudWatchAppender();
appender.setContext(mockContext);
appender.setAwsLogs(mockAwsLogs);
appender.start();
appender.doAppend(new LoggingEvent());
appender.stop();
}
示例3: testAlreadyExists
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void testAlreadyExists() {
final Context mockContext = mock(Context.class);
final PutLogEventsResult mockResult = mock(PutLogEventsResult.class);
when(mockResult.getNextSequenceToken()).thenReturn("2");
final AWSLogs mockAwsLogs = mock(AWSLogs.class);
when(mockAwsLogs.createLogGroup(any())).thenThrow(ResourceAlreadyExistsException.class);
when(mockAwsLogs.createLogStream(any())).thenThrow(ResourceAlreadyExistsException.class);
when(mockAwsLogs.putLogEvents(any())).thenReturn(mockResult);
final CloudWatchAppender appender = new CloudWatchAppender();
appender.setContext(mockContext);
appender.setAwsLogs(mockAwsLogs);
appender.start();
appender.doAppend(new LoggingEvent());
appender.stop();
}
示例4: append
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Override
protected void append(Object eventObject) {
if (eventObject == null) {
return;
}
if ( ! eventObject.getClass().isAssignableFrom(LoggingEvent.class) ) {
return;
}
LoggingEvent event = (LoggingEvent) eventObject;
String logEntry = event.getFormattedMessage();
if (logEntry == null || logEntry.isEmpty()) {
return;
}
int end = logEntry.indexOf("(");
if (end > 0) {
String methodName = logEntry.substring(0, end);
if (ignoredConsoleEntries.contains(methodName)) {
return;
}
}
logEntries.add(logEntry);
}
示例5: testMEssagesStream
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void testMEssagesStream() {
nifiAppender.start();
int i = 0;
boolean run=true;
while (run) {
LoggingEvent event = new LoggingEvent();
event.setMessage("{\"message\":\"rest in peace for " + i + " \" }");
nifiAppender.append(event);
i++;
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (i > 10)
run=false;
}
}
示例6: build
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
public static LoggingInfo build(LoggingEvent loggingEvent) {
LoggingInfo loggingInfo = new LoggingInfo();
if (null != loggingEvent) {
loggingInfo.setMessage(loggingEvent.getMessage());
loggingInfo.setLevel(loggingEvent.getLevel().toString());
loggingInfo.setLoggerName(loggingEvent.getLoggerName());
loggingInfo.setThreadName(loggingEvent.getThreadName());
if (null != loggingEvent.getThrowableProxy()) {
loggingInfo.setExceptionName(loggingEvent.getThrowableProxy().getClassName());
loggingInfo.setExceptionMessage(loggingEvent.getThrowableProxy().getMessage());
StackTraceElementProxy[] stackTraces = loggingEvent.getThrowableProxy().getStackTraceElementProxyArray();
if (null != stackTraces && stackTraces.length > 0) {
loggingInfo.setTopStackTrace(stackTraces[0].getStackTraceElement().toString());
}
}
if (loggingEvent.hasCallerData()) {
StackTraceElement st = loggingEvent.getCallerData()[0];
loggingInfo.setCallerData(st.toString());
}
loggingInfo.setMdcProperty(loggingEvent.getMDCPropertyMap());
loggingInfo.setCreateTime(millisecondToDateTime(loggingEvent.getTimeStamp()));
}
return loggingInfo;
}
示例7: shouldNotCaptureLogTentantAwareLogWhenEventLevelIsDifferentFromDeviceLevel
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void shouldNotCaptureLogTentantAwareLogWhenEventLevelIsDifferentFromDeviceLevel() {
ILoggingEvent logEvent = new LoggingEvent(
LOG.getName(),
LOG,
Level.DEBUG,
"Test Message",
null,
new Object[]{device.toURI(), device.getLogLevel()}
);
konkerLoggerAppender.append(logEvent);
Mockito.verify(konkerLoggerAppender, Mockito.never())
.store(Mockito.any(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString());
}
示例8: shouldNotCaptureTenantAwareLogWhenEventHasNoURI
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void shouldNotCaptureTenantAwareLogWhenEventHasNoURI(){
ILoggingEvent logEvent = new LoggingEvent(
LOG.getName(),
LOG,
Level.DEBUG,
"Test Message",
null,
new Object[]{device.getLogLevel()}
);
konkerLoggerAppender.append(logEvent);
Mockito.verify(konkerLoggerAppender, Mockito.never())
.store(Mockito.any(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString());
}
示例9: shouldNotCaptureTenantAwareLogWhenEventHasNoContextLogLevel
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void shouldNotCaptureTenantAwareLogWhenEventHasNoContextLogLevel(){
ILoggingEvent logEvent = new LoggingEvent(
LOG.getName(),
LOG,
Level.DEBUG,
"Test Message",
null,
new Object[]{device.toURI()}
);
konkerLoggerAppender.append(logEvent);
Mockito.verify(konkerLoggerAppender, Mockito.never())
.store(Mockito.any(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString());
}
示例10: shouldCaptureTenantAwareLog
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void shouldCaptureTenantAwareLog() {
ILoggingEvent logEvent = new LoggingEvent(
LOG.getName(),
LOG,
Level.INFO,
"Test Message",
null,
new Object[]{device.toURI(), device.getLogLevel()}
);
konkerLoggerAppender.append(logEvent);
Mockito.verify(konkerLoggerAppender, Mockito.atLeastOnce())
.store(Mockito.any(),
Mockito.anyString(),
Mockito.anyString(),
Mockito.anyString());
}
示例11: start_ShouldWaitAndLogUntilDatabaseIsAccessible
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void start_ShouldWaitAndLogUntilDatabaseIsAccessible() throws Exception {
Connection mockConnection = mock(Connection.class);
when(mockApplicationStartupDependentResource.getDatabaseConnection())
.thenThrow(new SQLException("not there yet"))
.thenReturn(mockConnection);
applicationStartupDependentResourceChecker.checkAndWaitForResources();
verify(mockApplicationStartupDependentResource, times(2)).getDatabaseConnection();
verify(mockApplicationStartupDependentResource).sleep(5000L);
verify(mockAppender, times(3)).doAppend(loggingEventArgumentCaptor.capture());
List<LoggingEvent> allValues = loggingEventArgumentCaptor.getAllValues();
assertThat(allValues.get(0).getFormattedMessage(), is("Checking for database availability >>>"));
assertThat(allValues.get(1).getFormattedMessage(), is("Waiting for 5 seconds till the database is available ..."));
assertThat(allValues.get(2).getFormattedMessage(), is("Database available."));
}
開發者ID:alphagov,項目名稱:pay-adminusers,代碼行數:21,代碼來源:ApplicationStartupApplicationStartupDependentResourceCheckerTest.java
示例12: start_ShouldProgressivelyIncrementSleepingTimeBetweenChecksForDBAccessibility
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void start_ShouldProgressivelyIncrementSleepingTimeBetweenChecksForDBAccessibility() throws Exception {
Connection mockConnection = mock(Connection.class);
when(mockApplicationStartupDependentResource.getDatabaseConnection())
.thenThrow(new SQLException("not there"))
.thenThrow(new SQLException("not there yet"))
.thenThrow(new SQLException("still not there"))
.thenReturn(mockConnection);
applicationStartupDependentResourceChecker.checkAndWaitForResources();
verify(mockApplicationStartupDependentResource, times(4)).getDatabaseConnection();
verify(mockApplicationStartupDependentResource).sleep(5000L);
verify(mockApplicationStartupDependentResource).sleep(10000L);
verify(mockApplicationStartupDependentResource).sleep(15000L);
verify(mockAppender, times(5)).doAppend(loggingEventArgumentCaptor.capture());
List<LoggingEvent> logStatement = loggingEventArgumentCaptor.getAllValues();
assertThat(logStatement.get(0).getFormattedMessage(), is("Checking for database availability >>>"));
assertThat(logStatement.get(1).getFormattedMessage(), is("Waiting for 5 seconds till the database is available ..."));
assertThat(logStatement.get(2).getFormattedMessage(), is("Waiting for 10 seconds till the database is available ..."));
assertThat(logStatement.get(3).getFormattedMessage(), is("Waiting for 15 seconds till the database is available ..."));
assertThat(logStatement.get(4).getFormattedMessage(), is("Database available."));
}
開發者ID:alphagov,項目名稱:pay-adminusers,代碼行數:25,代碼來源:ApplicationStartupApplicationStartupDependentResourceCheckerTest.java
示例13: addStatusEvent
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Override
public void addStatusEvent(final Status status) {
final Level level;
switch (status.getLevel()) {
case Status.INFO:
level = Level.INFO;
break;
case Status.WARN:
level = Level.WARN;
break;
case Status.ERROR:
level = Level.ERROR;
break;
default:
level = Level.INFO;
break;
}
final LoggingEvent event = new LoggingEvent(StatusToFileListener.class.getSimpleName(),
new LoggerContext().getLogger(StatusToFileListener.class),
level,
status.getMessage(),
null,
null);
append(event);
}
示例14: decide
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Override
public FilterReply decide(E eventObject) {
if (!isStarted()) {
return FilterReply.NEUTRAL;
}
LoggingEvent event = (LoggingEvent) eventObject;
if (this.levelMin != null && !event.getLevel().isGreaterOrEqual(levelMin)) {
return DENY;
}
if (this.levelMax != null && event.getLevel().toInt() > levelMax.toInt()) {
return DENY;
}
if (acceptOnMatch) {
return ACCEPT;
} else {
return NEUTRAL;
}
}
示例15: testBuildsMessage
import ch.qos.logback.classic.spi.LoggingEvent; //導入依賴的package包/類
@Test
public void testBuildsMessage() {
AppenderForTest appender = new AppenderForTest();
appender.setChannel("channel");
appender.setUsername("username");
appender.setIconEmoji("icon-emoji");
appender.setIconUrl("icon-url");
appender.setLinkNames(true);
LoggingEvent event = new LoggingEvent();
event.setMessage("text \"quoted\"");
appender.append(event);
String actual = new String(appender.body, StandardCharsets.UTF_8);
String expected = "{ \"text\": \"text \\\"quoted\\\"\", \"channel\": \"channel\", \"username\": \"username\", \"icon_emoji\": \"icon-emoji\", \"icon_url\": \"icon-url\", \"link_names\": 1 }";
Assert.assertEquals(expected, actual);
}