logotel

package module
v0.0.0-...-c21fe68 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 22, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

README

logotel

PkgGoDev

logotel is a simple logger for OpenTelemetry.

PRs and patches are welcomed.

LICENSE

See LICENSE

TODO

  • examples
  • more test cases

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, message string, attributes ...attribute.KeyValue)

Debug is a helper that uses the Logger in the context.

func Error

func Error(ctx context.Context, message string, attributes ...attribute.KeyValue)

Error is a helper that uses the Logger in the context.

func Fatal

func Fatal(ctx context.Context, message string, attributes ...attribute.KeyValue)

Fatal is a helper that uses the Logger in the context.

func Info

func Info(ctx context.Context, message string, attributes ...attribute.KeyValue)

Info is a helper that uses the Logger in the context.

func ToContext

func ToContext(ctx context.Context, l *Logger) context.Context

ToContext adds the Logger to the context.

func Warn

func Warn(ctx context.Context, message string, attributes ...attribute.KeyValue)

Warn is a helper that uses the Logger in the context.

Types

type Exporter

type Exporter interface {
	ExportLogs(ctx context.Context, protoLogs []*logsv1.ResourceLogs) error
}

Exporter exports log records

type GrpcExporter

type GrpcExporter struct {
	// contains filtered or unexported fields
}

GrpcExporter exports logs using the oltp grpc log export service.

func NewGrpcExporter

func NewGrpcExporter(ctx context.Context, address string, options ...grpc.DialOption) (*GrpcExporter, error)

NewGrpcExporter creates an exporter.

func (*GrpcExporter) ExportLogs

func (g *GrpcExporter) ExportLogs(_ context.Context, protoLogs []*logsv1.ResourceLogs) error

ExportLogs exports logs.

type JSONExporter

type JSONExporter struct {
	// contains filtered or unexported fields
}

JSONExporter writes logs in json format.

func NewJSONExporter

func NewJSONExporter() *JSONExporter

NewJSONExporter creates a new exported that writes json to stdout.

func (*JSONExporter) ExportLogs

func (j *JSONExporter) ExportLogs(_ context.Context, protoLogs []*logsv1.ResourceLogs) error

ExportLogs exports logs.

func (*JSONExporter) WithWriter

func (j *JSONExporter) WithWriter(w io.Writer) *JSONExporter

WithWriter sets the writer for the exporter. It is up to the caller to ensure the writer is locked. The exported writes logs one complete line at a time.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is an opentelemetry logger

func FromContext

func FromContext(ctx context.Context) *Logger

FromContext returns the Logger from the context. If no logger was added, a nop Logger is returned.

func NewLogger

func NewLogger() *Logger

NewLogger creates a new Logger at Info severity. It does nothing with logs, so you must add an exporter.

func (*Logger) Debug

func (l *Logger) Debug(ctx context.Context, message string, attributes ...attribute.KeyValue)

Debug logs at debug severity. Attributes passed here are merged with those added WithAttributes.

func (*Logger) Error

func (l *Logger) Error(ctx context.Context, message string, attributes ...attribute.KeyValue)

Error logs at error severity. Attributes passed here are merged with those added WithAttributes.

func (*Logger) Fatal

func (l *Logger) Fatal(ctx context.Context, message string, attributes ...attribute.KeyValue)

Fatal logs at fatal severity. Attributes passed here are merged with those added WithAttributes.

func (*Logger) Info

func (l *Logger) Info(ctx context.Context, message string, attributes ...attribute.KeyValue)

Info logs at info severity. Attributes passed here are merged with those added WithAttributes.

func (*Logger) Warn

func (l *Logger) Warn(ctx context.Context, message string, attributes ...attribute.KeyValue)

Warn logs at warn severity. Attributes passed here are merged with those added WithAttributes.

func (*Logger) WithAttributes

func (l *Logger) WithAttributes(attributes ...attribute.KeyValue) *Logger

WithResource returns a clone of the logger with the attributes merged with any existing ones on the Logger.

func (*Logger) WithExporter

func (l *Logger) WithExporter(exporter Exporter) *Logger

WithExporter returns a clone of the logger with the given exporter. This overrides any previously set exporter.

func (*Logger) WithResource

func (l *Logger) WithResource(resource *resource.Resource) *Logger

WithResource returns a clone of the logger with the given resource. The resource is included with the exporter log records. This overrides any previously set resource.

func (*Logger) WithSeverity

func (l *Logger) WithSeverity(severity logsv1.SeverityNumber) *Logger

WithSeverity returns a clone of the logger with the given severity. Logs below this severity will not be exported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL