Giter VIP home page Giter VIP logo

logback-gelf-appender's Introduction

GELF Appender for Logback

Build Status Maven Central

This logback appender logs messages to a Graylog server. It's using the official GELF Java client to connect to the remote server. It's inspired and influenced greatly by the Log4j2 GELF Appender.

The appender has several configurable properties:

  • server (default: localhost)
    • The host name or IP address of the GELF server
  • port (default: 12201)
    • The port the GELF server is listening on
  • hostName (default: the local host name or localhost if it couldn't be detected)
    • The host name of the machine generating the logs
  • protocol (default: UDP)
    • The transport protocol to use
  • includeSource (default: true)
    • Whether the source of the log message should be included
  • includeMDC (default: true)
  • includeStackTrace (default: true)
    • Whether a full stack trace should be included
  • includeLevelName (default: false)
    • Whether the log level's name should be included, e.g. 'WARN', 'INFO' ...
  • queueSize (default: 512)
    • The size of the internally used queue
  • connectTimeout (default: 1000)
    • The connection timeout for TCP connections in milliseconds
  • reconnectDelay (default: 500)
    • The time to wait between reconnects in milliseconds
  • sendBufferSize (default: -1)
    • The size of the socket send buffer in bytes. A size of -1 deactivates the send buffer
  • tcpNoDelay (default: false)
    • Whether Nagle's algorithm should be used for TCP connections
  • tcpKeepAlive (default: false)
    • Whether to try keeping alive TCP connections.
  • layout (default: "%m %n")
    • The Layout to use to format the LogEvent; the resulting string will be used as GELF's short_message (exception stacktraces are not included in this message)
  • additionalFields
    • Comma-delimited list of key=value pairs to be included in every message

Logback.xml example

<configuration debug="true">    
    <appender name="gelf" class="de.appelgriepsch.logback.GelfAppender">
        <server>localhost</server>
        <port>12201</port>
        <hostName>localhost</hostName>
        <protocol>UDP</protocol>
        <includeSource>true</includeSource>
        <includeMDC>true</includeMDC>
        <queueSize>512</queueSize>
        <connectTimeout>1000</connectTimeout>
        <reconnectDelay>500</reconnectDelay>
        <additionalFields>cow=moo,cat=meow</additionalFields>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%.-25m</pattern>
        </layout>
    </appender>
    <root level="DEBUG">
        <appender-ref ref="gelf" />
    </root>
</configuration>

License

GELF Appender for Logback

Copyright (C) 2019 Sandra Thieme [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

logback-gelf-appender's People

Contributors

augi avatar bujo avatar ced-b avatar ch4rms avatar dertobsch avatar emil-genov avatar sandra-thieme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

logback-gelf-appender's Issues

Release New Version

Hello,
can you please release a new version with updated gelfclient?

The latest released version has this two vulnerability:

✗ Medium severity vulnerability found on com.fasterxml.jackson.core:[email protected]
- desc: Denial of Service (DoS)
- from: de.appelgriepsch.logback:[email protected] > org.graylog2:[email protected] > com.fasterxml.jackson.core:[email protected]

✗ Medium severity vulnerability found on io.netty:[email protected]
- desc: Insecure Defaults
- from: de.appelgriepsch.logback:[email protected] > org.graylog2:[email protected] > io.netty:[email protected]

Thank you.
Best Regards,
Matteo

%logger is reported as null

I have the following appender configured

<appender name="GELF" class="de.appelgriepsch.logback.GelfAppender">
    <server>my_server_dns</server>
    <port>12201</port>
    <protocol>UDP</protocol>
    <includeSource>true</includeSource>
    <includeMDC>true</includeMDC>
    <includeLevelName>true</includeLevelName>
    <queueSize>512</queueSize>
    <layout class="ch.qos.logback.classic.PatternLayout">
       <pattern>%date [%level] from %logger - %message%n%xException</pattern>
    </layout>
</appender>

Everything works fine except the message is reported as follows in Graylog:

...[DEBUG] from null - Received blah blah blah...

I am wondering if I am doing something wrong with the %logger as it is reported as "null".

Full message is not included in data sent to graylog

The read me about layout says

The Layout to use to format the LogEvent; the resulting string will be used as GELF's short_message (exception stacktraces are not included in this message)

Problem is the full message is not sent (It is only sent if fullstack trace is on and there is an exception).

I would like the full message to always be sent...

It's a fairly trivial change

Unable to set different layout

I'm using your appender and it works very well. Now, I would like to truncate very long messages so I would like to set a custom layout. The README says it's possible to set it but I'm not able to make it working :(

<appender name="GRAYLOG" class="de.appelgriepsch.logback.GelfAppender">
        <server>my-server</server>
        <port>12201</port>
        <protocol>UDP</protocol>
        <includeLevelName>true</includeLevelName>
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%.255msg</pattern>
        </layout>
</appender>

Could you please update the README to contain how to setup custom layout correctly? It would be very useful for me. Thanks!

Additional fields with "comma"

I would like to pass a list of the active spring profiles via additional fields, but since there's a comma it does not work correctly.

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
  <include resource="org/springframework/boot/logging/logback/base.xml"/>
  <springProperty scope="context" name="name" source="spring.application.name"/>
  <springProperty scope="context" name="profiles" source="spring.profiles.active" defaultValue="default"/>

  <appender name="gelf" class="de.appelgriepsch.logback.GelfAppender">
    <server>192.168.1.113</server>
    <includeSource>true</includeSource>
    <includeMDC>true</includeMDC>
    <includeLevelName>true</includeLevelName>
    <additionalFields>profiles=${profiles},name=${name}</additionalFields>
  </appender>
  <root>
    <appender-ref ref="gelf"/>
  </root>
</configuration>

Host name is resolved once for each log message

If the host name is not supplied then the host name is resolved once per log message, which is an expensive syscall. This PR changes the behavior to resolve the host name once before the appender starts. This increased throughput by 15% for my benchmarks.

#18

[question] Immediate log send via UDP

Hello

I'm trying to use this appender for sending GELF logs via UDP. Unfortunately I can't force appender to send statements to Graylog server immediately.

I understand this is done intentionally to buffer output and optimize bandwidth usage, but for testing purposes it is really uncomfortable, because I have to multiple logging statements to make logs appear at Graylog server.

Is there any way to turn immediate sending on ?

Can run with `includeThreadContext`

With version 1.2.1, if I add <includeThreadContext>true</includeThreadContext> to my logback configuration in a SpringBoot application, the application does not start with the following exception. Everything works if I take that configuration out. I don't have this problem with 1.2.

java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.spi.Interpreter@18:31 - no applicable action for [includeThreadContext], current ElementPath  is [[configuration][appender][includeThreadContext]]
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:161)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:72)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:114)
    at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:299)
    at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:272)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:235)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:208)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:68)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:337)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:308)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)

question: possible to tell programatically whether communication to graylog is working?

I would love to be able to check (in code) whether communication with the graylog server is working. I could then add that check to a series of other status checks I use for a status URL. Then the load balancer and system monitoring tools can tell whether logging with GELF isn't working.

I've looked through the current source code and also the source code for org.graylog2:gelfclient:1.3.1, but so far haven't seen anything that might help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.