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

Java GelfTransports类代码示例

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

本文整理汇总了Java中org.graylog2.gelfclient.GelfTransports的典型用法代码示例。如果您正苦于以下问题:Java GelfTransports类的具体用法?Java GelfTransports怎么用?Java GelfTransports使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



GelfTransports类属于org.graylog2.gelfclient包,在下文中一共展示了GelfTransports类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getGelfConfiguration

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
private GelfConfiguration getGelfConfiguration(Configuration config) {
    final Integer queueCapacity = config.getInt("graylog2.appender.queue-size", 512);
    final Long reconnectInterval = config.getMilliseconds("graylog2.appender.reconnect-interval", 500L);
    final Long connectTimeout = config.getMilliseconds("graylog2.appender.connect-timeout", 1000L);
    final Boolean isTcpNoDelay = config.getBoolean("graylog2.appender.tcp-nodelay", false);
    final String hostString = config.getString("graylog2.appender.host", "127.0.0.1:12201");
    final String protocol = config.getString("graylog2.appender.protocol", "udp");

    final HostAndPort hostAndPort = HostAndPort.fromString(hostString);

    GelfTransports gelfTransport = GelfTransports.valueOf(protocol.toUpperCase());

    final Integer sendBufferSize = config.getInt("graylog2.appender.sendbuffersize", 0); // causes the socket default to be used

    return new GelfConfiguration(hostAndPort.getHost(), hostAndPort.getPort())
            .transport(gelfTransport)
            .reconnectDelay(reconnectInterval.intValue())
            .queueSize(queueCapacity)
            .connectTimeout(connectTimeout.intValue())
            .tcpNoDelay(isTcpNoDelay)
            .sendBufferSize(sendBufferSize);
}
 
开发者ID:tochkak,项目名称:play-graylog2,代码行数:23,代码来源:Graylog2Component.java


示例2: GelfWriter

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
/**
 * Construct a new GelfWriter instance.
 *
 * @param server                 the hostname of the GELF-compatible server
 * @param port                   the port of the GELF-compatible server
 * @param transport              the transport protocol to use
 * @param hostname               the hostname of the application
 * @param requiredLogEntryValues additional information for log messages, see {@link LogEntryValue}
 * @param staticFields           additional static fields for the GELF messages
 * @param queueSize              the size of the internal queue the GELF client is using
 * @param connectTimeout         the connection timeout for TCP connections in milliseconds
 * @param reconnectDelay         the time to wait between reconnects in milliseconds
 * @param sendBufferSize         the size of the socket send buffer in bytes; a value of {@code -1}
 *                               deactivates the socket send buffer.
 * @param tcpNoDelay             {@code true} if Nagle's algorithm should used for TCP connections,
 *                               {@code false} otherwise
 */
public GelfWriter(final String server,
                  final int port,
                  final GelfTransports transport,
                  final String hostname,
                  final Set<LogEntryValue> requiredLogEntryValues,
                  final Map<String, Object> staticFields,
                  final int queueSize,
                  final int connectTimeout,
                  final int reconnectDelay,
                  final int sendBufferSize,
                  final boolean tcpNoDelay) {
    this.server = server;
    this.port = port;
    this.transport = transport;
    this.hostname = buildHostName(hostname);
    this.requiredLogEntryValues = buildRequiredLogEntryValues(requiredLogEntryValues);
    this.staticFields = staticFields;
    this.queueSize = queueSize;
    this.connectTimeout = connectTimeout;
    this.reconnectDelay = reconnectDelay;
    this.sendBufferSize = sendBufferSize;
    this.tcpNoDelay = tcpNoDelay;
}
 
开发者ID:joschi,项目名称:tinylog-gelf,代码行数:41,代码来源:GelfWriter.java


