本文整理汇总了Java中org.graylog2.gelfclient.GelfMessageLevel类的典型用法代码示例。如果您正苦于以下问题:Java GelfMessageLevel类的具体用法?Java GelfMessageLevel怎么用?Java GelfMessageLevel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GelfMessageLevel类属于org.graylog2.gelfclient包,在下文中一共展示了GelfMessageLevel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Override
public void write(Message message) {
Uninterruptibles.awaitUninterruptibly(transportInitialized);
LOG.debug("Sending message: {}", message);
try {
final GelfMessageBuilder messageBuilder = new GelfMessageBuilder(message.getMessage(), message.getSource())
.timestamp(message.getTimestamp().getMillis() / 1000.0)
.additionalFields(message.getFields().asMap());
if (message.getLevel() != null) {
messageBuilder.level(GelfMessageLevel.valueOf(message.getLevel().toString()));
} else {
messageBuilder.level(null);
}
transport.send(messageBuilder.build());
} catch (InterruptedException e) {
LOG.error("Failed to send message", e);
}
}
示例2: append
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
public void append(
String shortMessage, AccessLogMessage accessLogMessage,
Map<String, Object> additionalFields) {
GelfMessage gelfMessage = new GelfMessageBuilder(shortMessage, hostname)
.additionalFields(accessLogMessage.getFields())
.additionalFields(additionalFields)
.level(GelfMessageLevel.INFO)
.build();
try {
transport.send(gelfMessage);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
示例3: toGelfMessageLevel
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
private GelfMessageLevel toGelfMessageLevel(Level level) {
switch (level.toInt()) {
case Level.ERROR_INT:
return GelfMessageLevel.ERROR;
case Level.WARN_INT:
return GelfMessageLevel.WARNING;
case Level.DEBUG_INT:
return GelfMessageLevel.DEBUG;
default:
return GelfMessageLevel.INFO;
}
}
示例4: convertFrom
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Override
public GelfMessageLevel convertFrom(String value) {
try {
return GelfMessageLevel.valueOf(Strings.nullToEmpty(value).toUpperCase(Locale.ENGLISH));
} catch (IllegalArgumentException e) {
throw new ParameterException("Couldn't convert value \"" + value + "\" to GELF message level.", e);
}
}
示例5: convertTo
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Override
public String convertTo(GelfMessageLevel value) {
if (value == null) {
throw new ParameterException("Couldn't convert \"null\" to string.");
}
return value.name();
}
示例6: setup
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@BeforeMethod
public void setup() {
channel = new EmbeddedChannel(new GelfMessageJsonEncoder());
message = new GelfMessageBuilder("test")
.fullMessage("The full message!")
.level(GelfMessageLevel.INFO)
.additionalField("_foo", 1.0)
.additionalField("_bar", 128)
.additionalField("_baz", "a value")
.build();
assertTrue(channel.writeOutbound(message));
assertTrue(channel.finish());
}
示例7: toGelfMessageLevel
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
private GelfMessageLevel toGelfMessageLevel(final Level level) {
switch (level) {
case TRACE:
case DEBUG:
return GelfMessageLevel.DEBUG;
case INFO:
return GelfMessageLevel.INFO;
case WARNING:
return GelfMessageLevel.WARNING;
case ERROR:
return GelfMessageLevel.ERROR;
default:
throw new IllegalArgumentException("Invalid log level " + level);
}
}
示例8: toGelfMessageLevel
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
private GelfMessageLevel toGelfMessageLevel(Level level) {
switch(level.toInt()) {
case Level.ERROR_INT:
return GelfMessageLevel.ERROR;
case Level.WARN_INT:
return GelfMessageLevel.WARNING;
case Level.DEBUG_INT:
return GelfMessageLevel.DEBUG;
default:
return GelfMessageLevel.INFO;
}
}
示例9: append
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的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");
}
}
示例10: getLevel
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
public GelfMessageLevel getLevel() {
return level;
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:4,代码来源:MetricsGelfReporterConfiguration.java
示例11: convertFromValidString
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Test
public void convertFromValidString() throws Exception {
Assert.assertEquals(GelfMessageLevel.INFO, new GelfMessageLevelConverter().convertFrom("INFO"));
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:5,代码来源:GelfMessageLevelConverterTest.java
示例12: convertFromValidLowerCaseString
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Test
public void convertFromValidLowerCaseString() throws Exception {
assertEquals(GelfMessageLevel.ERROR, new GelfMessageLevelConverter().convertFrom("error"));
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:5,代码来源:GelfMessageLevelConverterTest.java
示例13: convertTo
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Test
public void convertTo() throws Exception {
assertEquals("WARNING", new GelfMessageLevelConverter().convertTo(GelfMessageLevel.WARNING));
}
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:5,代码来源:GelfMessageLevelConverterTest.java
示例14: append
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Override
public void append(LogEvent event) {
final Layout<? extends Serializable> layout = getLayout();
final String formattedMessage;
if (layout == null) {
formattedMessage = event.getMessage().getFormattedMessage();
} else {
formattedMessage = new String(layout.toByteArray(event), StandardCharsets.UTF_8);
}
final GelfMessageBuilder builder = new GelfMessageBuilder(formattedMessage, hostName)
.timestamp(event.getTimeMillis() / 1000d)
.level(GelfMessageLevel.fromNumericLevel(Severity.getSeverity(event.getLevel()).getCode()))
.additionalField("loggerName", event.getLoggerName())
.additionalField("threadName", event.getThreadName());
final Marker marker = event.getMarker();
if (marker != null) {
builder.additionalField("marker", marker.getName());
}
if (includeThreadContext) {
for (Map.Entry<String, String> entry : event.getContextMap().entrySet()) {
builder.additionalField(entry.getKey(), entry.getValue());
}
// Guard against https://issues.apache.org/jira/browse/LOG4J2-1530
final ThreadContext.ContextStack contextStack = event.getContextStack();
if (contextStack != null) {
final List<String> contextStackItems = contextStack.asList();
if (contextStackItems != null && !contextStackItems.isEmpty()) {
builder.additionalField("contextStack", contextStackItems.toString());
}
}
}
if (includeSource) {
final StackTraceElement source = event.getSource();
if (source != null) {
builder.additionalField("sourceFileName", source.getFileName());
builder.additionalField("sourceMethodName", source.getMethodName());
builder.additionalField("sourceClassName", source.getClassName());
builder.additionalField("sourceLineNumber", source.getLineNumber());
}
}
@SuppressWarnings("all")
final Throwable thrown = event.getThrown();
if (includeStackTrace && thrown != null) {
String stackTrace;
if (includeExceptionCause) {
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
thrown.printStackTrace(printWriter);
stackTrace = stringWriter.toString();
} else {
stackTrace = getSimpleStacktraceAsString(thrown);
}
builder.additionalField("exceptionClass", thrown.getClass().getCanonicalName());
builder.additionalField("exceptionMessage", thrown.getMessage());
builder.additionalField("exceptionStackTrace", stackTrace);
builder.fullMessage(formattedMessage);
}
if (!additionalFields.isEmpty()) {
builder.additionalFields(additionalFields);
}
final GelfMessage gelfMessage = builder.build();
try {
final boolean sent = client.trySend(gelfMessage);
if (!sent) {
LOG.debug("Couldn't send message: {}", gelfMessage);
}
} catch (Exception e) {
throw new AppenderLoggingException("failed to write log event to GELF server: " + e.getMessage(), e);
}
}
示例15: testWrite
import org.graylog2.gelfclient.GelfMessageLevel; //导入依赖的package包/类
@Test
public void testWrite() throws Exception {
final GelfTransport client = mock(GelfTransport.class);
final GelfWriter gelfWriter = new GelfWriter("localhost", 12201, GelfTransports.UDP, "myHostName",
EnumSet.of(LogEntryValue.EXCEPTION, LogEntryValue.PROCESS_ID),
Collections.<String, Object>singletonMap("staticField", "TEST"), 512, 1000, 500, -1, false);
@SuppressWarnings("all")
final RuntimeException exception = new RuntimeException("BOOM!");
exception.fillInStackTrace();
final Date now = new Date();
final ThreadGroup threadGroup = new ThreadGroup("TEST-threadGroup");
final Thread thread = new Thread(threadGroup, "TEST-thread");
thread.setPriority(1);
final LogEntry logEntry = new LogEntry(now, "TEST-processId", thread,
"TEST-ClassName", "TEST-MethodName", "TEST-FileName", 42, Level.INFO,
"Test 123", exception);
gelfWriter.write(client, logEntry);
final ArgumentCaptor<GelfMessage> argumentCaptor = ArgumentCaptor.forClass(GelfMessage.class);
verify(client).send(argumentCaptor.capture());
final GelfMessage message = argumentCaptor.getValue();
assertThat(message.getHost(), equalTo("myHostName"));
assertThat(message.getMessage(), equalTo("Test 123"));
assertThat(message.getLevel(), equalTo(GelfMessageLevel.INFO));
assertThat(new Date((long) (message.getTimestamp() * 1000l)), equalTo(now));
assertThat(message.getFullMessage(), startsWith(message.getMessage()));
final Map<String, Object> additionalFields = message.getAdditionalFields();
assertThat(additionalFields.isEmpty(), is(false));
assertThat((String) additionalFields.get("processId"), equalTo("TEST-processId"));
assertThat((String) additionalFields.get("threadName"), equalTo("TEST-thread"));
assertThat((Integer) additionalFields.get("threadPriority"), equalTo(1));
assertThat((String) additionalFields.get("threadGroup"), equalTo("TEST-threadGroup"));
assertThat((String) additionalFields.get("sourceClassName"), equalTo("TEST-ClassName"));
assertThat((String) additionalFields.get("sourceMethodName"), equalTo("TEST-MethodName"));
assertThat((String) additionalFields.get("sourceFileName"), equalTo("TEST-FileName"));
assertThat((Integer) additionalFields.get("sourceLineNumber"), equalTo(42));
assertThat((String) additionalFields.get("exceptionMessage"), equalTo("BOOM!"));
assertThat((String) additionalFields.get("exceptionClass"), equalTo(RuntimeException.class.getCanonicalName()));
assertThat((String) additionalFields.get("exceptionStackTrace"), startsWith(this.getClass().getCanonicalName()));
}