当前位置: 首页>>代码示例>>Java>>正文


Java LoggingEvent.setMessage方法代码示例

本文整理汇总了Java中ch.qos.logback.classic.spi.LoggingEvent.setMessage方法的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent.setMessage方法的具体用法?Java LoggingEvent.setMessage怎么用?Java LoggingEvent.setMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.classic.spi.LoggingEvent的用法示例。


在下文中一共展示了LoggingEvent.setMessage方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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;
	}
}
 
开发者ID:pradeepmvn,项目名称:logback-nifi-appender,代码行数:21,代码来源:TestNifiAppender.java

示例2: 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);
}
 
开发者ID:dwango,项目名称:slack-webhook-appender,代码行数:19,代码来源:SlackWebhookAppenderTest.java

示例3: build

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
public LoggingEvent build(int i) {

    LoggingEvent le = new LoggingEvent();
    le.setTimeStamp(System.currentTimeMillis());

    Object[] aa = new Object[] { i, "HELLO WORLD [========== ]" + i };

    le.setArgumentArray(aa);
    String msg = MSG + i;
    le.setMessage(msg);

    // compute formatted message
    // this forces le.formmatedMessage to be set (this is the whole point of the
    // exercise)
    le.getFormattedMessage();
    le.setLevel(Level.DEBUG);
    le.setLoggerName(logger.getName());
    le.setLoggerContextRemoteView(loggerContext.getLoggerContextRemoteView());
    le.setThreadName("threadName");
    return le;
  }
 
开发者ID:cscfa,项目名称:bartleby,代码行数:22,代码来源:LoggingEventWithParametersBuilder.java

示例4: makeEvent

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
private LoggingEvent makeEvent(Level level, String message, Throwable th) {
	LoggingEvent event = new LoggingEvent();
	event.setLoggerName(CloudWatchAppender.class.getName());
	event.setLevel(level);
	event.setMessage(message);
	event.setTimeStamp(System.currentTimeMillis());
	if (th != null) {
		event.setThrowableProxy(new ThrowableProxy(th));
	}
	return event;
}
 
开发者ID:j256,项目名称:cloudwatch-logback-appender,代码行数:12,代码来源:CloudWatchAppender.java

