dlog

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

基于 klog 和 zap 封装的 Logger 及其接口

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxDebugf

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

CtxDebugf calls the default logger's CtxDebugf method.

func CtxErrorf

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

CtxErrorf calls the default logger's CtxErrorf method.

func CtxFatalf

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

CtxFatalf calls the default logger's CtxFatalf method and then os.Exit(1).

func CtxInfof

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

CtxInfof calls the default logger's CtxInfof method.

func CtxNoticef

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

CtxNoticef calls the default logger's CtxNoticef method.

func CtxTracef

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

CtxTracef calls the default logger's CtxTracef method.

func CtxWarnf

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

CtxWarnf calls the default logger's CtxWarnf method.

func Debug

func Debug(v ...any)

Debug calls the default logger's Debug method.

func Debugf

func Debugf(format string, v ...any)

Debugf calls the default logger's Debugf method.

func Error

func Error(v ...any)

Error calls the default logger's Error method.

func Errorf

func Errorf(format string, v ...any)

Errorf calls the default logger's Errorf method.

func Fatal

func Fatal(v ...any)

Fatal calls the default logger's Fatal method and then os.Exit(1).

func Fatalf

func Fatalf(format string, v ...any)

Fatalf calls the default logger's Fatalf method and then os.Exit(1).

func Info

func Info(v ...any)

Info calls the default logger's Info method.

func Infof

func Infof(format string, v ...any)

Infof calls the default logger's Infof method.

func InitLog

func InitLog() *zap.Logger

Init Logger config

func Notice

func Notice(v ...any)

Notice calls the default logger's Notice method.

func Noticef

func Noticef(format string, v ...any)

Noticef calls the default logger's Noticef method.

func SetLevel

func SetLevel(lv klog.Level)

SetLevel sets the level of logs below which logs will not be output. The default log level is LevelTrace. Note that this method is not concurrent-safe.

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the output of default logger. By default, it is stderr.

func Trace

func Trace(v ...any)

Trace calls the default logger's Trace method.

func Tracef

func Tracef(format string, v ...any)

Tracef calls the default logger's Tracef method.

func Warn

func Warn(v ...any)

Warn calls the default logger's Warn method.

func Warnf

func Warnf(format string, v ...any)

Warnf calls the default logger's Warnf method.

Types

type SugaredLogger

type SugaredLogger struct {
	Base *zapgorm2.Logger
}

A SugaredLogger wraps the Base Logger functionality in a slower, but less verbose, API. Any Logger can be converted to a SugaredLogger with its Sugar method.

Unlike the Logger, the SugaredLogger doesn't insist on structured logging. For each log level, it exposes three methods: one for loosely-typed structured logging, one for println-style formatting, and one for printf-style formatting. For example, SugaredLoggers can produce InfoLevel output with Infow ("info with" structured context), Info, or Infof.

func (*SugaredLogger) DPanic

func (s *SugaredLogger) DPanic(args ...interface{})

DPanic uses fmt.Sprint to construct and log a message. In development, the logger then panics. (See DPanicLevel for details.)

func (*SugaredLogger) DPanicf

func (s *SugaredLogger) DPanicf(template string, args ...interface{})

DPanicf uses fmt.Sprintf to log a templated message. In development, the logger then panics. (See DPanicLevel for details.)

func (*SugaredLogger) DPanicw

func (s *SugaredLogger) DPanicw(msg string, keysAndValues ...interface{})

DPanicw logs a message with some additional context. In development, the logger then panics. (See DPanicLevel for details.) The variadic key-value pairs are treated as they are in With.

func (*SugaredLogger) Debug

func (s *SugaredLogger) Debug(args ...interface{})

Debug uses fmt.Sprint to construct and log a message.

func (*SugaredLogger) Debugf

func (s *SugaredLogger) Debugf(template string, args ...interface{})

Debugf uses fmt.Sprintf to log a templated message.

func (*SugaredLogger) Debugw

func (s *SugaredLogger) Debugw(msg string, keysAndValues ...interface{})

Debugw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

When debug-level logging is disabled, this is much faster than

s.With(keysAndValues).Debug(msg)

func (*SugaredLogger) Error

func (s *SugaredLogger) Error(args ...interface{})

Error uses fmt.Sprint to construct and log a message.

func (*SugaredLogger) Errorf

func (s *SugaredLogger) Errorf(template string, args ...interface{})

Errorf uses fmt.Sprintf to log a templated message.

func (*SugaredLogger) Errorw

func (s *SugaredLogger) Errorw(msg string, keysAndValues ...interface{})

Errorw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*SugaredLogger) Fatal

func (s *SugaredLogger) Fatal(args ...interface{})

Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.

func (*SugaredLogger) Fatalf

