forked from nownabe/clog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc.go
61 lines (47 loc) · 1.98 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Package clog is a structured logger optimized for [Cloud Logging] based on [log/slog].
clog supports following special fields in JSON log entries:
- severity
- message
- httpRequest
- time
- logging.googleapis.com/insertId
- logging.googleapis.com/labels
- logging.googleapis.com/operation
- logging.googleapis.com/sourceLocation
- logging.googleapis.com/spanId
- logging.googleapis.com/trace
- logging.googleapis.com/trace_sampled
- logging.googleapis.com/stack_trace
See [Cloud Logging documentation] and [Cloud Error Reporting documentation] for more details.
# Severity
clod uses [Severity] in the "severity" field instead of log levels. 8 severities are supported:
- DEBUG
- INFO
- NOTICE
- WARNING
- ERROR
- CRITICAL
- ALERT
- EMERGENCY
# Usage
Each severity has three methods like [Info], [Infof], and [InfoErr].
clog.Info(ctx, "simple logging with args", "key", "value")
// {"severity":"INFO", "message":"simple logging with args", "key":"value",
// "time": "...", "logging.googleapis.com/sourceLocation": {...}}
clog.Noticef(ctx, "formatted message %s %s", "like", "fmt.Printf")
// {"severity":"NOTICE", "message":"formatted message like fmt.Printf",
// "time": "...", "logging.googleapis.com/sourceLocation": {...}}
clog.CriticalErr(ctx, errors.New("critical error!!"), "key", "value")
// {"severity":"CRITICAL", "message":"critical error!!", "key":"value",
// "time": "...", "logging.googleapis.com/sourceLocation": {...}}
// clog.ErrorErr has a shorthand clog.Err.
clog.Err(ctx, errors.New("error!"))
// {"severity":"ERROR", "message":"error!",
// "time": "...", "logging.googleapis.com/sourceLocation": {...}}
See [Examples] for more details.
[Cloud Logging]: https://cloud.google.com/logging
[Cloud Logging documentation]: https://cloud.google.com/logging/docs/structured-logging
[Cloud Error Reporting documentation]: https://cloud.google.com/error-reporting/docs/formatting-error-messages
*/
package clog // import "go.nownabe.dev/clog"