log4j2-json-layout


Лицензия

Лицензия

Категории

Категории

JSON Данные
Группа

Группа

org.zalando
Идентификатор

Идентификатор

log4j2-json-layout
Последняя версия

Последняя версия

1.0.0-RC1
Дата

Дата

Тип

Тип

jar
Описание

Описание

log4j2-json-layout
Ссылка на сайт

Ссылка на сайт

https://github.com/lukasniemeier-zalando/log4j2-json-layout
Система контроля версий

Система контроля версий

https://github.com/lukasniemeier-zalando/log4j2-json-layout

Скачать log4j2-json-layout

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.zalando/log4j2-json-layout/ -->
<dependency>
    <groupId>org.zalando</groupId>
    <artifactId>log4j2-json-layout</artifactId>
    <version>1.0.0-RC1</version>
</dependency>
// https://jarcasting.com/artifacts/org.zalando/log4j2-json-layout/
implementation 'org.zalando:log4j2-json-layout:1.0.0-RC1'
// https://jarcasting.com/artifacts/org.zalando/log4j2-json-layout/
implementation ("org.zalando:log4j2-json-layout:1.0.0-RC1")
'org.zalando:log4j2-json-layout:jar:1.0.0-RC1'
<dependency org="org.zalando" name="log4j2-json-layout" rev="1.0.0-RC1">
  <artifact name="log4j2-json-layout" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.zalando', module='log4j2-json-layout', version='1.0.0-RC1')
)
libraryDependencies += "org.zalando" % "log4j2-json-layout" % "1.0.0-RC1"
[org.zalando/log4j2-json-layout "1.0.0-RC1"]

Зависимости

compile (4)

Идентификатор библиотеки Тип Версия
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.2.30
org.apache.logging.log4j : log4j-api jar 2.7
org.apache.logging.log4j : log4j-core jar 2.7
com.fasterxml.jackson.core : jackson-databind jar 2.8.10

test (3)

Идентификатор библиотеки Тип Версия
com.google.code.gson : gson jar 2.7
org.junit.jupiter : junit-jupiter-api jar 5.1.0
org.junit.jupiter : junit-jupiter-engine jar 5.1.0

Модули Проекта

Данный проект не имеет модулей.

Log4J 2 JSON Layout Plugin

Build Status Release Maven Central License

A Log4J 2 layout plugin rendering structured JSON log lines. The goal of this plugin is to offer a minimal, concise and ready-to-be-used JSON log layout.

{"time":"2018-03-21T17:50:20.868Z","severity":"INFO","logger":"MyLogger","message":"Hello World","thread":"main"}
{"time":"2018-03-21T18:00:46.175Z","severity":"WARN","logger":"MyLogger","message":"Huch","thrown":{"class":"java.lang.IllegalStateException","stack":"..."},"thread":"main"}

This plugin only supports Log4J 2.7. This is a perfect match in case you are using Spring Boot 1.

Usage

Use this layout by configuring the SimpleJsonLayout it on your appender of choice. Make sure to expose the plugin to your Log4J instance (see here).

<Configuration packages="koeln.niemeier.log4j2.json">
    <Appenders>
        <Console name="stdout">
            <SimpleJsonLayout/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="info">
            <AppenderRef ref="stdout"/>
        </Root>
    </Loggers>
</Configuration>

Logging of Throwable

In case a Throwable is logged an additional object exception is rendered with the following fields.

  • thrown: the exception's class.
  • message: the exception's message (optional).
  • stack: the full stack trace serialized as an escaped string.
{
    "time": "2018-03-22T08:00:46.175Z"
    "logger": "logger",
    "severity": "WARN",
    "message": "Huch",
    "thread": "main",
    "exception": {
        "thrown": "java.lang.IllegalStateException",
        "message": "test",
        "stack":"java.lang.IllegalStateException: test\n\tat koeln.niemeier.log4j2.json.LoggingTest.testThrown(LoggingTest.kt:119) ~[classes/:?]\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_121]\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_121]\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_121]\n\tat java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_121]\n\t... suppressed 46 lines\n\tat com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:65) [junit5-rt.jar:?]\n\tat com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) [junit-rt.jar:?]\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) [junit-rt.jar:?]\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) [junit-rt.jar:?]\n",
    }
}

Customization

Currently the following options are available:

  • ignoredStackTracePackages: a comma-separated list of packages to be ignored on rendering the stack trace.

Example XML configuration fragment showing all possible options:

<SimpleJsonLayout ignoredStackTracePackages="org.junit.,java.util.,org.gradle."/>

Alternatives

There are many alternatives which may fit your use case better.

As I did not get them to work with Log4J 2 easily, I took inspiration from all of them.

Building

This project uses Kotlin with Gradle.

    $ ./gradlew clean build

Версии библиотеки

Версия
1.0.0-RC1