本文整理汇总了Java中ch.qos.logback.classic.spi.ILoggingEvent类的典型用法代码示例。如果您正苦于以下问题:Java ILoggingEvent类的具体用法?Java ILoggingEvent怎么用?Java ILoggingEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILoggingEvent类属于ch.qos.logback.classic.spi包,在下文中一共展示了ILoggingEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addCustomDataToJsonMap
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Override
protected void addCustomDataToJsonMap(Map<String, Object> map, ILoggingEvent event) {
add(HOST, includeHost, HOST_NAME, map);
if (event.hasCallerData()) {
StackTraceElement callerData = event.getCallerData()[0];
addLine(LINE_NUMBER, includeLineNumber, callerData.getLineNumber(), map);
add(CLASS_NAME, includeClassName, callerData.getClassName(), map);
add(METHOD_NAME, includeMethodName, callerData.getMethodName(), map);
add(FILE_NAME, includeFileName, callerData.getFileName(), map);
}
if (additionalFields != null) {
additionalFields.forEach(field -> {
String[] p = field.split("\\|");
if (p.length == 2) {
add(p[0], true, p[1], map);
} else {
addWarn("Unable to parse property string: " + field);
}
});
}
}
示例2: appendThrowable
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
private void appendThrowable(IThrowableProxy proxy, ILoggingEvent loggingEvent) {
//Append Exception Message
appendToLog(loggingEvent, String.format("%s: %s", proxy.getClassName(), proxy.getMessage()));
//Append Exception Stack Trace
for (StackTraceElementProxy element : loggingEvent.getThrowableProxy().getStackTraceElementProxyArray()) {
appendToLog(loggingEvent, "\t" + element.getSTEAsString());
}
if (proxy.getSuppressed().length > 0) {
appendToLog(loggingEvent, "Suppressed Exceptions:");
for (IThrowableProxy p : proxy.getSuppressed()) {
appendThrowable(p, loggingEvent);
}
}
if (proxy.getCause() != null) {
appendToLog(loggingEvent, "Cause:");
appendThrowable(proxy.getCause(), loggingEvent);
}
}
示例3: fieldsConfigTest
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Test
public void fieldsConfigTest()
{
LogFmtLayout logFmtLayout = new LogFmtLayout();
logFmtLayout.setFields("time, mdc, custom, level, msg");
logFmtLayout.setTimeFormat("YYYY");
Calendar calendar = Calendar.getInstance();
calendar.set(2017, Calendar.NOVEMBER, 30, 15, 10, 25);
Map<String, String> mdc = new HashMap<>();
mdc.put("mdckey", "mdc value");
ILoggingEvent loggingEvent = createLoggingEvent("thread0", Level.DEBUG, calendar.getTime(),
with("key1", "value1").and("key2", "val ue2"), "message with \"double quotes\"", mdc);
assertEquals(
"time=2017 mdckey=\"mdc value\" key1=value1 key2=\"val ue2\" level=debug msg=\"message with \\\"double quotes\\\"\"\n",
logFmtLayout.doLayout(loggingEvent)
);
}
示例4: shouldReportOnMigrations
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Test
public void shouldReportOnMigrations() throws MongoTrekFailureException {
MongoTrek migrations = new MongoTrek("fixtures/last-failure-migrations.yml", this.database);
migrations.setSchemaVersionCollection(SCHEMA_VERSION_COLLECTION);
migrations.status();
verify(appender, atLeastOnce()).doAppend(captor.capture());
List<ILoggingEvent> events = captor.getAllValues();
assertThat(events).areAtLeastOne(loggedMessage("DATABASE MIGRATIONS"))
.areAtLeastOne(loggedMessage(" Database : [ migration_test ]"))
.areAtLeastOne(loggedMessage(" Schema Version : [ _schema_version ]"))
.areAtLeastOne(loggedMessage(" Action : [ status ]"))
.areAtLeastOne(loggedMessage("Current Version : [ 1.0.1 ]"))
.areAtLeastOne(loggedMessage(" Migrations :"))
.areAtLeastOne(loggedMessage(" 1.0.0 : Applied migration"))
.areAtLeastOne(loggedMessage(String.format(" Tags: [ Successful ] [ %s ] [ 2 seconds ]", toTimeStamp("2014-12-05T09:00:00+1100"))))
.areAtLeastOne(loggedMessage(" 1.0.1 : Another applied migration"))
.areAtLeastOne(loggedMessage(String.format(" Tags: [ Successful ] [ %s ] [ 60 seconds ]", toTimeStamp("2014-12-05T09:10:00+1100"))))
.areAtLeastOne(loggedMessage(" 1.0.2 : Failed last time migration"))
.areAtLeastOne(loggedMessage(String.format(" Tags: [ Failed ] [ %s ] [ ERROR: Something went horribly wrong! ]", toTimeStamp("2014-12-05T09:11:01+1100"))))
.areAtLeastOne(loggedMessage(" 2.0.0 : Brand new migration"))
.areAtLeastOne(loggedMessage(" Tags: [ Pending ]"))
.areAtLeastOne(loggedMessage(" 2.0.0.1 : I will always fail"))
.areAtLeastOne(loggedMessage(" Tags: [ Pending ]"));
}
示例5: init
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@BeforeClass
@SuppressWarnings("unchecked")
public static void init() {
loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
appender = new CdpAppender();
appender.setContext(loggerContext);
appender.start();
appender.setName(CdpAppender.class.getName());
Logger logger = loggerContext.getLogger("cdp4j.flow");
logger.addAppender((Appender<ILoggingEvent>) appender);
factory = new Launcher().launch();
session = factory.create();
session.enableConsoleLog();
URL url = TestAll.class.getResource("/session-test.html");
session.navigate(url.toString());
}
示例6: init
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Before
public void init()
{
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
ctx.reset();
this.layoutProducer = new LayoutProducer();
ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>();
appender.setLayout(layoutProducer);
appender.setContext(ctx);
appender.start();
Logger basicLogger = ctx.getLogger(LogFmtTest.class);
basicLogger.addAppender(appender);
this.logger = LogFmt.from(basicLogger);
ctx.start();
}
示例7: append
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
/**
* Info,error,warn,callback method implementation
*
* @param event
*/
@Override
protected void append(ILoggingEvent event) {
if (!isStarted()) {
return;
}
String logStr = this.layout.doLayout(event);
try {
Message msg = new Message(topic, tag, logStr.getBytes());
msg.getProperties().put(ProducerInstance.APPENDER_TYPE, ProducerInstance.LOGBACK_APPENDER);
//Send message and do not wait for the ack from the message broker.
producer.sendOneway(msg);
} catch (Exception e) {
addError("Could not send message in RocketmqLogbackAppender [" + name + "]. Message is : " + logStr, e);
}
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:RocketmqLogbackAppender.java
示例8: setMetricsMarkerLogbackFilter
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
onMarkerMetricsEvaluator.setContext(context);
onMarkerMetricsEvaluator.addMarker("metrics");
onMarkerMetricsEvaluator.start();
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
metricsFilter.setContext(context);
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
metricsFilter.setOnMatch(FilterReply.DENY);
metricsFilter.start();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext();) {
Appender<ILoggingEvent> appender = it.next();
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
log.debug("Filter metrics logs from the {} appender", appender.getName());
appender.setContext(context);
appender.addFilter(metricsFilter);
appender.start();
}
}
}
}
示例9: testGettersSetters
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Test
public void testGettersSetters() {
@SuppressWarnings("unchecked")
final Layout<ILoggingEvent> layout = mock(Layout.class);
final AWSLogs awsLogs = mock(AWSLogs.class);
final String logGroupName = "myGroup";
final String logStreamName = "myStream";
final CloudWatchAppender appender = new CloudWatchAppender();
appender.setLayout(layout);
appender.setAwsLogs(awsLogs);
appender.setLogGroupName(logGroupName);
appender.setLogStreamName(logStreamName);
assertEquals(layout, appender.getLayout());
assertEquals(awsLogs, appender.getAwsLogs());
assertEquals(logGroupName, appender.getLogGroupName());
assertEquals(logStreamName, appender.getLogStreamName());
}
示例10: overrideLogLevelProvider
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Test
public void overrideLogLevelProvider() {
SixtJsonEncoder encoder = new SixtJsonEncoder();
JsonProviders<ILoggingEvent> providers = encoder.getProviders();
int defaultCount = 0;
int overrideCount = 0;
for (JsonProvider<ILoggingEvent> provider : providers.getProviders()) {
if (provider instanceof LogLevelJsonProvider &&
!(provider instanceof CustomLogLevelJsonProvider)) {
defaultCount++;
} else if (provider instanceof CustomLogLevelJsonProvider) {
overrideCount++;
}
}
assertThat(defaultCount).isEqualTo(0);
assertThat(overrideCount).isEqualTo(1);
}
示例11: setMetricsMarkerLogbackFilter
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
private void setMetricsMarkerLogbackFilter(LoggerContext context) {
log.info("Filtering metrics logs from all appenders except the {} appender", LOGSTASH_APPENDER_NAME);
OnMarkerEvaluator onMarkerMetricsEvaluator = new OnMarkerEvaluator();
onMarkerMetricsEvaluator.setContext(context);
onMarkerMetricsEvaluator.addMarker("metrics");
onMarkerMetricsEvaluator.start();
EvaluatorFilter<ILoggingEvent> metricsFilter = new EvaluatorFilter<>();
metricsFilter.setContext(context);
metricsFilter.setEvaluator(onMarkerMetricsEvaluator);
metricsFilter.setOnMatch(FilterReply.DENY);
metricsFilter.start();
for (ch.qos.logback.classic.Logger logger : context.getLoggerList()) {
for (Iterator<Appender<ILoggingEvent>> it = logger.iteratorForAppenders(); it.hasNext(); ) {
Appender<ILoggingEvent> appender = it.next();
if (!appender.getName().equals(ASYNC_LOGSTASH_APPENDER_NAME)) {
log.debug("Filter metrics logs from the {} appender", appender.getName());
appender.setContext(context);
appender.addFilter(metricsFilter);
appender.start();
}
}
}
}
示例12: containLogsEventsNotMatchingExpected
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Test
public void containLogsEventsNotMatchingExpected() {
ExpectedLoggingMessage expectedLogMessage = aLog().info().withMessage("a log message");
List<ILoggingEvent> logEvents = Arrays.asList(
aLoggingEventWith(Level.INFO, "a different message"),
aLoggingEventWith(Level.INFO, "another different message")
);
VerificationException verificationException = VerificationException.forUnmatchedLog(expectedLogMessage, logEvents);
assertThat(verificationException.toString()).isEqualTo("com.logcapture.assertion.VerificationException: Expected at least one log matching: \n" +
"ExpectedLoggingMessage{logLevelMatcher=<INFO>, expectedMessageMatcher=[\"a log message\"], expectedMdc={}}\n" +
"Logs received: \n" +
"level: INFO marker: null mdc: {} message: a different message\n" +
"level: INFO marker: null mdc: {} message: another different message");
}
示例13: containLogsEventsNotMatchingExpectedWithMdcKeys
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Test
public void containLogsEventsNotMatchingExpectedWithMdcKeys() {
Map<String, String> mdcKeys = new HashMap<String, String>() {{
put("aKey", "aValue");
put("anotherKey", "anotherValue");
}};
ExpectedLoggingMessage expectedLogMessage = aLog().info()
.withMessage("a log message")
.withMdc("aKey", equalTo("aValue"))
.withMdc("anotherKey", equalTo("anotherValue"));
List<ILoggingEvent> logEvents = Arrays.asList(
aLoggingEventWith(Level.INFO, "a different message", mdcKeys),
aLoggingEventWith(Level.INFO, "another different message", mdcKeys)
);
VerificationException verificationException = VerificationException.forUnmatchedLog(expectedLogMessage, logEvents);
assertThat(verificationException.toString()).isEqualTo("com.logcapture.assertion.VerificationException: Expected at least one log matching: \n" +
"ExpectedLoggingMessage{logLevelMatcher=<INFO>, expectedMessageMatcher=[\"a log message\"], expectedMdc={anotherKey=\"anotherValue\", aKey=\"aValue\"}}\n" +
"Logs received: \n" +
"level: INFO marker: null mdc: {anotherKey=anotherValue, aKey=aValue} message: a different message\n" +
"level: INFO marker: null mdc: {anotherKey=anotherValue, aKey=aValue} message: another different message");
}
示例14: convert
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
@Override
public String convert(ILoggingEvent event) {
String hashPart = "";
try {
hashPart = getHashPart();
} catch (Exception e) {
DEV_LOG.trace("No part to associate with log output.", e);
}
return hashPart;
}
示例15: errorAppender
import ch.qos.logback.classic.spi.ILoggingEvent; //导入依赖的package包/类
private void errorAppender(StringBuilder sb, ILoggingEvent iLoggingEvent)
{
if ( iLoggingEvent.getThrowableProxy() != null )
{
appendKeyValueAndEscape(sb, ERROR.toString(), ThrowableProxyUtil.asString(iLoggingEvent.getThrowableProxy()));
}
}