diff --git a/adapters/apex/apex_test.go b/adapters/apex/apex_test.go index 3f0beeba..4f5bee82 100644 --- a/adapters/apex/apex_test.go +++ b/adapters/apex/apex_test.go @@ -42,10 +42,8 @@ func TestNew(t *testing.T) { } func TestHandler(t *testing.T) { - now := time.Now() - exp := fmt.Sprintf(`{"_time":"%s","severity":"info","key":"value","message":"my message"}`, - now.Format(time.RFC3339Nano)) + time.Now().Format(time.RFC3339Nano)) var hasRun uint64 hf := func(w http.ResponseWriter, r *http.Request) { @@ -53,7 +51,7 @@ func TestHandler(t *testing.T) { require.NoError(t, err) b, err := io.ReadAll(zsr) - assert.NoError(t, err) + require.NoError(t, err) testhelper.JSONEqExp(t, exp, string(b), []string{ingest.TimestampField}) diff --git a/adapters/logrus/logrus.go b/adapters/logrus/logrus.go index 6ecdef0e..765b5a95 100644 --- a/adapters/logrus/logrus.go +++ b/adapters/logrus/logrus.go @@ -3,7 +3,7 @@ package logrus import ( "context" "errors" - stdlog "log" + "log" "os" "sync" "time" @@ -134,7 +134,7 @@ func New(options ...Option) (*Hook, error) { go func() { defer close(hook.closeCh) - logger := stdlog.New(os.Stderr, "[AXIOM|LOGRUS]", 0) + logger := log.New(os.Stderr, "[AXIOM|LOGRUS]", 0) res, err := hook.client.IngestChannel(context.Background(), hook.datasetName, hook.eventCh, hook.ingestOptions...) if err != nil { diff --git a/adapters/zap/README.md b/adapters/zap/README.md index 7cf029f8..f36e22d3 100644 --- a/adapters/zap/README.md +++ b/adapters/zap/README.md @@ -46,6 +46,7 @@ core, err := adapter.New( ### ❗ Important ❗ The adapter uses a buffer to batch events before sending them to Axiom. This -buffer must be flushed explicitly by calling [Sync](https://pkg.go.dev/github.com/axiomhq/axiom-go/adapters/zap#WriteSyncer.Sync). Refer to the -[zap documentation](https://pkg.go.dev/go.uber.org/zap/zapcore#WriteSyncer) -for details and checkout out the [example](../../examples/zap/main.go). +buffer must be flushed explicitly by calling[Sync](https://pkg.go.dev/github.com/axiomhq/axiom-go/adapters/zap#WriteSyncer.Sync). +Refer to the +[zap documentation](https://pkg.go.dev/go.uber.org/zap/zapcore#WriteSyncer) for +details and checkout out the [example](../../examples/zap/main.go). diff --git a/adapters/zap/zap_test.go b/adapters/zap/zap_test.go index 7f002b59..1f362808 100644 --- a/adapters/zap/zap_test.go +++ b/adapters/zap/zap_test.go @@ -48,7 +48,7 @@ func TestCore(t *testing.T) { require.NoError(t, err) b, err := io.ReadAll(zsr) - assert.NoError(t, err) + require.NoError(t, err) assert.JSONEq(t, exp, string(b)) diff --git a/examples/logrus/main.go b/examples/logrus/main.go index 9db9c409..9cf4c7f0 100644 --- a/examples/logrus/main.go +++ b/examples/logrus/main.go @@ -22,21 +22,21 @@ func main() { // application exits in case of a "fatal" log operation. logrus.RegisterExitHandler(hook.Close) - // 3. Spawn the logger. + // 3. This makes sure logrus calls the registered exit handler. Alternaively + // hook.Close() can be called manually. It is safe to call multiple times. + // + // ❗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 logrus.Exit(0) + + // 4. Spawn the logger. logger := logrus.New() - // 4. Attach the Axiom hook. + // 5. Attach the Axiom hook. logger.AddHook(hook) - // 5. Log ⚡ + // 6. Log ⚡ logger.WithField("mood", "hyped").Info("This is awesome!") logger.WithField("mood", "worried").Warn("This is no that awesome...") logger.WithField("mood", "depressed").Error("This is rather bad.") - - // 6. This makes sure logrus calls the registered exit handler. Alternaively - // hook.Close() can be called manually. It is safe to call multiple times. - // - // ❗THIS IS IMPORTANT❗ Without it, the logs will not be sent to Axiom as - // the buffer will not be flushed when the application exits. - logrus.Exit(0) } diff --git a/examples/zap/main.go b/examples/zap/main.go index 260106d7..ca80e4dd 100644 --- a/examples/zap/main.go +++ b/examples/zap/main.go @@ -18,7 +18,7 @@ func main() { log.Fatal(err) } - // 2. Spawn the logger. + // 2. Create the logger. logger := zap.New(core) // 3. Have all logs flushed before the application exits.