log

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 10 Imported by: 49

README

log

Chat Build License Go Reference Go Report Card codecov Release

Installation

go get -u github.com/no-src/log

Quick Start

Current support following loggers

  • empty logger
  • console logger
  • file logger
  • multi logger

For example, init a file logger, to write logs.

log.InitDefaultLogger(NewFileLogger(DebugLevel,"./logs",""))
log.Debug("%s,test debug log", "hello")
log.Info("%s,test info log", "hello")
log.Warn("%s,test warn log", "hello")
log.Error(errors.New("log err"), "%s,test error log", "hello")
log.Log("%s,test log log", "hello")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close() error

func Debug

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

func Error

func Error(err error, format string, args ...interface{})

func Info

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

func InitDefaultLogger

func InitDefaultLogger(logger Logger)

InitDefaultLogger init a default logger if InitDefaultLogger is not called, default is consoleLogger with InfoLevel

func Log

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

func Warn

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

Types

type Level

type Level int8
const (
	DebugLevel Level = iota
	InfoLevel
	WarnLevel
	ErrorLevel
	// NoneLevel disable all level log, except for the Writer.Log
	NoneLevel
)

func (Level) String

func (l Level) String() string

type Logger

type Logger interface {
	Debug(format string, args ...interface{})
	Info(format string, args ...interface{})
	Warn(format string, args ...interface{})
	Error(err error, format string, args ...interface{})
	Writer
}

Logger define a universal log interface

func DefaultLogger

func DefaultLogger() Logger

func NewConsoleLogger

func NewConsoleLogger(level Level) Logger

NewConsoleLogger get a console logger

func NewEmptyLogger

func NewEmptyLogger() Logger

NewEmptyLogger get an empty logger, there is nothing to do

func NewFileLogger

func NewFileLogger(level Level, logDir string, filePrefix string) (Logger, error)

NewFileLogger get a file logger

func NewFileLoggerWithAutoFlush

func NewFileLoggerWithAutoFlush(level Level, logDir string, filePrefix string, autoFlush bool, flushInterval time.Duration) (Logger, error)

NewFileLoggerWithAutoFlush get a file logger

func NewMultiLogger

func NewMultiLogger(loggers ...Logger) Logger

NewMultiLogger get a multi logger, write log to multiple loggers

type Writer

type Writer interface {
	io.Writer
	// Log write log to output
	Log(format string, args ...interface{})
	// Close to close log and release dependencies
	Close() error
}

Writer implement write to log

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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