log

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 9 Imported by: 0

README

log

Simple log support stdout, file, syslog

Examples

package main

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

func main() {
	//log, err := log.New(log.LogTypeSyslog, log.LogLevelDebug, "simple")
	log, err := log.New(log.LogTypeStdoutColor, log.LogLevelDebug, "simple")
	if err == nil {
		defer log.Close()
		log.Debugf("debug message: %d", 1)
		log.Infof("info message: %d", 1)
		log.Errorf("error message: %d", 1)
		log.Fatalf("fatalf message: %d", 1)
	}
}

Documentation

Index

Constants

View Source
const (
	LogLevelFatal = iota
	LogLevelError
	LogLevelInfo
	LogLevelDebug
)
View Source
const (
	LogTypeNull = iota
	LogTypeStdout
	LogTypeStdoutColor
	LogTypeSyslog
	LogTypeFile
)

Variables

View Source
var (
	ErrInvalidLogType = errors.New("Invalid log type")
)

Functions

func NewFileRotate added in v0.2.0

func NewFileRotate(fileName string, age time.Duration, size int64, num int) (io.WriteCloser, error)

age may be 0. size may be 0

Types

type Log

type Log interface {
	Fatalf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Write(p []byte) (n int, err error)
	Close() error
	SetMinLevel(level int)
	MinLevel() int
}

func New

func New(logType, minLevel int, param string) (l Log, err error)

param: - LogTypeNull, LogTypeStdout, LogTypeStdoutColor: ignore - LogTypeSyslog: tag - LogTypeFile: fileName

func NewFile

func NewFile(name string, minLevel int) (l Log, err error)

func NewNull

func NewNull() Log

func NewStdout

func NewStdout(minLevel int) Log

func NewStdoutColor

func NewStdoutColor(minLevel int) Log

func NewSyslog

func NewSyslog(tag string, minLevel int) (l Log, err error)

Jump to

Keyboard shortcuts

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