在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:logfellow/logstash-logback-encoder开源软件地址:https://github.com/logfellow/logstash-logback-encoder开源编程语言:Java 99.8%开源软件介绍:
Logstash Logback EncoderProvides logback encoders, layouts, and appenders to log in JSON and other formats supported by Jackson. Supports both regular LoggingEvents (logged through a Originally written to support output in logstash's JSON format, but has evolved into a highly-configurable, general-purpose, structured logging mechanism for JSON and other Jackson dataformats. The structure of the output, and the data it contains, is fully configurable. Contents:
Including it in your projectMaven style: <dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.2</version>
<!-- Use runtime scope if the project does not have any compile-time usage of logstash-logback-encoder,
such as usage of StructuredArguments/Markers or implementations such as
JsonProvider, AppenderListener, JsonFactoryDecorator, JsonGeneratorDecorator, etc
<scope>runtime</scope>
-->
</dependency>
<!-- Your project must also directly depend on either logback-classic or logback-access. For example: -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<!-- Use runtime scope if the project does not have any compile-time usage of logback,
such as implementations of Appender, Encoder, Layout, TurboFilter, etc
<scope>runtime</scope>
-->
</dependency> If you get
Older versions than the ones specified in the pom file might work, but the versions in the pom file are what testing has been performed against. Support for logback versions prior to 1.2.0 was removed in logstash-logback-encoder 7.0. If you are using logstash-logback-encoder in a project (such as spring-boot) that also declares dependencies on any of the above libraries, you might need to tell maven explicitly which versions to use to avoid conflicts. You can do so using maven's dependencyManagement feature. For example, to ensure that maven doesn't pick different versions of logback-core, logback-classic, and logback-access, add this to your project's pom.xml <properties>
<logback.version>1.2.6</logback.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-access</artifactId>
<version>${logback.version}</version>
</dependency>
</dependencies>
</dependencyManagement> Java Version Requirements
UsageTo log using JSON format, you must configure logback to use either:
The appenders, encoders, and layouts provided by the logstash-logback-encoder library are as follows:
These encoders/layouts can generally be used by any logback appender (such as The general composite JSON encoders/layouts can be used to output any JSON format/data by configuring them with various JSON providers. The Logstash encoders/layouts are really just extensions of the general composite JSON encoders/layouts with a pre-defined set of providers. The logstash encoders/layouts are easier to configure if you want to use the standard logstash version 1 output format. Use the composite encoders/layouts if you want to heavily customize the output, or if you need to use logstash version 0 output. The UDP AppenderTo output JSON for LoggingEvents to a syslog/UDP channel,
use the <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stash" class="net.logstash.logback.appender.LogstashUdpSocketAppender">
<host>MyAwesomeSyslogServer</host>
<!-- port is optional (default value shown) -->
<port>514</port>
<!-- layout is required -->
<layout class="net.logstash.logback.layout.LogstashLayout"/>
</appender>
<root level="all">
<appender-ref ref="stash" />
</root>
</configuration> You can further customize the JSON output by customizing the layout as described in later sections. For example, to configure global custom fields, you can specify <appender name="stash" class="net.logstash.logback.appender.LogstashUdpSocketAppender">
<host>MyAwesomeSyslogServer</host>
<!-- port is optional (default value shown) -->
<port>514</port>
<layout class="net.logstash.logback.layout.LogstashLayout">
<customFields>{"appname":"myWebservice"}</customFields>
</layout>
</appender> To output JSON for AccessEvents over UDP, use a <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stash" class="net.logstash.logback.appender.LogstashAccessUdpSocketAppender">
<host>MyAwesomeSyslogServer</host>
<!-- port is optional (default value shown) -->
<port>514</port>
<layout class="net.logstash.logback.layout.LogstashAccessLayout">
<customFields>{"appname":"myWebservice"}</customFields>
</layout>
</appender>
<appender-ref ref="stash" />
</configuration> To receive syslog/UDP input in logstash, configure a
TCP AppendersTo output JSON for LoggingEvents over TCP, use a <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:4560</destination>
<!-- encoder is required -->
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
<root level="DEBUG">
<appender-ref ref="stash" />
</root>
</configuration> To output JSON for AccessEvents over TCP, use a <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="stash" class="net.logstash.logback.appender.LogstashAccessTcpSocketAppender">
<destination>127.0.0.1:4560</destination>
<!-- encoder is required -->
<encoder class="net.logstash.logback.encoder.LogstashAccessEncoder" />
</appender>
<appender-ref ref="stash" />
</configuration> The TCP appenders use an encoder, rather than a layout as the UDP appenders .
You can use a Internally, the TCP appenders are asynchronous (using the LMAX Disruptor RingBuffer).
All the encoding and TCP communication is delegated to a single writer thread.
There is no need to wrap the TCP appenders with another asynchronous appender
(such as All the configuration parameters (except for sub-appender) of the async appenders
are valid for TCP appenders. For example, The TCP appenders will never block the logging thread. If the RingBuffer is full (e.g. due to slow network, etc), then events will be dropped. The TCP appenders will automatically reconnect if the connection breaks. However, events may be lost before Java's socket realizes the connection has broken. To receive TCP input in logstash, configure a
In order to guarantee that logged messages have had a chance to be processed by the TCP appender, you'll need to cleanly shut down logback when your application exits. Keep-AliveIf events occur infrequently, and the connection breaks consistently due to a server-side idle timeout,
then you can enable keep alive functionality by configuring a <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
...
<keepAliveDuration>5 minutes</keepAliveDuration>
</appender> This setting accepts a Logback Duration value - see the section dedicated to Duration Property for more information about the valid values. When the
Any other value will be used as-is. The keep alive message is encoded in Multiple DestinationsThe TCP appenders can be configured to try to connect to one of several destinations like this: <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>destination1.domain.com:4560</destination>
<destination>destination2.domain.com:4560</destination>
<destination>destination3.domain.com:4560</destination>
...
</appender> or this: <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>
destination1.domain.com:4560,
destination2.domain.com:4560,
destination3.domain.com:4560
</destination>
...
</appender> The appender uses a
Logs are only sent to one destination at a time (i.e. not all destinations). By default, the appender will stay connected to the connected destination until it breaks, or until the application is shut down. Some connection strategies can force a reconnect (see below). If a connection breaks, then the appender will attempt to connect to the next destination selected by the connection strategy. The available connection strategies are as follows:
You can also use your own custom connection strategy by implementing the <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>destination1.domain.com:4560</destination>
<destination>destination2.domain.com:4560</destination>
<destination>destination3.domain.com:4560</destination>
<connectionStrategy class="your.package.YourDestinationConnectionStrategy">
</connectionStrategy>
</appender> Reconnection DelayBy default, the TCP appender will wait 30 seconds between connection attempts to a single destination. The time between connection attempts to each destination is tracked separately. This amount of time to delay can be changed by setting the <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
...
<reconnectionDelay>1 second</reconnectionDelay>
</appender> This setting accepts a Logback Duration value - see the section dedicated to Duration Property for more information about the valid values. Connection TimeoutBy default, a connection timeout of 5 seconds is used when connecting to a remote destination.
You can adjust this by setting the appender's <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
...
<connectionTimeout>5 seconds</connectionTimeout>
</appender> A value of This setting accepts a Logback Duration value - see the section dedicated to Duration Property for more information about the valid values. Write Buffer SizeBy default, a buffer size of 8192 is used to buffer socket output stream writes.
You can adjust this by setting the appender's <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
...
<writeBufferSize>16384</writeBufferSize>
</appender> Buffering can be disabled by setting the Write TimeoutsIf a destination stops reading from its socket input, but does not close the connection, then writes from the TCP appender will eventually backup, causing the ring buffer to backup, causing events to be dropped. To detect this situation, you can enable a write timeout, so that "stuck" writes will eventually timeout, at which point the connection will be re-established. When the write buffer is enabled, any buffered data will be lost when the connection is reestablished. By default there is no write timeout. To enable a write timeout, do the following: <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
...
<writeTimeout>1 minute</writeTimeout>
</appender> Note that since the blocking java socket output stream used to send events does not have a concept of a write timeout, write timeouts are detected using a task scheduled periodically with the same frequency as the write timeout. For example, if the write timeout is set to 30 seconds, then a task will execute every 30 seconds to see if 30 seconds has elapsed since the start of the current write operation. Therefore, it is recommended to use longer write timeouts (e.g. > 30s, or minutes), rather than short write timeouts, so that this task does not execute too frequently. Also, this approach means that it could take up to two times the write timeout before a write timeout is detected. The write timeout must be >0. A timeout of zero is interpreted as an infinite timeout which effecively means "no write timeout". This setting accepts a Logback Duration value - see the section dedicated to Duration Property for more information about the valid values. SSLTo use SSL, add an See the logback manual for how to configure SSL.
SSL for the For example, to enable SSL using the JVM's default keystore/truststore, do the following: <appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
...
<!-- Enable SSL using the JVM's default keystore/truststore -->
<ssl/>
</appender> To use a different truststore, do the following: 全部评论
专题导读
上一篇:contiv/vpp: Kubernetes CNI plugin based on FD.io VPP发布时间:2022-07-09下一篇:s-yadav/jsonQ: A JavaScript library to make manipulation and extraction of data ...发布时间:2022-07-08热门推荐
热门话题
阅读排行榜
|
请发表评论