示例3: init

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void init(Configuration configuration) throws Exception {
    final InetSocketAddress remoteAddress = new InetSocketAddress(server, port);
    final GelfConfiguration gelfConfiguration = new GelfConfiguration(remoteAddress)
            .transport(transport)
            .queueSize(queueSize)
            .connectTimeout(connectTimeout)
            .reconnectDelay(reconnectDelay)
            .sendBufferSize(sendBufferSize)
            .tcpNoDelay(tcpNoDelay);

    client = GelfTransports.create(gelfConfiguration);

    VMShutdownHook.register(this);
}
 
开发者ID:joschi,项目名称:tinylog-gelf,代码行数:19,代码来源:GelfWriter.java


示例4: doStart

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Override
protected void doStart() {
    final GelfConfiguration clientConfig = new GelfConfiguration(configuration.getHost(), configuration.getPort());

    switch (configuration.getProtocol()) {
        case UDP:
            clientConfig
                    .transport(GelfTransports.UDP)
                    .queueSize(configuration.getClientQueueSize())
                    .sendBufferSize(configuration.getClientSendBufferSize());
        case TCP:
            clientConfig
                    .transport(GelfTransports.TCP)
                    .queueSize(configuration.getClientQueueSize())
                    .connectTimeout(configuration.getClientConnectTimeout())
                    .reconnectDelay(configuration.getClientReconnectDelay())
                    .tcpNoDelay(configuration.isClientTcpNoDelay())
                    .sendBufferSize(configuration.getClientSendBufferSize());

            if (configuration.isClientTls()) {
                clientConfig.enableTls();
                clientConfig.tlsTrustCertChainFile(configuration.getClientTlsCertChainFile());

                if (configuration.isClientTlsVerifyCert()) {
                    clientConfig.enableTlsCertVerification();
                } else {
                    clientConfig.disableTlsCertVerification();
                }
            }
            break;
    }

    LOG.info("Starting GELF transport: {}", clientConfig);
    this.transport = GelfTransports.create(clientConfig);

    transportInitialized.countDown();

    notifyStarted();
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:40,代码来源:GelfOutput.java


示例5: Graylog2Impl

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Inject
public Graylog2Impl(Configuration config) {
    String canonicalHostName;
    try {
        canonicalHostName = config.getString(
                "graylog2.appender.sourcehost",
                InetAddress.getLocalHost().getCanonicalHostName()
        );
    } catch (UnknownHostException e) {
        canonicalHostName = "unknown";
    }

    accessLogEnabled = config.getBoolean("graylog2.appender.access-log", false);

    final GelfConfiguration gelfConfiguration = getGelfConfiguration(config);

    GelfTransport transport = GelfTransports.create(gelfConfiguration);

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    final Logger rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);

    gelfClientAppender = new GelfClientAppender(transport, canonicalHostName);

    gelfClientAppender.setContext(lc);

    gelfClientAppender.start();

    rootLogger.addAppender(gelfClientAppender);
}
 
开发者ID:tochkak,项目名称:play-graylog2,代码行数:30,代码来源:Graylog2Component.java


示例6: getGelfConfiguration

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
private GelfConfiguration getGelfConfiguration() {

        final InetSocketAddress serverAddress = new InetSocketAddress(server, port);
        final GelfTransports gelfProtocol = GelfTransports.valueOf(protocol().toUpperCase());

        return new GelfConfiguration(serverAddress).transport(gelfProtocol)
            .queueSize(queueSize)
            .connectTimeout(connectTimeout)
            .reconnectDelay(reconnectDelay)
            .sendBufferSize(sendBufferSize)
            .tcpNoDelay(tcpNoDelay)
            .tcpKeepAlive(tcpKeepAlive);
    }
 
开发者ID:rkcpi,项目名称:logback-gelf-appender,代码行数:14,代码来源:GelfAppender.java


