Skip to content

Commit a6abd90

Browse files
Elliot ForbesElliot Forbes
authored andcommitted
Updated the readme
1 parent d8f5f38 commit a6abd90

1 file changed

Lines changed: 36 additions & 10 deletions

File tree

README.md

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
1-
ctx-logger
1+
ctxlog - the simple context logger
22
===========
33

4+
ctxlog looks to simplify the way that we handle observability through the various layers of our Go applications.
5+
6+
The idea is that, when a request hits the left-most edge of our application, we can append information such as request ids and trace ids to the context. This will then be automagically added to all subsequent log messages for that particular request context.
7+
8+
## Installation
9+
10+
```shell
11+
$ go get github.com/TutorialEdge/ctxlog
12+
```
13+
14+
## Example Code
15+
16+
A picture is worth a thousand words, a code snippet is likely worth a lot less than that, but it hopefully highlights how this simplifies our lives.
417

518
```go
619
ctx := context.Background()
7-
log := ctxlog.New(
8-
ctxlog.WithJSONFormat(),
9-
)
10-
ctx = ctxlog.WithFields(ctx, ctxlog.Fields{
11-
"trace_id": "my-trace-id",
12-
})
13-
14-
log.Info(ctx, "hello world")
15-
```
20+
log := ctxlog.New(
21+
ctxlog.WithJSONFormat(),
22+
)
23+
ctx = ctxlog.WithFields(ctx, ctxlog.Fields{
24+
"trace_id": "my-trace-id",
25+
})
26+
27+
log.Info(ctx, "hello world")
28+
// {"level":"info","msg":"hello world","time":"2022-07-23T12:01:43+01:00","trace_id":"my-trace-id"}
29+
log.Error(ctx, "oh my goodness")
30+
// {"level":"error","msg":"oh my goodness","time":"2022-07-23T12:01:43+01:00","trace_id":"my-trace-id"}
31+
```
32+
33+
## Contributing
34+
35+
This is a very early rendition of this package. I'll likely expand this out as I start to adopt it in TutorialEdge's services.
36+
37+
If you'd like to accelerate the development, feel free to submit a Pull Request.
38+
39+
## Attribution
40+
41+
It should be noted this was heavily inspired by the usability of a library developed within CircleCI for our Go applications. I've distilled some of the core concepts down into this far smaller, focused library.

0 commit comments

Comments
 (0)