slslog

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: MIT Imports: 8 Imported by: 0

README

slslog

Overview

AWS Lambda の標準出力に吐かれたログを Cloudwatch Logs Insight で trace 付きで一連の処理を追うことのできるための Logger です。

This is inspired by https://github.com/DeNA/aelog.

Usage

const label = "$LogLabelName"

func main() {
    slslog.SetLogLabel(label)
    span := slslog.StartSpan(context.Background(), label)
    defer span.End()

    ctx := span.Context()
    Infof(ctx, "this is slslog output")

    // Output:
    // {"severity":"INFO","message":"this is slslog output","trace":"service/$LogLabelName/trace/...","span":"service/$LogLabelName/span/..."}
}

See Also

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Criticalf

func Criticalf(ctx context.Context, format string, a ...interface{})

Criticalf is like Infof, but the severity is critical level.

Example
parent := context.Background()
s := trace.SpanFromContext(parent)
ctx := trace.ContextWithSpan(parent, s)
Criticalf(ctx, "%s", "test")
Output:

{"severity":"CRITICAL","message":"test","trace":"service/slslog/trace/00000000000000000000000000000000","span":"service/slslog/span/0000000000000000"}

func Errorf

func Errorf(ctx context.Context, format string, a ...interface{})

Errorf is like Infof, but the severity is error level.

Example
parent := context.Background()
s := trace.SpanFromContext(parent)
ctx := trace.ContextWithSpan(parent, s)
Errorf(ctx, "%s", "test")
Output:

{"severity":"ERROR","message":"test","trace":"service/slslog/trace/00000000000000000000000000000000","span":"service/slslog/span/0000000000000000"}

func Infof

func Infof(ctx context.Context, format string, a ...interface{})

Infof formats its arguments according to the format like fmt.Printf, and records the text as log message at Info level.

Example
parent := context.Background()
s := trace.SpanFromContext(parent)
ctx := trace.ContextWithSpan(parent, s)
Infof(ctx, "%s", "test")
Output:

{"severity":"INFO","message":"test","trace":"service/slslog/trace/00000000000000000000000000000000","span":"service/slslog/span/0000000000000000"}

func SetLogLabel

func SetLogLabel(label string)

func Warningf

func Warningf(ctx context.Context, format string, a ...interface{})

Warningf is like Infof, but the severity is warning level.

Example
parent := context.Background()
s := trace.SpanFromContext(parent)
ctx := trace.ContextWithSpan(parent, s)
Warningf(ctx, "%s", "test")
Output:

{"severity":"WARNING","message":"test","trace":"service/slslog/trace/00000000000000000000000000000000","span":"service/slslog/span/0000000000000000"}

Types

type Span

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

Span wraps go.opentelemetry.io/otel/trace.Span.

func StartSpan

func StartSpan(ctx context.Context, label string) *Span

StartSpan starts a new span from the current span in the given context and returns it as Span. This span can be propagated to the subsequent process by using span's context.

func (*Span) Context

func (s *Span) Context() context.Context

Context returns the span context attached to Span.

func (*Span) End

func (s *Span) End()

End ends the span.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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