log

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 5 Imported by: 33

README

log

Base logger. Define different log level and logger interface

How to use
go get github.com/coreservice-io/log
example
package main

import (
	"os"

	"github.com/coreservice-io/log"
)

func main() {

	l := log.NewBaseLogger()

	//default logLevel is Info
	l.SetLevel(log.TraceLevel)

	//default output is StdOut
	f, _ := os.Create("logFile")
	l.SetOutput(f)

	l.Traceln("trace", 1)
	l.Debugln("debug", 2)
	l.Infoln("info", 3)
	l.Warnln("warn", 4)
	l.Errorln("error", 5)
	l.PrintLastN(1000, []log.LogLevel{})
	//l.Fatalln("fatal", 6)
	//l.Panicln("panic")
	
}

Documentation

Index

Constants

View Source
const (
	PanicTagStr logTag = "[PANI]"
	FatalTagStr logTag = "[FATA]"
	ErrorTagStr logTag = "[ERRO]"
	WarnTagStr  logTag = "[WARN]"
	InfoTagStr  logTag = "[INFO]"
	DebugTagStr logTag = "[DEBU]"
	TraceTagStr logTag = "[TRAC]"
)

Variables

This section is empty.

Functions

func LogLevelToTag

func LogLevelToTag(level LogLevel) logTag

Types

type LogLevel

type LogLevel int32
const (
	// PanicLevel level, highest level of severity. Logs and then calls panic with the
	// message passed to Debug, Info, ...
	PanicLevel LogLevel = iota
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. It will exit even if the
	// logging level is set to Panic.
	FatalLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel
)

func ParseLogLevel

func ParseLogLevel(levelStr string) LogLevel

type Logger

type Logger interface {
	SetOutput(w io.Writer)
	SetLevel(v LogLevel)
	GetLevel() LogLevel
	Traceln(i ...interface{})
	Debugln(i ...interface{})
	Infoln(i ...interface{})
	Warnln(i ...interface{})
	Errorln(i ...interface{})
	Fatalln(i ...interface{})
	Panicln(i ...interface{})
	PrintLastN(int64, []LogLevel)                 //print out last n lines of logs with specified levels sorted by time
	GetLastN(int64, []LogLevel) ([]string, error) //return last n lines of logs with specified levels sorted by time
}

Logger defines the logging interface.

func NewBaseLogger

func NewBaseLogger() Logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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