logger

package module
v0.0.0-...-2938e4f Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2023 License: MIT Imports: 5 Imported by: 0

README

Logger

GoDoc MIT License

This is a logger wrap on zap for simple daily usage, and aimed to replace exist logger.

This repo still on development and do not promise API compatible.

Done

See zap_test.go use cases.

TODO

  • Add guance-syncer to push logging data to Guance Cloud
  • Add trace-id inject(use otelzap)
  • Add metrics on logger
  • Add more testing

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SLogger

func SLogger(name string) *zap.SugaredLogger

func Setup

func Setup(opts ...option) error

func Sync

func Sync()

func WithColorLevel

func WithColorLevel(on bool) option

WithColorLevel set color on log levels. Only applied to stdout and non-JSON encoder.

Why: color in json and diskfile makes it hard to parse for

logging system, it's only for human readablility.

func WithErrorLogPath

func WithErrorLogPath(p string) option

WithErrorLogPath set log file on ERROR logs

func WithJSONEncoding

func WithJSONEncoding(on bool) option

WithJSONEncoding encode log format in JSON.

func WithLevel

func WithLevel(lvl Level) option

WithLevel set root logger level.

func WithMode

func WithMode(mode Mode) option

WithMode set global logging mode.

func WithPath

func WithPath(p string) option

WithPath set log path.

func WithRotate

func WithRotate(on bool) option

WithRotate setup log file rotate on default settings.

func WithStackTrace

func WithStackTrace(on bool, lvl Level) option

WithStackTrace enable stack trace that log level >= lvl

func WithStdout

func WithStdout(on bool) option

WithStdout send log to stdout even the log path already set.

Types

type Level

type Level int8

A Level is a logging priority. Higher levels are more important.

const (
	// same to zap's levels, but only keep 4 levels of them
	DebugLevel Level = iota - 1
	// InfoLevel is the default logging priority.
	InfoLevel
	// WarnLevel logs are more important than Info, but don't need individual
	// human review.
	WarnLevel
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel
)

type Mode

type Mode int8

A Mode is a logging settings. development mode logging are more readable than production mode.

const (
	// ModeDevelopment set mode to development
	ModeDevelopment Mode = iota

	// ModeDevelopment set mode to production
	ModeProduction
)

Jump to

Keyboard shortcuts

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