log

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: Apache-2.0 Imports: 11 Imported by: 45

Documentation

Overview

Copyright 2019 The arhat.dev Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2019 The arhat.dev Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	LevelVerbose = Level(zapcore.DebugLevel)
	LevelDebug   = Level(zapcore.InfoLevel)
	LevelInfo    = Level(zapcore.WarnLevel)
	LevelError   = Level(zapcore.ErrorLevel)
	LevelSilent  = Level(zapcore.FatalLevel + 1)
)

Log levels

View Source
const (
	TimeLayout = time.RFC3339Nano
)

TimeLayout used by this logger

Variables

View Source
var (
	Any        = zap.Any
	Error      = zap.Error
	NamedError = zap.NamedError
	Binary     = zap.Binary
	Bool       = zap.Bool
	ByteString = zap.ByteString
	Complex128 = zap.Complex128
	Complex64  = zap.Complex64
	Float64    = zap.Float64
	Float32    = zap.Float32
	Int        = zap.Int
	Int64      = zap.Int64
	Int32      = zap.Int32
	Int16      = zap.Int16
	Int8       = zap.Int8
	String     = zap.String
	Strings    = zap.Strings
	Uint       = zap.Uint
	Uint64     = zap.Uint64
	Uint32     = zap.Uint32
	Uint16     = zap.Uint16
	Uint8      = zap.Uint8
	Uintptr    = zap.Uintptr
	Time       = zap.Time
	Duration   = zap.Duration
)

log fields for zap logger

Functions

func FlagsForLogConfig

func FlagsForLogConfig(prefix string, c *Config) *pflag.FlagSet

func SetDefaultLogger

func SetDefaultLogger(cs ConfigSet) error

Types

type Config

type Config struct {
	Level       string `json:"level" yaml:"level"`
	Format      string `json:"format" yaml:"format"`
	KubeLog     bool   `json:"kubeLog" yaml:"kubeLog"`
	Destination `json:",inline" yaml:",inline"`
}

type ConfigSet

type ConfigSet []Config

func (ConfigSet) GetUnique

func (cs ConfigSet) GetUnique() ConfigSet

func (ConfigSet) KubeLogFile

func (cs ConfigSet) KubeLogFile() string

type Destination

type Destination struct {
	File string `json:"file" yaml:"file"`
}

type Field

type Field = zapcore.Field

func StringError

func StringError(err string) Field

type Interface

type Interface interface {
	// Enabled check if level is enabled
	Enabled(level Level) bool

	// WithName return a logger which shares config and runtime but with different name
	WithName(name string) Interface

	// WithFields return a logger with predefined fields
	WithFields(fields ...Field) Interface

	// V is the verbose level, should be used in library and not useful or untested stuff
	// such as showing a call started, printing some internal values for inspection
	V(msg string, fields ...Field)

	// D is the debug level, should be used for information
	D(msg string, fields ...Field)

	// I is the info level, should be used to indicate application state, show important messages
	I(msg string, fields ...Field)

	// E is the error level, should only be used to report unexpected or fatal error, will print
	// a stacktrace when used
	E(msg string, fields ...Field)

	// Flush logger
	Flush() error
}
var (
	Log        Interface
	NoOpLogger Interface
)

Global log instance

type Level

type Level zapcore.Level

func (Level) String

func (l Level) String() string

type Logger

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

func New

func New(name string, config ConfigSet) (*Logger, error)

func (*Logger) D

func (l *Logger) D(msg string, fields ...Field)

D debug

func (*Logger) E

func (l *Logger) E(msg string, fields ...Field)

E error

func (*Logger) Enabled

func (l *Logger) Enabled(level Level) bool

func (*Logger) Flush

func (l *Logger) Flush() error

Flush log write

func (*Logger) I

func (l *Logger) I(msg string, fields ...Field)

I info

func (*Logger) V

func (l *Logger) V(msg string, fields ...Field)

V verbose

func (*Logger) WithFields

func (l *Logger) WithFields(fields ...Field) Interface

func (*Logger) WithName

func (l *Logger) WithName(name string) Interface

type Structure

type Structure struct {
	Msg        string `json:"M,omitempty"`
	Level      string `json:"L,omitempty"`
	Time       string `json:"T,omitempty"`
	Name       string `json:"N,omitempty"`
	Caller     string `json:"C,omitempty"`
	Stacktrace string `json:"S,omitempty"`
}

Jump to

Keyboard shortcuts

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