logs

package module
v0.0.0-...-12a3c58 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2017 License: MIT Imports: 5 Imported by: 0

README

Objective

Offer a Golang logger based on Lalamove k8s logging format.

Install

go get -u github.com/lalamove/logs

Usage

import lalamove "github.com/lalamove/logs"

func main(){
    lalamove.Logger().Debug("I am not a Debug")
    // {"level":"debug","time":"2017-12-23T05:42:47.752491212Z","src_file":"logs/logs_test.go:10","message":"I am not a Debug","src_line":"10"}

    lalamove.Logger().Info("I am not an Info")
    // {"level":"info","time":"2017-12-23T05:42:47.752524440Z","src_file":"logs/logs_test.go:11","message":"I am not an Info","src_line":"11"}

    lalamove.Logger().Warn("I am not a Warn")
    // {"level":"warning","time":"2017-12-23T05:42:47.752541092Z","src_file":"logs/logs_test.go:12","message":"I am not a Warn","src_line":"12","backtrace":"github.com/logs.TestGetLalamoveLoggerPassDebug\n\t/home/alpha/works/src/github.com/logs/logs_test.go:12\ntesting.tRunner\n\t/home/alpha/go/src/testing/testing.go:746"}

    lalamove.Logger().Error("I am not an Error")
    // {"level":"error","time":"2017-12-23T05:42:47.752575758Z","src_file":"logs/logs_test.go:13","message":"I am not an Error","src_line":"13","backtrace":"github.com/logs.TestGetLalamoveLoggerPassDebug\n\t/home/alpha/works/src/github.com/logs/logs_test.go:13\ntesting.tRunner\n\t/home/alpha/go/src/testing/testing.go:746"}

    lalamove.Logger().Fatal("I am not a Fatal")
    // {"level":"fatal","time":"2017-12-23T05:30:41.901899661Z","src_file":"logs/logs_test.go:49","message":"I am a Fatal","src_line":"49","backtrace":"github.com/logs.TestGetLalamoveLoggerPassFatal\n\t/home/alpha/works/src/github.com/logs/logs_test.go:49\ntesting.tRunner\n\t/home/alpha/go/src/testing/testing.go:746"}
}

Run test

go test . -v

Report issue

alpha.wong@lalamove.com

Credit

License

Released under the MIT License.

Documentation

Overview

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Reference: https://lalamove.atlassian.net/wiki/spaces/TECH/pages/82149406/Kubernetes Lalamove kubernetes logging format

{
		"message": "", // string describing what happened
		"src_file": "", // file path
		"src_line": "", // line number
		"fields": {}, // custom field here
		"level": "", // debug/info/warning/error/fatal
		"time": "", // ISO8601.nanoseconds+TZ (in node only support precision up to milliseconds)
		"backtrace": "" // err stack
}

Index

Constants

View Source
const (
	ISO8601 = "2006-01-02T15:04:05.000000000Z0700"

	Debug   = "debug"
	Info    = "info"
	Warning = "warning"
	Error   = "error"
	Fatal   = "fatal"

	TimeKey       = "time"
	LevelKey      = "level"
	CallerKey     = "src_file"
	SourceLineKey = "src_line"
	MessageKey    = "message"
	StacktraceKey = "backtrace"

	EncodingType = "json"
)

Variables

This section is empty.

Functions

func LalamoveISO8601TimeEncoder

func LalamoveISO8601TimeEncoder(t time.Time, enc zapcore.PrimitiveArrayEncoder)

LalamoveISO8601TimeEncoder will convert the time to ISO8601 based on Lalamove k8s logging format

func LalamoveLevelEncoder

func LalamoveLevelEncoder(l zapcore.Level, enc zapcore.PrimitiveArrayEncoder)

LalamoveLevelEncoder will convert the warn display string to warning

func Logger

func Logger() *zap.Logger

Logger will create an zap based logger return a *zap.Logger for logging

func NewLalamoveEncoderConfig

func NewLalamoveEncoderConfig() zapcore.EncoderConfig

NewLalamoveEncoderConfig will create an EncoderConfig

func NewLalamoveZapConfig

func NewLalamoveZapConfig() *zap.Config

NewLalamoveZapConfig will create an config for zap

Types

This section is empty.

Jump to

Keyboard shortcuts

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