Giter Site home page Giter Site logo

gcloud-logging-slf4j-logback's Introduction

gcloud-logging json log appender for sl4j + logback

Build Status Maven Central

This library provides a simple json based layout that can be used to send structured logs to gcloud logging.

This appender is particularly useful in Google Container Engine where logs should be emitted to stdout.

Stackdriver fluentd plugin implementation

https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud/blob/master/lib/fluent/plugin/out_google_cloud.rb

Is this production ready?

Yes.

Usage

Add dependency to build.gradle:

dependencies {
    // refer to badge for latest version
    compile 'com.github.ankurcha:google-cloud-logging-logback-slf4j:LATEST'
}

or to maven pom.xml:

<dependency>
    <groupId>com.github.ankurcha</groupId>
    <artifactId>google-cloud-logging-logback-slf4j</artifactId>
    <version>LATEST</version>
</dependency>

Add entry to logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="KUBE_CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
            <layout class="com.google.cloud.logging.GoogleCloudLoggingV2Layout">
                <appendLineSeparator>true</appendLineSeparator>
                <serviceName>@service-name@</serviceName>
                <serviceVersion>@git.sha@</serviceVersion>
                <jsonFormatter class="com.google.cloud.logging.GSONJsonFormatter"/>
            </layout>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="KUBE_CONSOLE"/>
    </root>

</configuration>

Example log line (prettified here):

{
   "severity":"INFO",
   "logging.googleapis.com/trace": "projects/<project-id>/traces/<trace_id>",
   "logging.googleapis.com/spanId": "<span_id>",
   "context":{
      "reportLocation":{
         "functionName":"org.springframework.web.servlet.FrameworkServlet.initServletBean",
         "filePath":"org/springframework/web/servlet/FrameworkServlet.class",
         "logger":"org.springframework.web.servlet.DispatcherServlet",
         "thread":"http-nio-8080-exec-1",
         "lineNumber":508
      }
   },
   "serviceContext":{
      "version":"dc23b8d342e95b48a80219a2af67388b1c1a52d0",
      "service":"ferric"
   },
   "message":"FrameworkServlet \u0027dispatcherServlet\u0027: initialization completed in 27 ms",
   "timestamp":{
      "seconds":1478201184,
      "nanos":753000000
   }
}

Adding trace context (since 1.1.7)

Add an argument to the log statement of type com.google.cloud.logging.TraceContext with trace and spanId if available. Trace id should be of the format: projects/<project-id>/traces/<trace_id> where project-id is the gcp project id and trace_id is the 16-character hexadecimal encoding of the trace id. Similarly for the <span-id>.

Adding http request context (since 1.1.8)

Add an argument to the log statement of type com.google.cloud.logging.HttpRequestContext to provide the httpRequest fields. This field will be emitted as the httpRequest field in the output.

Source location (since 1.1.9)

The source location is now populated as the logging.googleapis.com/sourceLocation field when available.

TODO

  • Update in readme
  • Add some tests for the formatter

gcloud-logging-slf4j-logback's People

Contributors

ankurcha avatar maresja1 avatar pavel-kurnosov avatar vvakame 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

Watchers

 avatar  avatar  avatar  avatar

gcloud-logging-slf4j-logback's Issues

Difference between gcloud-logging-slf4j-logback and google-cloud-logging-logback?

Hi.
What is the difference between google-cloud-logging-logback-slf4j and Google's google-cloud-logging-logback?
Doesn't https://github.com/googleapis/google-cloud-java/tree/master/google-cloud-clients/google-cloud-contrib/google-cloud-logging-logback already produce a JSON formatted log entry?
Please bear with me if this question seems inexperienced.
Greetings
Carlo

P.S.: It seems like the website http://blog.malloc64.com/ linked in your profile is no longer working.

Add License

Hi, Could you add a license file to the project? Preferably MIT, BSD or Apache 2?

Support logging of additional context fields

some libraries add fields to the log-contexts. currently there is no way to have such fields added to gcloud log messages. Usually these informations are part of the MDC (Mapped Diagnostic Context).

Example:

spring-sleuth adds a trace and span id to the log context (for tracing). having these fields in log messages is very useful to find all log messages that belong to a specific http request.

Solution:

add (filtered) MDC data to the json output (maybe the context field?)

see ILoggingEvent.getMDCPropertyMap()

https://github.com/logstash/logstash-logback-encoder/blob/ae1e3d91137d69b327f9977f096c145fbc893004/src/main/java/net/logstash/logback/composite/loggingevent/MdcJsonProvider.java

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.