logger

package
v1.4.22 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Example
package main

import (
	"context"
	"os"
	"time"

	"go.uber.org/zap"

	"github.com/ww24/linebot/logger"
)

func main() {
	ctx := context.Background()
	testTime := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC)

	// initialize root logger
	if err := logger.SetConfigWithWriter("service-name", "v1.0.0", os.Stdout); err != nil {
		panic(err)
	}

	dl := logger.Default(ctx)
	dl = dl.WithLogger(dl.WithOptions(zap.WithClock(logger.StaticClock(testTime))))

	// info log
	dl.Info("message", zap.String("key", "value"))

}
Output:

{"severity":"INFO","timestamp":"2023-01-01T00:00:00Z","message":"message","serviceContext":{"service":"service-name","version":"v1.0.0"},"key":"value","logging.googleapis.com/sourceLocation":{"file":"github.com/ww24/linebot/logger/example_test.go","line":"26","function":"github.com/ww24/linebot/logger_test.Example"}}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetConfig added in v1.4.6

func SetConfig(service, version string) error

func SetConfigWithWriter added in v1.4.7

func SetConfigWithWriter(service, version string, w io.Writer) error

Types

type Logger

type Logger struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func Default added in v1.4.7

func Default(ctx context.Context) *Logger

func NewNop added in v1.0.14

func NewNop() *Logger

func (*Logger) WithLogger added in v1.4.7

func (l *Logger) WithLogger(zl *zap.Logger) *Logger

func (*Logger) WithTraceFromContext

func (l *Logger) WithTraceFromContext(ctx context.Context) *Logger

Jump to

Keyboard shortcuts

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