本文整理汇总了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);
}