https://github.com/oresoftware/json-logging
Log JSON to stdout for important services and easy log inspection.
https://github.com/oresoftware/json-logging
go-library go-module go-modules golang golang-library json logging
Last synced: 24 days ago
JSON representation
Log JSON to stdout for important services and easy log inspection.
- Host: GitHub
- URL: https://github.com/oresoftware/json-logging
- Owner: ORESoftware
- Created: 2020-02-06T02:39:32.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-05T21:27:34.000Z (over 1 year ago)
- Last Synced: 2024-08-06T00:31:31.340Z (over 1 year ago)
- Topics: go-library, go-module, go-modules, golang, golang-library, json, logging
- Language: Go
- Homepage:
- Size: 186 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# @oresoftware/json-logging
### json-logging is:
>
> * very high-performance
> * developer friendly
> * opinionated
> * only writes to stdout, never to stderr
>
### json-logging accomplishes two things:
1. When stdout is connected to a terminal (tty), it writes beautiful output like so:
2. When stdout is not connected to a tty, then it writes optimized JSON in an array form:
To force the use of JSON output, you can do:
```bash
myapp | cat
```
or set an env var:
```bash
jlog_force_json=yes myapp
```
### Implementation details / features
1. Handles pointers, structs, slices/arrays, maps, and primitives
2. Includes facilities for easily writing raw serialized data (string, byte) to stdout (and stderr if you want).
3. The array format is optimized for performance and also developer friendliness since it is much less verbose.
### The array format:
```
[date, level, appname, pid, hostname, {customFields}, [...messages]]
```
Custom fields are used to filter the logs easily, for example if you want to filter the logs by request id:
```
[date, level, appname, pid, hostname, {requestId: ""}, [...messages]]
```
where requestId is a uuid for a particular request to an HTTP server.