• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java GelfMessageLevel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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);
    }
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:23,代码来源:GelfOutput.java


示例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();
    }

}
 
开发者ID:tochkak,项目名称:play-graylog2,代码行数:17,代码来源:GelfClientAppender.java


示例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;
    }
}
 
开发者ID:tochkak,项目名称:play-graylog2,代码行数:13,代码来源:GelfClientAppender.java


示例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);
    }
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:9,代码来源:GelfMessageLevelConverter.java


示例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();
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:8,代码来源:GelfMessageLevelConverter.java


示例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());
}
 
开发者ID:Graylog2,项目名称:gelfclient,代码行数:15,代码来源:GelfMessageJsonEncoderTest.java


示例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);
    }
}
 
开发者ID:joschi,项目名称:tinylog-gelf,代码行数:16,代码来源:GelfWriter.java


示例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;
    }
}
 
开发者ID:graylog-labs,项目名称:play2-graylog2,代码行数:13,代码来源:GelfclientAppender.java


示例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");
    }
}
 
开发者ID:rkcpi,项目名称:logback-gelf-appender,代码行数:69,代码来源:GelfAppender.java


示例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);
    }
}
 
开发者ID:graylog-labs,项目名称:log4j2-gelf,代码行数:81,代码来源:GelfAppender.java


示例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()));
}
 
开发者ID:joschi,项目名称:tinylog-gelf,代码行数:46,代码来源:GelfWriterTest.java



注:本文中的org.graylog2.gelfclient.GelfMessageLevel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java FinishApplicationMasterRequestProtoOrBuilder类代码示例发布时间:2022-05-22
下一篇:
Java ValidationException类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap