log

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppID

func AppID() string

AppID get appID

func AppVersion

func AppVersion() string

AppVersion get buildAppVersion

func BuildHost

func BuildHost() string

BuildHost get buildHost

func BuildTime

func BuildTime() string

BuildTime get buildTime

func BuildUser

func BuildUser() string

BuildUser get buildUser

func Debug

func Debug(a ...interface{})

Debug logs a message at `debug` level.

func DebugW

func DebugW(template string, a ...Field)

DebugW writes msg along with fields into access log at `debug` level.

func Debugf

func Debugf(template string, a ...interface{})

Debugf logs a message at `debug` level.

func Error

func Error(a ...interface{})

Error logs a message at error level.

func ErrorW

func ErrorW(template string, a ...Field)

ErrorW writes msg along with fields into access log at `error` level.

func Errorf

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

Errorf logs a message at `error` level.

func Fatal

func Fatal(a ...interface{})

Fatal logs a message at `fatal` level.

func FatalW

func FatalW(template string, a ...Field)

FatalW writes msg along with fields into access log at `fatal` level.

func Fatalf

func Fatalf(format string, a ...interface{})

Fatalf logs a message at `fatal` level.

func FirstUpper

func FirstUpper(s string) string

func GoVersion

func GoVersion() string

GoVersion get go version

func HostName

func HostName() string

HostName get host name

func Info

func Info(a ...interface{})

Info logs a message at info level.

func InfoW

func InfoW(template string, a ...Field)

InfoW writes msg along with fields into access log at `info` level.

func Infof

func Infof(template string, a ...interface{})

Infof logs a message at `info` level.

func ModuleName

func ModuleName() string

func PkgVersion

func PkgVersion() string

func Printf

func Printf(format string, args ...interface{})

func ServiceName

func ServiceName() string

func SetAppID

func SetAppID(s string)

SetAppID set appID

func SetBuildTime

func SetBuildTime(param string)

SetBuildTime set buildTime

func SetLogger

func SetLogger(logger Logger)

SetLogger should be called before any other log call. And it is NOT THREAD SAFE.

func SetModuleName

func SetModuleName(name string)

func SetServiceName

func SetServiceName(s string)

func StartTime

func StartTime() string

StartTime get start time

func Warn

func Warn(a ...interface{})

Warn logs a message at `warn` level.

func WarnW

func WarnW(template string, a ...Field)

WarnW writes msg along with fields into access log at `warn` level.

func Warnf

func Warnf(format string, a ...interface{})

Warnf logs a message at `warn` level.

Types

type Config

type Config struct {
	Debug bool // 本地调试模式
	Level string

	// writer (syslog 地址)
	Net  string
	Addr string //remote addr of syslog
	Tag  string //tag of syslog

	// filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	Filename string

	// maxSize is the maximum size in bytes of the log file before it gets
	// rotated.
	MaxSize int64

	// maxAge is the maximum time to retain old log files based on the timestamp
	// encoded in their filename. The default is not to remove old log files
	// based on age.
	MaxAge time.Duration

	// maxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int

	// localTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool

	// compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool
	// contains filtered or unexported fields
}

Config for redis, contains RedisStubConfig and RedisClusterConfig

func (*Config) Build

func (c *Config) Build()

func (*Config) BuildOption

func (c *Config) BuildOption() []Option

func (*Config) GetTag

func (c *Config) GetTag() string

func (*Config) WithModuleName

func (c *Config) WithModuleName(moduleName string) *Config

func (*Config) WithServiceName

func (c *Config) WithServiceName(serviceName string) *Config

type Field

type Field struct {
	Key string
	Val FiledValue
}

func Any

func Any(key string, val interface{}) Field

func Bool

func Bool(key string, val bool) Field

func Duration

func Duration(key string, val time.Duration) Field

func FieldAddr

func FieldAddr(value string) Field

func FieldCost

func FieldCost(value time.Duration) Field

FieldCost 耗时时间

func FieldErr

func FieldErr(err error) Field

func FieldErrKind

func FieldErrKind(value string) Field

func FieldEvent

func FieldEvent(value string) Field

FieldEvent ...

func FieldKey

func FieldKey(value string) Field

func FieldMessage

func FieldMessage(value string) Field

FieldMessage ...

func FieldMethod

func FieldMethod(value string) Field

FieldMethod ...

func FieldMod

func FieldMod(value string) Field

func FieldName

func FieldName(value string) Field

func FieldStack

func FieldStack(value []byte) Field

FieldStack ...

func FieldString

func FieldString(key, value string) Field

func FieldType

func FieldType(value string) Field

FieldType ...

func Float64

func Float64(key string, val float64) Field

func Int

func Int(key string, val int) Field

func Int32

func Int32(key string, val int32) Field

func Int64

func Int64(key string, val int64) Field

func String

func String(key, val string) Field

func UInt

func UInt(key string, val uint) Field

type FiledType

type FiledType int
const (
	TypeString FiledType = iota
	TypeBool
	TypeInt
	TypeFloat
	TypeAny
)

type FiledValue

type FiledValue struct {
	V interface{}
	T FiledType
}

type Helper

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

func NewHelper

func NewHelper(logger Logger) *Helper

func (*Helper) Debug

func (h *Helper) Debug(args ...interface{})

func (*Helper) DebugW

func (h *Helper) DebugW(template string, args ...Field)

func (*Helper) Debugf

func (h *Helper) Debugf(template string, args ...interface{})

func (*Helper) Error

func (h *Helper) Error(args ...interface{})

func (*Helper) ErrorW

func (h *Helper) ErrorW(template string, args ...Field)

func (*Helper) Errorf

func (h *Helper) Errorf(template string, args ...interface{})

func (*Helper) Fatal

func (h *Helper) Fatal(args ...interface{})

func (*Helper) FatalW

func (h *Helper) FatalW(template string, args ...Field)

func (*Helper) Fatalf

func (h *Helper) Fatalf(template string, args ...interface{})

func (*Helper) Info

func (h *Helper) Info(args ...interface{})

func (*Helper) InfoW

func (h *Helper) InfoW(template string, args ...Field)

func (*Helper) Infof

func (h *Helper) Infof(template string, args ...interface{})

func (*Helper) Trace

func (h *Helper) Trace(args ...interface{})

func (*Helper) Tracef

func (h *Helper) Tracef(template string, args ...interface{})

func (*Helper) Warn

func (h *Helper) Warn(args ...interface{})

func (*Helper) WarnW

func (h *Helper) WarnW(template string, args ...Field)

func (*Helper) Warnf

func (h *Helper) Warnf(template string, args ...interface{})

type Level

type Level int8

Level is a logger level.

const (
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel Level = iota - 2
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// InfoLevel is the default logging priority.
	// General operational entries about what's going on inside the application.
	InfoLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
	FatalLevel
)

func GetLevel

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) Enabled

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {

	// Init initialises options
	Init(options ...Option) error

	// The Logger options
	Options() Options

	// Fields set fields to always be logged
	Fields(fields map[string]interface{}) Logger

	// Log writes a log entry
	Log(level Level, keyvals ...interface{})

	// Logf writes a formatted log entry
	Logf(level Level, format string, keyvals ...interface{})

	// LogW writes a field log
	LogW(level Level, msg string, args ...Field)

	Printf(format string, args ...interface{})

	// Level 变更
	OnChangeLevel(level Level)

	// String returns the name of logger
	String() string
}

Logger is a logger interface.

var (
	DefaultLogger Logger
)

DefaultLogger is default logger.

func NewLogger

func NewLogger(opts ...Option) Logger

NewLogger builds a new logger based on options

type Option

type Option func(*Options)

func WithCallerSkipCount

func WithCallerSkipCount(c int) Option

WithCallerSkipCount set frame count to skip

func WithFields

func WithFields(fields map[string]interface{}) Option

WithFields set default fields for the logger

func WithLevel

func WithLevel(level Level) Option

WithLevel set default level for the logger

func WithOutput

func WithOutput(out io.Writer) Option

WithOutput set default output writer for the logger

func WithSetOption

func WithSetOption(k, v interface{}) Option

func WithTag

func WithTag(tag string) Option

WithTag set syslog tag

type Options

type Options struct {
	// The logging level the logger should log at. default is `InfoLevel`
	Level Level
	// fields to always be logged
	Fields map[string]interface{}
	// It's common to set this to a file, or leave it default which is `os.Stderr`
	Out io.Writer
	// Caller skip frame count for file:line info
	CallerSkipCount int
	// Alternative options
	Context context.Context
	// syslog tag
	Tag string
}

type ZapCnf

type ZapCnf struct {
	Debug bool //调试模式 本地打印
	Level string
	Net   string
	Addr  string
	Tag   string

	// filename is the file to write logs to.  Backup log files will be retained
	// in the same directory.  It uses <processname>-lumberjack.log in
	// os.TempDir() if empty.
	Filename string

	// maxSize is the maximum size in bytes of the log file before it gets
	// rotated.
	MaxSize int64

	// maxAge is the maximum time to retain old log files based on the timestamp
	// encoded in their filename. The default is not to remove old log files
	// based on age.
	MaxAge time.Duration

	// maxBackups is the maximum number of old log files to retain.  The default
	// is to retain all old log files (though MaxAge may still cause them to get
	// deleted.)
	MaxBackups int

	// localTime determines if the time used for formatting the timestamps in
	// backup files is the computer's local time.  The default is to use UTC
	// time.
	LocalTime bool

	// compress determines if the rotated log files should be compressed
	// using gzip. The default is not to perform compression.
	Compress bool
}

type ZapCnfKey

type ZapCnfKey struct {
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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