slog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: Apache-2.0 Imports: 6 Imported by: 6

README

Hertz Slog (This is a community driven project)

Introduction

This is a logger library that uses slog to implement the Hertz logger interface

Usage

Download and install it:

go get github.com/hertz-contrib/logger/slog

Import it in your code:

import hertzslog "github.com/hertz-contrib/logger/slog"

Simple Example:

package main

import (
	"context"

	"github.com/cloudwego/hertz/pkg/common/hlog"
	hertzslog "github.com/hertz-contrib/logger/slog"
)

func main() {
	logger := hertzslog.NewLogger()
	hlog.SetLogger(logger)

	...

	hlog.CtxInfof(context.Background(), "hello %s", "hertz")
}

Documentation

Index

Constants

View Source
const (
	LevelTrace  = slog.Level(-8)
	LevelNotice = slog.Level(2)
	LevelFatal  = slog.Level(12)
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

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

Logger slog impl

func NewLogger

func NewLogger(opts ...Option) *Logger

func (*Logger) CtxDebugf

func (l *Logger) CtxDebugf(ctx context.Context, format string, v ...any)

func (*Logger) CtxErrorf

func (l *Logger) CtxErrorf(ctx context.Context, format string, v ...any)

func (*Logger) CtxFatalf

func (l *Logger) CtxFatalf(ctx context.Context, format string, v ...any)

func (*Logger) CtxInfof

func (l *Logger) CtxInfof(ctx context.Context, format string, v ...any)

func (*Logger) CtxNoticef

func (l *Logger) CtxNoticef(ctx context.Context, format string, v ...any)

func (*Logger) CtxTracef

func (l *Logger) CtxTracef(ctx context.Context, format string, v ...any)

func (*Logger) CtxWarnf

func (l *Logger) CtxWarnf(ctx context.Context, format string, v ...any)

func (*Logger) Debug

func (l *Logger) Debug(v ...any)

func (*Logger) Debugf

func (l *Logger) Debugf(format string, v ...any)

func (*Logger) Error

func (l *Logger) Error(v ...any)

func (*Logger) Errorf

func (l *Logger) Errorf(format string, v ...any)

func (*Logger) Fatal

func (l *Logger) Fatal(v ...any)

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...any)

func (*Logger) Info

func (l *Logger) Info(v ...any)

func (*Logger) Infof

func (l *Logger) Infof(format string, v ...any)

func (*Logger) Logger

func (l *Logger) Logger() *slog.Logger

func (*Logger) Notice

func (l *Logger) Notice(v ...any)

func (*Logger) Noticef

func (l *Logger) Noticef(format string, v ...any)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level hlog.Level)

func (*Logger) SetOutput

func (l *Logger) SetOutput(writer io.Writer)

func (*Logger) Trace

func (l *Logger) Trace(v ...any)

func (*Logger) Tracef

func (l *Logger) Tracef(format string, v ...any)

func (*Logger) Warn

func (l *Logger) Warn(v ...any)

func (*Logger) Warnf

func (l *Logger) Warnf(format string, v ...any)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithHandlerOptions

func WithHandlerOptions(opts *slog.HandlerOptions) Option

func WithLevel

func WithLevel(lvl *slog.LevelVar) Option

func WithOutput

func WithOutput(writer io.Writer) Option

Jump to

Keyboard shortcuts

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