log

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

使用默认的日志记录器:

package main

import (
	"github.com/blessmylovexy/log"
)

func main() {
	log.Info("Info log")
	log.Infof("%s", "InfoF log")

	//动态设置日记级别
	log.Debug("我不应该被输出")
	log.Config.SetLevel("debug")
	log.Debug("Debug log")

	//设置ProjectName
	log.Config.SetProjectName("mlog")
	log.ApplyConfig()
	log.Infof("SetProjectName: %s", "mlog")

	//禁用JSON格式
	log.Config.DisableJSONFormat()
	log.ApplyConfig()
	log.Info("DisableJSONFormat")
}
{"L":"INFO","T":"2020-04-27T10:15:47.230+0800","C":"_test_/main.go:8","M":"Info log"}
{"L":"INFO","T":"2020-04-27T10:15:47.230+0800","C":"_test_/main.go:9","M":"InfoF log"}
{"L":"DEBUG","T":"2020-04-27T10:15:47.230+0800","C":"_test_/main.go:14","M":"Debug log"}
{"L":"INFO","T":"2020-04-27T10:15:47.230+0800","N":"mlog","C":"_test_/main.go:19","M":"SetProjectName: mlog"}
2020-04-27T10:15:47.230+0800	INFO	mlog	_test_/main.go:24	DisableJSONFormat

新建日志记录器:

package main

import (
	"github.com/blessmylovexy/log/logger"
)

func main() {
	log1 := logger.New()
	log1.Config.SetProjectName("log1")
	log1.ApplyConfig()
	log1.Error("msg log1")

	log2 := logger.New()
	log2.Config.SetProjectName("log2")
	log2.ApplyConfig()
	log2.Error("msg log2")
}
{"L":"ERROR","T":"2020-04-27T10:17:01.163+0800","N":"log1","C":"_test_/main.go:11","M":"msg log1"}
{"L":"ERROR","T":"2020-04-27T10:17:01.163+0800","N":"log2","C":"_test_/main.go:16","M":"msg log2"}

格式化日志记录:

package main

import (
	"github.com/blessmylovexy/log"
)

func main() {
	log.Infow("with fild",
		"url", "www.url.com",
		"duration", 3,
	)
}
{"L":"INFO","T":"2020-04-27T10:17:28.377+0800","C":"_test_/main.go:8","M":"with fild","url":"www.url.com","duration":3}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	/*Config log配置文件*/
	Config *logger.Config
)

Functions

func ApplyConfig

func ApplyConfig()

ApplyConfig 应用当前Config配置

func Debug

func Debug(args ...interface{})

Debug Debug log

func Debugf

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

Debugf Debug format log

func Debugw

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

Debugw Debugw log

func Error

func Error(args ...interface{})

Error Error log

func Errorf

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

Errorf Error format log

func Errorw

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

Errorw Errorw log

func Fatal

func Fatal(args ...interface{})

Fatal Fatal log

func Fatalf

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

Fatalf Fatal format log

func Fatalw

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

Fatalw Fatalw log

func Info

func Info(args ...interface{})

Info Info log

func Infof

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

Infof Info format log

func Infow

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

Infow Infow log

func Panic

func Panic(args ...interface{})

Panic Panic log

func Panicf

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

Panicf Panic format log

func Panicw

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

Panicw Panicw log

func Warn

func Warn(args ...interface{})

Warn Warn log

func Warnf

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

Warnf Warn format log

func Warnw

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

Warnw Warnw log

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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