func (s *SugaredLogger) Fatalf(template string, args ...interface{})

Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.

func (*SugaredLogger) Fatalw

func (s *SugaredLogger) Fatalw(msg string, keysAndValues ...interface{})

Fatalw logs a message with some additional context, then calls os.Exit. The variadic key-value pairs are treated as they are in With.

func (*SugaredLogger) Info

func (s *SugaredLogger) Info(args ...interface{})

Info uses fmt.Sprint to construct and log a message.

func (*SugaredLogger) Infof

func (s *SugaredLogger) Infof(template string, args ...interface{})

Infof uses fmt.Sprintf to log a templated message.

func (*SugaredLogger) Infow

func (s *SugaredLogger) Infow(msg string, keysAndValues ...interface{})

Infow logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*SugaredLogger) Named

func (s *SugaredLogger) Named(name string) *SugaredLogger

func (*SugaredLogger) Notice

func (s *SugaredLogger) Notice(args ...interface{})

func (*SugaredLogger) Noticef

func (s *SugaredLogger) Noticef(template string, args ...interface{})

func (*SugaredLogger) Panic

func (s *SugaredLogger) Panic(args ...interface{})

Panic uses fmt.Sprint to construct and log a message, then panics.

func (*SugaredLogger) Panicf

func (s *SugaredLogger) Panicf(template string, args ...interface{})

Panicf uses fmt.Sprintf to log a templated message, then panics.

func (*SugaredLogger) Panicw

func (s *SugaredLogger) Panicw(msg string, keysAndValues ...interface{})

Panicw logs a message with some additional context, then panics. The variadic key-value pairs are treated as they are in With.

func (*SugaredLogger) Sync

func (s *SugaredLogger) Sync() error

Sync flushes any buffered log entries.

func (*SugaredLogger) Trace

func (s *SugaredLogger) Trace(args ...interface{})

func (*SugaredLogger) Tracef

func (s *SugaredLogger) Tracef(template string, args ...interface{})

func (*SugaredLogger) Warn

func (s *SugaredLogger) Warn(args ...interface{})

Warn uses fmt.Sprint to construct and log a message.

func (*SugaredLogger) Warnf

func (s *SugaredLogger) Warnf(template string, args ...interface{})

Warnf uses fmt.Sprintf to log a templated message.

func (*SugaredLogger) Warnw

func (s *SugaredLogger) Warnw(msg string, keysAndValues ...interface{})

Warnw logs a message with some additional context. The variadic key-value pairs are treated as they are in With.

func (*SugaredLogger) With

func (s *SugaredLogger) With(args ...interface{}) *SugaredLogger

With adds a variadic number of fields to the logging context. It accepts a mix of strongly-typed Field objects and loosely-typed key-value pairs. When processing pairs, the first element of the pair is used as the field key and the second as the field value.

For example,

 sugaredLogger.With(
   "hello", "world",
   "failure", errors.New("oh no"),
   Stack(),
   "count", 42,
   "user", User{Name: "alice"},
)

is the equivalent of

unsugared.With(
  String("hello", "world"),
  String("failure", "oh no"),
  Stack(),
  Int("count", 42),
  Object("user", User{Name: "alice"}),
)

Note that the keys in key-value pairs should be strings. In development, passing a non-string key panics. In production, the logger is more forgiving: a separate error is logged, but the key-value pair is skipped and execution continues. Passing an orphaned key triggers similar behavior: panics in development and errors in production.

type ZapLogger

type ZapLogger struct {
	SugaredLogger
	Level klog.Level
}

func (*ZapLogger) CtxDebugf

func (ll *ZapLogger) CtxDebugf(ctx context.Context, format string, v ...any)

func (*ZapLogger) CtxErrorf

func (ll *ZapLogger) CtxErrorf(ctx context.Context, format string, v ...any)

func (*ZapLogger) CtxFatalf

func (ll *ZapLogger) CtxFatalf(ctx context.Context, format string, v ...any)

*

CtxLogger

*

func (*ZapLogger) CtxInfof

func (ll *ZapLogger) CtxInfof(ctx context.Context, format string, v ...any)

func (*ZapLogger) CtxNoticef

func (ll *ZapLogger) CtxNoticef(ctx context.Context, format string, v ...any)

func (*ZapLogger) CtxTracef

func (ll *ZapLogger) CtxTracef(ctx context.Context, format string, v ...any)

func (*ZapLogger) CtxWarnf

func (ll *ZapLogger) CtxWarnf(ctx context.Context, format string, v ...any)

func (*ZapLogger) SetLevel

func (ll *ZapLogger) SetLevel(lv klog.Level)

func (*ZapLogger) SetOutput

func (ll *ZapLogger) SetOutput(w io.Writer)

*

Control

*

Jump to

Keyboard shortcuts

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