示例7: convertFrom

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Override
public GelfTransports convertFrom(String value) {
    try {
        return GelfTransports.valueOf(Strings.nullToEmpty(value).toUpperCase(Locale.ENGLISH));
    } catch (IllegalArgumentException e) {
        throw new ParameterException("Couldn't convert value \"" + value + "\" to GELF transport.", e);
    }
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:9,代码来源:GelfTransportsConverter.java


示例8: convertTo

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Override
public String convertTo(GelfTransports value) {
    if (value == null) {
        throw new ParameterException("Couldn't convert \"null\" to string.");
    }
    return value.name();
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:8,代码来源:GelfTransportsConverter.java


示例9: GraylogUplink

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
public GraylogUplink(String hostname, int port, String nzymeId, String networkInterfaceName) {
    this.nzymeId = nzymeId;
    this.networkInterfaceName = networkInterfaceName;

    this.gelfTransport = GelfTransports.create(new GelfConfiguration(new InetSocketAddress(hostname, port))
            .transport(GelfTransports.TCP)
            .queueSize(512)
            .connectTimeout(5000)
            .reconnectDelay(1000)
            .tcpNoDelay(true)
            .sendBufferSize(32768));
}
 
开发者ID:lennartkoopmann,项目名称:nzyme,代码行数:13,代码来源:GraylogUplink.java


示例10: getRequiredLogEntryValuesIncludesAdditionalFields

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Test
public void getRequiredLogEntryValuesIncludesAdditionalFields() {
    final Writer gelfWriter = new GelfWriter("localhost", 12201, GelfTransports.UDP, "localhost",
            EnumSet.of(LogEntryValue.EXCEPTION, LogEntryValue.PROCESS_ID), Collections.<String, Object>emptyMap(),
            512, 1000, 500, -1, false);

    assertThat(gelfWriter.getRequiredLogEntryValues(), hasItems(
            LogEntryValue.DATE, LogEntryValue.LEVEL, LogEntryValue.RENDERED_LOG_ENTRY,
            LogEntryValue.EXCEPTION, LogEntryValue.PROCESS_ID));
}
 
开发者ID:joschi,项目名称:tinylog-gelf,代码行数:11,代码来源:GelfWriterTest.java


示例11: Graylog2Plugin

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
public Graylog2Plugin(Application app) {
    final Configuration config = app.configuration();

    accessLogEnabled = config.getBoolean("graylog2.appender.send-access-log", false);
    queueCapacity = config.getInt("graylog2.appender.queue-size", 512);
    reconnectInterval = config.getMilliseconds("graylog2.appender.reconnect-interval", 500L);
    connectTimeout = config.getMilliseconds("graylog2.appender.connect-timeout", 1000L);
    isTcpNoDelay = config.getBoolean("graylog2.appender.tcp-nodelay", false);
    sendBufferSize = config.getInt("graylog2.appender.sendbuffersize", 0); // causes the socket default to be used
    try {
        canonicalHostName = config.getString("graylog2.appender.sourcehost", InetAddress.getLocalHost().getCanonicalHostName());
    } catch (UnknownHostException e) {
        canonicalHostName = "localhost";
        log.error("Unable to resolve canonical localhost name. " +
                "Please set it manually via graylog2.appender.sourcehost or fix your lookup service, falling back to {}", canonicalHostName);
    }
    // TODO make this a list and dynamically accessible from the application
    final String hostString = config.getString("graylog2.appender.host", "127.0.0.1:12201");
    final String protocol = config.getString("graylog2.appender.protocol", "tcp");

    final HostAndPort hostAndPort = HostAndPort.fromString(hostString);

    final GelfTransports gelfTransport = GelfTransports.valueOf(protocol.toUpperCase());

    final GelfConfiguration gelfConfiguration = new GelfConfiguration(hostAndPort.getHostText(), hostAndPort.getPort())
            .transport(gelfTransport)
            .reconnectDelay(reconnectInterval.intValue())
            .queueSize(queueCapacity)
            .connectTimeout(connectTimeout.intValue())
            .tcpNoDelay(isTcpNoDelay)
            .sendBufferSize(sendBufferSize);

    this.transport = GelfTransports.create(gelfConfiguration);

    final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    rootLogger = lc.getLogger(Logger.ROOT_LOGGER_NAME);

    gelfAppender = new GelfclientAppender(transport, getLocalHostName());
    gelfAppender.setContext(lc);
}
 
开发者ID:graylog-labs,项目名称:play2-graylog2,代码行数:41,代码来源:Graylog2Plugin.java


示例12: GelfOutputConfiguration

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Inject
public GelfOutputConfiguration(@Assisted String id,
                               @Assisted Config config,
                               GelfOutput.Factory outputFactory) {
    super(id, config);
    this.outputFactory = outputFactory;

    if (config.hasPath("protocol")) {
        switch (config.getString("protocol").toUpperCase(Locale.ENGLISH)) {
            case "UDP":
                this.protocol = GelfTransports.UDP;
                break;
            case "TCP":
            default:
                this.protocol = GelfTransports.TCP;
                break;
        }
    }
    if (config.hasPath("host")) {
        this.host = config.getString("host");
    }
    if (config.hasPath("port")) {
        this.port = config.getInt("port");
    }
    if (config.hasPath("client-tls")) {
        this.clientTls = config.getBoolean("client-tls");
    }
    if (config.hasPath("client-tls-cert-chain-file")) {
        this.clientTlsCertChainFile = new File(config.getString("client-tls-cert-chain-file"));
    }
    if (config.hasPath("client-tls-verify-cert")) {
        this.clientTlsVerifyCert = config.getBoolean("client-tls-verify-cert");
    }
    if (config.hasPath("client-queue-size")) {
        this.clientQueueSize = config.getInt("client-queue-size");
    }
    if (config.hasPath("client-connect-timeout")) {
        this.clientConnectTimeout = config.getInt("client-connect-timeout");
    }
    if (config.hasPath("client-reconnect-delay")) {
        this.clientReconnectDelay = config.getInt("client-reconnect-delay");
    }
    if (config.hasPath("client-tcp-no-delay")) {
        this.clientTcpNoDelay = config.getBoolean("client-tcp-no-delay");
    }
    if (config.hasPath("client-send-buffer-size")) {
        this.clientSendBufferSize = config.getInt("client-send-buffer-size");
    }
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:50,代码来源:GelfOutputConfiguration.java


示例13: getProtocol

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
public GelfTransports getProtocol() {
    return protocol;
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:4,代码来源:GelfOutputConfiguration.java


示例14: getTransport

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
public GelfTransports getTransport() {
    return transport;
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:4,代码来源:MetricsGelfReporterConfiguration.java


示例15: convertFromValidString

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Test
public void convertFromValidString() throws Exception {
    Assert.assertEquals(GelfTransports.UDP, new GelfTransportsConverter().convertFrom("UDP"));
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:5,代码来源:GelfTransportsConverterTest.java


示例16: convertFromValidLowerCaseString

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Test
public void convertFromValidLowerCaseString() throws Exception {
    assertEquals(GelfTransports.TCP, new GelfTransportsConverter().convertFrom("tcp"));
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:5,代码来源:GelfTransportsConverterTest.java


示例17: convertTo

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Test
public void convertTo() throws Exception {
    assertEquals("UDP", new GelfTransportsConverter().convertTo(GelfTransports.UDP));
}
 
开发者ID:graylog-labs,项目名称:graylog-plugin-metrics-reporter,代码行数:5,代码来源:GelfTransportsConverterTest.java


示例18: start

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
@Override
public void start() {
    super.start();
    client = GelfTransports.create(gelfConfiguration);
}
 
开发者ID:graylog-labs,项目名称:log4j2-gelf,代码行数:6,代码来源:GelfAppender.java


示例19: testWrite

import org.graylog2.gelfclient.GelfTransports; //导入依赖的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


示例20: createGelfClient

import org.graylog2.gelfclient.GelfTransports; //导入依赖的package包/类
private void createGelfClient() {

        client = GelfTransports.create(getGelfConfiguration());
    }
 
开发者ID:rkcpi,项目名称:logback-gelf-appender,代码行数:5,代码来源:GelfAppender.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Filter类代码示例发布时间:2022-05-22
下一篇:
Java ProgressEventType类代码示例发布时间: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