Skip to content

Commit

Permalink
Add example for stdoutlog
Browse files Browse the repository at this point in the history
  • Loading branch information
XSAM committed Apr 20, 2024
1 parent 48f028f commit a442965
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions exporters/stdout/stdoutlog/example_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package stdoutlog_test

import (
"context"
"go.opentelemetry.io/otel/exporters/stdout/stdoutlog"
"go.opentelemetry.io/otel/log/global"
"go.opentelemetry.io/otel/sdk/log"
)

func Example() {
exp, err := stdoutlog.New()
if err != nil {
panic(err)
}

processor := log.NewBatchProcessor(exp)
provider := log.NewLoggerProvider(log.WithProcessor(processor))
defer func() {
if err := provider.Shutdown(context.Background()); err != nil {
panic(err)
}
}()

global.SetLoggerProvider(provider)

// From here, the provider can be used by instrumentation to collect
// telemetry.
}

0 comments on commit a442965

Please sign in to comment.