zlog

package module
v1.1.1-0...-214946d Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: MIT, Apache-2.0 Imports: 6 Imported by: 0

README

TravisBuildStatus GoDoc GoReportCard codecov

for what

depends

in go mod project, last version is v1.1.0

# before above global settings
# test version info
$ git ls-remote -q http://github.com/sinlovgo/zlog.git

# test depends see full version
$ go list -v -m -versions github.com/sinlovgo/zlog
# or use last version add go.mod by script
$ echo "go mod edit -require=$(go list -m -versions github.com/sinlovgo/zlog.git | awk '{print $1 "@" $NF}')"
$ echo "go mod vendor"

config file

zap:
  AtomicLevel: -1 # DebugLevel:-1 InfoLevel:0 WarnLevel:1 ErrorLevel:2
  FieldsAuto: false # is use auto Fields key set
  Fields:
    Key: key
    Val: val
  Development: true # is open Open file and line number
  Encoding: console # output format, only use console or json, default is console
  rotate:
    Filename: log/zlog.log # Log file path
    MaxSize: 16 # Maximum size of each log file, Unit: M
    MaxBackups: 10 # How many backups are saved in the log file
    MaxAge: 7 # How many days can the file be keep, Unit: day
    Compress: true # need compress
  EncoderConfig:
    TimeKey: time
    LevelKey: level
    NameKey: logger
    CallerKey: caller
    MessageKey: msg
    StacktraceKey: stacktrace

use-code

import (
	"github.com/sinlovgo/zlog"
)
func main() {
    // default config conf/config.yaml
	err := zlog.Init("")
	if err != nil {
		fmt.Printf("zlog init error %v\n", err)
		return
	}
	zlog.Sugared.Debugf("Sugared DEBUG info %s", "message")
	zlog.Sugared.Infof("Sugared INFO info %v", "message")
	zlog.Sugared.Infof("Sugared info num %d", 10)
	zlog.Sugared.Debug("Sugared Debug can not format %v", "debug-info")
}

dev

  • use to replace sinlovgo/zlog to you code

  • and run

make init
  • test code
make test

add main.go file and run

make run

dev

evn

  • golang sdk 1.13+

docker

base docker file can replace

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Wrapper *zap.Logger

Functions

func DPanic

func DPanic(args ...interface{})

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

func DPanicf

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

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

func DPanicw

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

Deprecated 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 Debug

func Debug(args ...interface{})

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

func Debugf

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

Deprecated Debugf uses fmt.Sprintf to log a templated message.

func Debugw

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

Deprecated 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 Error

func Error(args ...interface{})

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

func Errorf

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

Deprecated Errorf uses fmt.Sprintf to log a templated message.

func Errorw

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

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

func Fatal

func Fatal(args ...interface{})

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

func Fatalf

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

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

func Fatalw

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

Deprecated 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 Info

func Info(args ...interface{})

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

func Infof

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

Deprecated Infof uses fmt.Sprintf to log a templated message.

func Infow

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

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

func Init

func Init(path string) error

init path use type yaml if path is empty read default config path: conf/config.yaml

func InitType

func InitType(path, cfgType string) error

read default type is json if path is empty read default config path: conf/config.yaml

func Panic

func Panic(args ...interface{})

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

func Panicf

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

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

func Panicw

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

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

func Sync

func Sync() error

Deprecated Sync flushes any buffered log entries.

func Warn

func Warn(args ...interface{})

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

func Warnf

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

Deprecated Warnf uses fmt.Sprintf to log a templated message.

func Warnw

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

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

Types

type LoggerGlobal

type LoggerGlobal interface {
	Debug(args ...interface{})
	Info(args ...interface{})
	Warn(args ...interface{})
	Error(args ...interface{})
	DPanic(args ...interface{})
	Panic(args ...interface{})
	Fatal(args ...interface{})
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	DPanicf(template string, args ...interface{})
	Panicf(template string, args ...interface{})
	Fatalf(template string, args ...interface{})
	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	DPanicw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
	Sync() error
}

Logger is a interface

var Logger LoggerGlobal

Logger is the global variable for the object of lager.Logger

type ZapLogger

type ZapLogger struct {
	ConfigPath string
	Log        *zap.Logger
	Sugar      *zap.SugaredLogger
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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