示例5: onLog

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public void onLog(LogEntry logEntry) {

  final LoggingEvent loggingEvent = new LoggingEvent();
  loggingEvent.setTimeStamp(logEntry.getTimestamp());
  loggingEvent.setLoggerName(logEntry.getLoggerName());
  loggingEvent.setLevel(Level.valueOf(logEntry.getLogLevel().name()));
  loggingEvent.setThreadName(logEntry.getThreadName());
  Object [] formatObjects = new Object[] {logEntry.getHost(),
    getSimpleClassName(logEntry.getSourceClassName()),
    logEntry.getSourceMethodName(),
    logEntry.getFileName(),
    logEntry.getLineNumber(),logEntry.getMessage()};
  loggingEvent.setMessage(MESSAGE_FORMAT.get().format(formatObjects));

  // Prints the throwable and stack trace.
  LogThrowable logThrowable = logEntry.getThrowable();
  if (logThrowable != null) {
    loggingEvent.setThrowableProxy(new ThrowableProxy(setThrowable(logThrowable)));
  }

  if (logger instanceof Logger) {
    ((Logger) logger).callAppenders(loggingEvent);
  } else {
    logger.info("Logger is not instance of ch.qos.logback.classic.Logger. Logger event is: {}", loggingEvent);
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:28,代码来源:YarnTwillLogHandler.java

示例6: build

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
public Object build(int i) {
  LoggingEvent le = new LoggingEvent();
  le.setTimeStamp(System.currentTimeMillis());
  le.setLevel(Level.DEBUG);
  le.setLoggerName(logger.getName());
  le.setLoggerContextRemoteView(loggerContext.getLoggerContextRemoteView());
  le.setMessage(MSG_PREFIX);
  le.setThreadName("threadName");
  return le;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:11,代码来源:TrivialLoggingEventBuilder.java

示例7: createLoggingEvent

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
private ILoggingEvent createLoggingEvent() {
  LoggingEvent le = new LoggingEvent();
  le.setLevel(Level.DEBUG);
  le.setMessage("test message");
  le.setTimeStamp(System.currentTimeMillis());
  le.setThreadName(Thread.currentThread().getName());
  return le;
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:9,代码来源:JMSQueueAppenderTest.java

示例8: createLoggingEvent

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
private LoggingEvent createLoggingEvent(final Level level,
                                        final String message,
                                        final Object... params) {
    final LoggingEvent loggingEvent = new LoggingEvent();
    loggingEvent.setMDCPropertyMap(singletonMap("job_id", "someJobId"));
    loggingEvent.setMessage(message);
    loggingEvent.setArgumentArray(params);
    loggingEvent.setLevel(level);
    loggingEvent.setMarker(JobMarker.JOB);
    return loggingEvent;
}
 
开发者ID:otto-de,项目名称:edison-microservice,代码行数:12,代码来源:JobMessageLogAppenderTest.java

示例9: decideValidJson

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Test
public void decideValidJson() throws IOException {
    LoggingEvent loggingEvent = new LoggingEvent();
    loggingEvent.setMessage(readFirstLine("/valid-json.json"));
    FilterReply reply = jsonValidationFilter.decide(loggingEvent);
    assertThat(reply, is(FilterReply.ACCEPT));
    assertThat(MDC.get(OutputValidationException.MDC_KEY), nullValue());
}
 
开发者ID:CiscoCTA,项目名称:taxii-log-adapter,代码行数:9,代码来源:JsonValidationFilterTest.java

示例10: decideInvalidJson

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Test
public void decideInvalidJson() throws IOException {
    LoggingEvent loggingEvent = new LoggingEvent();
    loggingEvent.setMessage(readFirstLine("/invalid-json.json"));
    try {
        FilterReply reply = jsonValidationFilter.decide(loggingEvent);
        assertThat(reply, is(FilterReply.DENY));
        assertThat(MDC.get(OutputValidationException.MDC_KEY), notNullValue());
    }finally {
        MDC.remove(OutputValidationException.MDC_KEY);
    }
}
 
开发者ID:CiscoCTA,项目名称:taxii-log-adapter,代码行数:13,代码来源:JsonValidationFilterTest.java

示例11: testBasic

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Test(timeout = 5000)
public void testBasic() throws InterruptedException {
	CloudWatchAppender appender = new CloudWatchAppender();
	AWSLogsClient awsLogClient = createMock(AWSLogsClient.class);
	appender.setAwsLogsClient(awsLogClient);

	appender.setMaxBatchSize(1);
	appender.setRegion("region");
	final String logGroup = "pfqoejpfqe";
	appender.setLogGroup(logGroup);
	final String logStream = "pffqjfqjpoqoejpfqe";
	appender.setLogStream(logStream);
	PatternLayout layout = new PatternLayout();
	layout.setContext(new LoggerContext());
	layout.setPattern("[%thread] %level %logger{20} - %msg%n%xThrowable");
	layout.start();
	appender.setLayout(layout);

	LoggingEvent event = new LoggingEvent();
	event.setTimeStamp(System.currentTimeMillis());
	String loggerName = "name";
	event.setLoggerName(loggerName);
	Level level = Level.DEBUG;
	event.setLevel(level);
	String message = "fjpewjfpewjfpewjfepowf";
	event.setMessage(message);

	String threadName = Thread.currentThread().getName();
	final String fullMessage = "[" + threadName + "] " + level + " " + loggerName + " - " + message + "\n";

	final PutLogEventsResult result = new PutLogEventsResult();
	String sequence = "ewopjfewfj";
	result.setNextSequenceToken(sequence);
	expect(awsLogClient.putLogEvents(isA(PutLogEventsRequest.class))).andAnswer(new IAnswer<PutLogEventsResult>() {
		@Override
		public PutLogEventsResult answer() {
			PutLogEventsRequest request = (PutLogEventsRequest) getCurrentArguments()[0];
			assertEquals(logGroup, request.getLogGroupName());
			assertEquals(logStream, request.getLogStreamName());
			List<InputLogEvent> events = request.getLogEvents();
			assertEquals(1, events.size());
			assertEquals(fullMessage, events.get(0).getMessage());
			return result;
		}
	}).times(2);
	awsLogClient.shutdown();

	// =====================================

	replay(awsLogClient);
	appender.start();
	// for coverage
	appender.start();
	appender.append(event);
	Thread.sleep(10);
	appender.append(event);
	while (appender.getEventsWrittenCount() < 2) {
		Thread.sleep(10);
	}
	appender.stop();
	verify(awsLogClient);
}
 
开发者ID:j256,项目名称:cloudwatch-logback-appender,代码行数:63,代码来源:CloudWatchAppenderTest.java

示例12: append

import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
protected void append(ILoggingEvent event) {

    if (event == null) {
        return;
    }

    // create a copy of the logging event to avoid passing exception stacktraces to GELF's short_message field
    LoggingEvent copy = new LoggingEvent();
    copy.setMessage(event.getMessage());
    copy.setLevel(event.getLevel());
    copy.setArgumentArray(event.getArgumentArray());

    final GelfMessageBuilder builder = new GelfMessageBuilder(this.layout.doLayout(copy), hostName()).timestamp(
                event.getTimeStamp() / 1000d)
            .level(GelfMessageLevel.fromNumericLevel(toGelfNumericValue(event.getLevel())))
            .additionalField("loggerName", event.getLoggerName())
            .additionalField("threadName", event.getThreadName());

    final Marker marker = event.getMarker();

    if (marker != null) {
        builder.additionalField("marker", marker.getName());
    }

    if (includeMDC) {
        for (Map.Entry<String, String> entry : event.getMDCPropertyMap().entrySet()) {
            builder.additionalField(entry.getKey(), entry.getValue());
        }
    }

    StackTraceElement[] callerData = event.getCallerData();

    if (includeSource && event.hasCallerData() && callerData.length > 0) {
        StackTraceElement source = callerData[0];

        builder.additionalField("sourceFileName", source.getFileName());
        builder.additionalField("sourceMethodName", source.getMethodName());
        builder.additionalField("sourceClassName", source.getClassName());
        builder.additionalField("sourceLineNumber", source.getLineNumber());
    }

    IThrowableProxy thrown = event.getThrowableProxy();

    if (includeStackTrace && thrown != null) {
        String convertedThrowable = throwableConverter.convert(event);

        builder.additionalField("exceptionClass", thrown.getClassName());
        builder.additionalField("exceptionMessage", thrown.getMessage());
        builder.additionalField("exceptionStackTrace", convertedThrowable);

        builder.fullMessage(event.getFormattedMessage() + "\n\n" + convertedThrowable);
    } else {
        builder.fullMessage(event.getFormattedMessage());
    }

    if (includeLevelName) {
        builder.additionalField("levelName", event.getLevel().levelStr);
    }

    if (!additionalFields.isEmpty()) {
        builder.additionalFields(additionalFields);
    }

    if(!client.trySend(builder.build())) {
        addError("Failed to write log event to the GELF server using trySend");
    }
}
 
开发者ID:rkcpi,项目名称:logback-gelf-appender,代码行数:69,代码来源:GelfAppender.java


注:本文中的ch.qos.logback.classic.spi.LoggingEvent.setMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。