https://github.com/sha1n/gostash
A utility on top of logrus for structured logging and tracing in logstash json format.
https://github.com/sha1n/gostash
golang logging logrus logstash trace
Last synced: 11 months ago
JSON representation
A utility on top of logrus for structured logging and tracing in logstash json format.
- Host: GitHub
- URL: https://github.com/sha1n/gostash
- Owner: sha1n
- License: mit
- Created: 2018-11-04T09:44:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-31T21:56:07.000Z (over 3 years ago)
- Last Synced: 2025-01-20T08:14:08.538Z (over 1 year ago)
- Topics: golang, logging, logrus, logstash, trace
- Language: Go
- Homepage:
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/sha1n/gostash/actions/workflows/go.yml)
# gostash
A utility on top of [logrus](https://github.com/sirupsen/logrus) for structured logging and tracing in logstash json format.
## Usage Example: (see /example.go)
```go
package main
import (
"github.com/sha1n/gostash/logging"
)
func main() {
logging.SetLogConfig(
logging.Config{
FileName: "./test.log",
Level: "info",
Properties: logging.LogProperties{
DcName: "east",
ServiceName: "my-service",
InstanceName: "my-instance",
},
})
baseEntry := logging.
NewEntry("test").
WithField("user", "me")
// start a trace segment
traceSegment := logging.
NewTrace("traceAction", baseEntry).
StartSegment("segment-1")
// your business logic here...
// end a trace segment with error
traceSegment.End()
}
```
### Segment start document:
```json
{
"@timestamp": "2018-11-04T15:35:38.041+02:00",
"action": "traceAction",
"dc": "east",
"instance": "my-instance",
"level": "info",
"marker": "start",
"message": "",
"name": "test",
"segment": "segment-1",
"service": "my-service",
"trace_id": "81775219-3a91-443c-b77d-b8996337952f",
"user": "me"
}
```
### Segment end document:
```json
{
"@timestamp": "2018-11-04T15:35:38.041+02:00",
"action": "traceAction",
"dc": "east",
"duration_sec": 0.000062782,
"instance": "my-instance",
"level": "info",
"marker": "end",
"message": "",
"name": "test",
"segment": "segment-1",
"service": "my-service",
"trace_id": "81775219-3a91-443c-b77d-b8996337952f",
"user": "me"
}
```