Skip to content

Commit

Permalink
chore(adapters): code grooming
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasmalkmus committed Jul 18, 2023
1 parent 3b42cb7 commit c80567a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
6 changes: 2 additions & 4 deletions adapters/apex/apex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ 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) {
zsr, err := zstd.NewReader(r.Body)
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})

Expand Down
4 changes: 2 additions & 2 deletions adapters/logrus/logrus.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package logrus
import (
"context"
"errors"
stdlog "log"
"log"
"os"
"sync"
"time"
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions adapters/zap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion adapters/zap/zap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
20 changes: 10 additions & 10 deletions examples/logrus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion examples/zap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c80567a

Please sign in to comment.