gologger

package module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

1 log级别

DEBUG INFO WARNING ERROR FATAL

2 输出方式

file 文件形式,默认100m自动切割,本地存储 console 控制台直接输出

3 quick start

引入:go get gitee.com/fengpiaoyao/gologger

package main

import (
	"fmt"
	"os"
	"time"
	"gitee.com/fengpiaoyao/gologger"
	"gopkg.in/ini.v1"
)

func main() {
	cfg, err := ini.Load("my.ini")
	if err != nil {
		fmt.Printf("Fail to read file: %v", err)
		os.Exit(1)
	}
	logLv := cfg.Section("log").Key("level").String()
	outPutType := cfg.Section("log").Key("type").String()

	mylog := gologger.FotmatLog(logLv, outPutType, cfg.Section("log").Key("path").String())

	for {
		_, err := os.Open("d:/mytest.txt")
		if err != nil {
			mylog.ERROR("错误信息", err)
		}
		mylog.DEBUG("debug日志")
		mylog.INFO("info日志")
		mylog.WARNING("WARNING")
		name := "什么啊"
		mylog.ERROR("ERROR,id %s", name)
		mylog.FATAL("FATAL")
		time.Sleep(time.Second)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConsoleLogger

type ConsoleLogger struct {
	Level LogLevel
}
var Default *ConsoleLogger

func NewConsoleLogger

func NewConsoleLogger(levelStr string) *ConsoleLogger

构造函数

func (*ConsoleLogger) DEBUG

func (c *ConsoleLogger) DEBUG(fotmat string, a ...interface{})

func (*ConsoleLogger) ERROR

func (c *ConsoleLogger) ERROR(fotmat string, a ...interface{})

func (*ConsoleLogger) FATAL

func (c *ConsoleLogger) FATAL(fotmat string, a ...interface{})

func (*ConsoleLogger) INFO

func (c *ConsoleLogger) INFO(fotmat string, a ...interface{})

func (*ConsoleLogger) WARNING

func (c *ConsoleLogger) WARNING(fotmat string, a ...interface{})

type FileLogger

type FileLogger struct {
	Level LogLevel

	MaxSize int64
	// contains filtered or unexported fields
}

func NewFileLogger

func NewFileLogger(levelStr, fp, fn string, maxSize int64) *FileLogger

构造函数

func (*FileLogger) DEBUG

func (f *FileLogger) DEBUG(fotmat string, a ...interface{})

func (*FileLogger) ERROR

func (f *FileLogger) ERROR(fotmat string, a ...interface{})

错误日志

func (*FileLogger) FATAL

func (f *FileLogger) FATAL(fotmat string, a ...interface{})

func (*FileLogger) INFO

func (f *FileLogger) INFO(fotmat string, a ...interface{})

func (*FileLogger) WARNING

func (f *FileLogger) WARNING(fotmat string, a ...interface{})

func (*FileLogger) WriteToFile added in v0.2.0

func (f *FileLogger) WriteToFile()

type LogLevel

type LogLevel uint
const (
	UNKNOWN LogLevel = iota
	DEBUG
	INFO
	WARNING
	ERROR
	FATAL
)

type LogOutPut

type LogOutPut interface {
	DEBUG(fotmat string, a ...interface{})
	INFO(fotmat string, a ...interface{})
	WARNING(fotmat string, a ...interface{})
	ERROR(fotmat string, a ...interface{})
	FATAL(fotmat string, a ...interface{})
	// contains filtered or unexported methods
}

func FotmatLog added in v0.1.2

func FotmatLog(loglevel, outPutType string, path ...string) LogOutPut

格式化输出信息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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