Git Product home page Git Product logo

logzio-log4j2-appender's Introduction

Logzio Log4j 2 Appender

Log4j 2 Appender that ships logs using HTTPS bulk Build Status Maven Central

This appender sends logs to your Logz.io account, using non-blocking threading, bulks, and HTTPS encryption. Please note that this appender requires log4j version 2.7 and up, and java 8 and up.

Technical Information

This appender uses LogzioSender implementation. Once you send a log, it will be enqueued in the buffer and 100% non-blocking. There is a background task that will handle the log shipment for you. This jar is an "Uber-Jar" that shades both LogzioSender, BigQueue, Gson and Guava to avoid "dependency hell".

Installation from maven

    <dependency>
        <groupId>io.logz.log4j2</groupId>
        <artifactId>logzio-log4j2-appender</artifactId>
        <version>1.0.7</version>
    </dependency>

Log4 2 Example Configuration

    <Appenders>
        <LogzioAppender name="Logzio">
            <logzioToken>your-logzio-personal-token-from-settings</logzioToken>
            <logzioType>myAwesomeType</logzioType>
            <logzioUrl>https://listener.logz.io:8071</logzioUrl>
        </LogzioAppender>
       
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="Logzio"/>
        </Root>
    </Loggers>

Parameters

Parameter Default Explained
logzioToken None Your Logz.io token, which can be found under "settings" in your account, If the value begins with $ then the appender looks for an environment variable with the name specified. For example: $LOGZIO_TOKEN will look for environment variable named LOGZIO_TOKEN
logzioType java The log type for that appender, it must not contain any spaces
logzioUrl https://listener.logz.io:8071 The url that the appender sends to. If your account is in the EU you must use https://listener-eu.logz.io:8071
drainTimeoutSec 5 How often the appender should drain the buffer (in seconds)
fileSystemFullPercentThreshold 98 The percent of used file system space at which the appender will stop buffering. When we will reach that percentage, the file system in which the buffer is stored will drop all new logs until the percentage of used space drops below that threshold. Set to -1 to never stop processing new logs
bufferDir System.getProperty("java.io.tmpdir") Where the appender should store the buffer
socketTimeoutMs 10 * 1000 The socket timeout during log shipment
connectTimeoutMs 10 * 1000 The connection timeout during log shipment
addHostname false Optional. If true, then a field named 'hostname' will be added holding the host name of the machine. If from some reason there's no defined hostname, this field won't be added
additionalFields None Optional. Allows to add additional fields to the JSON message sent. The format is "fieldName1=fieldValue1;fieldName2=fieldValue2". You can optionally inject an environment variable value using the following format: "fieldName1=fieldValue1;fieldName2=$ENV_VAR_NAME". In that case, the environment variable should be the only value. In case the environment variable can't be resolved, the field will be omitted.
debug false Print some debug messages to stdout to help to diagnose issues
compressRequests false Boolean. true if logs are compressed in gzip format before sending. false if logs are sent uncompressed.

Code Example

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class LogzioLog4j2Example {

    public static void main(String[] args) {
        Logger logger = LogManager.getLogger(LogzioLog4j2Example.class);
        
        logger.info("Testing logz.io!");
        logger.warn("Winter is coming");
    }
}

MDC

Each key value you will add to MDC will be added to each log line as long as the thread alive. No further configuration needed.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.ThreadContext;

public class LogzioLog4j2Example {

    public static void main(String[] args) {
        Logger logger = LogManager.getLogger(LogzioLog4j2Example.class);

        ThreadContext.put("Key", "Value");
        logger.info("This log will hold the MDC data as well");
    }
}

Will send a log to Logz.io that looks like this:

{
    "message": "This log will hold the MDC data as well",
    "Key": "Value",
    ... (all other fields you used to get)
}

Marker

Markers are named objects used to enrich log statements, so each log line will be enriched with its own. No further configuration needed.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;

public class LogzioLog4j2Example {

    public static void main(String[] args) {
        Logger logger = LogManager.getLogger(LogzioLog4j2Example.class);

        Marker marker = MarkerManager.getMarker("Fatal");
        logger.error(marker, "This line has a fatal error");
    }
}

Will send a log to Logz.io that looks like this:

{
    "message": "This line has a fatal error",
    "Marker": "Fatal",
    ... (all other fields you used to get)
}

Release notes

Contribution

  • Fork
  • Code
  • mvn test
  • Issue a PR :)

logzio-log4j2-appender's People

Contributors

marinarazumovsky avatar roiravhon avatar schwin007 avatar abdel avatar idohalevi avatar

Watchers

James Cloos avatar  avatar

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.