-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
32 lines (25 loc) · 900 Bytes
/
main.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
// The purpose of this example is to show how to integrate with apex/log.
package main
import (
"github.com/apex/log"
adapter "github.com/axiomhq/axiom-go/adapters/apex"
)
func main() {
// Export "AXIOM_DATASET" in addition to the required environment variables.
// 1. Setup the Axiom handler for apex.
handler, err := adapter.New()
if err != nil {
log.Fatal(err.Error())
}
// 2. Have all logs flushed before the application exits.
//
// ❗THIS IS IMPORTANT❗ Without it, the logs will not be sent to Axiom as
// the buffer will not be flushed when the application exits.
defer handler.Close()
// 3. Set the Axiom handler as handler for apex.
log.SetHandler(handler)
// 4. Log ⚡
log.WithField("mood", "hyped").Info("This is awesome!")
log.WithField("mood", "worried").Warn("This is no that awesome...")
log.WithField("mood", "depressed").Error("This is rather bad.")
}