log

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

log

A simple log library based on github.com/uber-go/zap.

Installation

$ go get -u github.com/Kaiser925/log

Quick start

Log message

package main

import "github.com/Kaiser925/log"

func main() {
	defer log.Flush()
	log.Info("Hello world")
}

Log with custom options

package main

import "github.com/Kaiser925/log"

func main() {
	defer log.Flush()
	log.Init(&log.Option{
		Level: log.DebugLevel.String(),
		Format: log.JsonFormat,
		EnableCaller: true,
		EnableColor: false,
    })
	log.Info("Hello world")
}

Released under the BSD 3-Clause License

Documentation

Index

Constants

View Source
const (
	ConsoleFormat = "console"
	JsonFormat    = "json"
)
View Source
const (
	// ErrorLevel logs are high-priority. If an application is running smoothly,
	// it shouldn't generate any error-level logs.
	ErrorLevel = zapcore.ErrorLevel
	// WarnLevel  logs are more important than Info, but don't need individual human review
	WarnLevel = zapcore.WarnLevel
	// InfoLevel  logs are less important than Debug, but are still interesting
	InfoLevel = zapcore.InfoLevel
	// DebugLevel logs are for debugging.
	DebugLevel = zapcore.DebugLevel
	// DPanicLevel logs are particularly important errors.
	// In development the zapLogger panics after writing the message.
	DPanicLevel = zapcore.DPanicLevel
	// PanicLevel logs a message, then panics.
	PanicLevel = zapcore.PanicLevel
	// FatalLevel logs a message, then calls os.Exit(1).
	FatalLevel = zapcore.FatalLevel
)

Level variables aliases.

Variables

View Source
var (
	Any         = zap.Any
	Array       = zap.Array
	Object      = zap.Object
	Binary      = zap.Binary
	Bool        = zap.Bool
	Bools       = zap.Bools
	ByteString  = zap.ByteString
	ByteStrings = zap.ByteStrings
	Complex64   = zap.Complex64
	Complex64s  = zap.Complex64s
	Complex128  = zap.Complex128
	Complex128s = zap.Complex128s
	Duration    = zap.Duration
	Durations   = zap.Durations
	Err         = zap.Error
	Errors      = zap.Errors
	Float32     = zap.Float32
	Float32s    = zap.Float32s
	Float64     = zap.Float64
	Float64s    = zap.Float64s
	Int         = zap.Int
	Ints        = zap.Ints
	Int8        = zap.Int8
	Int8s       = zap.Int8s
	Int16       = zap.Int16
	Int16s      = zap.Int16s
	Int32       = zap.Int32
	Int32s      = zap.Int32s
	Int64       = zap.Int64
	Int64s      = zap.Int64s
	Namespace   = zap.Namespace
	Reflect     = zap.Reflect
	Stack       = zap.Stack
	String      = zap.String
	Stringer    = zap.Stringer
	Strings     = zap.Strings
	Time        = zap.Time
	Times       = zap.Times
	Uint        = zap.Uint
	Uints       = zap.Uints
	Uint8       = zap.Uint8
	Uint8s      = zap.Uint8s
	Uint16      = zap.Uint16
	Uint16s     = zap.Uint16s
	Uint32      = zap.Uint32
	Uint32s     = zap.Uint32s
	Uint64      = zap.Uint64
	Uint64s     = zap.Uint64s
	Uintptr     = zap.Uintptr
	Uintptrs    = zap.Uintptrs
)

Defines the alias for the zap type functions.

Functions

func Debug

func Debug(msg string, fields ...zap.Field)

func Debugf

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

func Error

func Error(msg string, fields ...Field)

func Errorf

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

func Errorw

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

func Fatal

func Fatal(msg string, fields ...Field)

func Fatalf

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

func Fatalw

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

func Flush

func Flush()

func Info

func Info(msg string, fields ...Field)

func Infof

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

func Init

func Init(opt *Option)

func Panic

func Panic(msg string, fields ...Field)

func Panicf

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

func Panicw

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

func Warn

func Warn(msg string, fields ...Field)

func Warnf

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

Types

type Field

type Field = zapcore.Field

Field is an alias for the field structure in the underlying log frame.

type Level

type Level = zapcore.Level

Level is an alias for zapcore.Level

type Logger

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

func NewLogger

func NewLogger(opt *Option) *Logger

func (*Logger) Debug

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

Debug logs a message at DebugLevel. The message includes any fields passed

func (*Logger) Debugf

func (l *Logger) Debugf(msg string, args ...interface{})

Debugf logs a message at DebugLevel.

func (*Logger) Error

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

Error logs a message at level Error on the standard logger.

func (*Logger) Errorf

func (l *Logger) Errorf(msg string, args ...interface{})

Errorf logs a message at level Error on the standard logger.

func (*Logger) Errorw

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

Errorw method output error level log.

func (*Logger) Fatal

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

Fatal method output fatal level log.

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, v ...interface{})

Fatalf method output fatal level log.

func (*Logger) Fatalw

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

Fatalw method output Fatalw level log.

func (*Logger) Flush

func (l *Logger) Flush()

func (*Logger) Info

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

Info logs a message at level Info on the standard logger.

func (*Logger) Infof

func (l *Logger) Infof(msg string, args ...interface{})

Infof logs a message at level Info on the standard logger.

func (*Logger) Panic

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

Panic method output panic level log and shutdown application.

func (*Logger) Panicf

func (l *Logger) Panicf(format string, v ...interface{})

Panicf method output panic level log and shutdown application.

func (*Logger) Panicw

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

Panicw method output panic level log.

func (*Logger) Warn

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

Warn logs a message at level Warn on the standard logger.

func (*Logger) Warnf

func (l *Logger) Warnf(msg string, args ...interface{})

Warnf logs a message at level Warn on the standard logger.

type Option

type Option struct {
	Level            string
	Format           string
	EnableColor      bool
	EnableCaller     bool
	OutputPaths      []string
	ErrorOutputPaths []string
	CallerSkip       int
}

Option represents a log option.

func DefaultOption

func DefaultOption() *Option

DefaultOption returns Option with the default value.

Jump to

Keyboard shortcuts

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