https://github.com/ankurcha/gcloud-logging-slf4j-logback
gcloud-logging json log appender for sl4j + logback
https://github.com/ankurcha/gcloud-logging-slf4j-logback
google-cloud-logging json sl4j-logback
Last synced: 5 months ago
JSON representation
gcloud-logging json log appender for sl4j + logback
- Host: GitHub
- URL: https://github.com/ankurcha/gcloud-logging-slf4j-logback
- Owner: ankurcha
- License: other
- Created: 2016-11-03T02:52:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-21T17:42:03.000Z (about 5 years ago)
- Last Synced: 2024-04-24T11:59:16.438Z (about 2 years ago)
- Topics: google-cloud-logging, json, sl4j-logback
- Language: Java
- Homepage:
- Size: 104 KB
- Stars: 32
- Watchers: 4
- Forks: 6
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gcloud-logging json log appender for sl4j + logback
[](https://travis-ci.org/ankurcha/gcloud-logging-slf4j-logback)
[](https://maven-badges.herokuapp.com/maven-central/com.github.ankurcha/google-cloud-logging-logback-slf4j)
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](https://cloud.google.com/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`:
```groovy
dependencies {
// refer to badge for latest version
compile 'com.github.ankurcha:google-cloud-logging-logback-slf4j:LATEST'
}
```
or to maven `pom.xml`:
```xml
com.github.ankurcha
google-cloud-logging-logback-slf4j
LATEST
```
Add entry to `logback.xml`
```xml
true
@service-name@
@git.sha@
```
Example log line (prettified here):
```json
{
"severity":"INFO",
"logging.googleapis.com/trace": "projects//traces/",
"logging.googleapis.com/spanId": "",
"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//traces/` where `project-id` is the gcp project id and
`trace_id` is the 16-character hexadecimal encoding of the trace id. Similarly for the ``.
## 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
* [x] Update in readme
* [ ] Add some tests for the formatter