log

package module
v0.0.0-...-902d57f Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: MIT Imports: 10 Imported by: 0

README

log

The log system for GoLang.

Support:

1. Log level color output.
2. Log file today split.
3. Error traceback.

Usage:

1. On project add dir for config.
2. Add logs.toml config file to config dir.
3. The logs.toml file example.
[log]
    relative    = true          # true: Default use relative path, false: use absolute path.
    dir         =  "logs"       # Log storage directory.
    name        = "logs.log"    # Log filename.
    prefix      =  ""           # Prefix for cutting log filename.
    level       =  "INFO"       # The log level, if the value is OFF, then log off.

Documentation

Overview

Author: Kernel.Huang Mail: kernelman79@gmail.com Date: 3/18/21 1:01 PM Package: log

Author: Kernel.Huang Mail: kernelman79@gmail.com Date: 3/18/21 1:01 PM

Author: Kernel.Huang Mail: kernelman79@gmail.com File: config.go Date: 8/9/22 1:57 PM

Index

Constants

View Source
const DateFormat = "2006-01-02"
View Source
const TimeFormat = "2006-01-02 15:04:05"

Variables

View Source
var Logs = new(Services)
View Source
var Toml = new(TomlConfig)

Functions

func BootLogger

func BootLogger() (err error)

初始化日志配置

func CloseLogger

func CloseLogger()

关闭日志

func CurrentAndAbsPath

func CurrentAndAbsPath() string

当前执行程序的绝对路径

func GetAbsPath

func GetAbsPath(current string) string

获取当前执行程序的绝对路径

func GetConfigDir

func GetConfigDir() string

获取配置目录名

func GetConfigPath

func GetConfigPath() string

获取日志配置名

func GetCurrentDir

func GetCurrentDir() string

获取当前执行程序的绝对目录路径

func GetCustomConfigDir

func GetCustomConfigDir(dirname string) string

Get config dir of custom

func GetCustomConfigPath

func GetCustomConfigPath(dirname string, filename string) string

Get config path

func GetLastPath

func GetLastPath(currentPath string) string

获取路径的上个目录

func GetLogsDir

func GetLogsDir() string

获取日志目录

func GetLogsFilename

func GetLogsFilename() string

获取日志文件名

func GetLogsLevel

func GetLogsLevel() string

获取日志级别, 值为OFF则关闭日志

func GetLogsPrefix

func GetLogsPrefix() string

获取日志文件内容前缀

func GetRootPath

func GetRootPath() string

获取项目根目录

func SetCurrentPath

func SetCurrentPath() string

设置当前执行程序的绝对路径

Types

type LEVEL

type LEVEL byte
const (
	TRACE LEVEL = iota
	DEBUG
	INFO
	WARN
	ERROR
	OFF
)

type LoggerConf

type LoggerConf struct {
	FileDir  string
	FileName string
	Prefix   string
	Level    string
}

type Services

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

func (*Services) Debug

func (f *Services) Debug(format string, v ...interface{})

输出调试日志

func (*Services) Error

func (f *Services) Error(format string, v ...interface{})

输出错误日志

func (*Services) Fatal

func (f *Services) Fatal(v ...interface{})

输出致命错误日志, 并退出系统

func (*Services) Fatally

func (f *Services) Fatally(v ...interface{})

输出致命错误日志, 并退出系统

func (*Services) Info

func (f *Services) Info(format string, v ...interface{})

输出信息日志

func (*Services) Print

func (f *Services) Print(v ...interface{})

输出格式化日志

func (*Services) Printf

func (f *Services) Printf(format string, v ...interface{})

输出格式化日志

func (*Services) Println

func (f *Services) Println(v ...interface{})

输出格式化日志

func (*Services) Trace

func (f *Services) Trace(format string, v ...interface{})

输出跟踪日志

func (*Services) Warning

func (f *Services) Warning(format string, v ...interface{})

输出警告日志

type TomlConfig

type TomlConfig struct {
	Structured interface{}
	// contains filtered or unexported fields
}

func GetToml

func GetToml() *TomlConfig

获取Toml配置解析服务

func (*TomlConfig) AtBool

func (tf *TomlConfig) AtBool() bool

Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Get("key").AtBool()

func (*TomlConfig) AtInt

func (tf *TomlConfig) AtInt() int

Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Get("key").AtInt()

func (*TomlConfig) AtStr

func (tf *TomlConfig) AtStr() string

Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Get("key").AtStr()

func (*TomlConfig) Fetch

func (tf *TomlConfig) Fetch(key string) *TomlConfig

Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Fetch("key").ToStr()

func (*TomlConfig) Get

func (tf *TomlConfig) Get(key string) *TomlConfig

Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Get("key").To()

func (*TomlConfig) NewToml

func (tf *TomlConfig) NewToml(dirname string, filename string) *TomlConfig

func (*TomlConfig) Read

func (tf *TomlConfig) Read(key string) *TomlConfig

Example: result := Tome.NewToml(dirname, filename).Read("zoneName.key").ToStr() or ToInt()

func (*TomlConfig) To

func (tf *TomlConfig) To() interface{}

*

  • Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Get("key").To()

func (*TomlConfig) ToBool

func (tf *TomlConfig) ToBool() bool

Example: result := Tome.NewToml(dirname, filename).Read("zoneName.key").ToBool()

func (*TomlConfig) ToInt

func (tf *TomlConfig) ToInt() int

Example: result := Tome.NewToml(dirname, filename).Read("zoneName.key").ToInt()

func (*TomlConfig) ToStr

func (tf *TomlConfig) ToStr() string

Example: result := Tome.NewToml(dirname, filename).Read("zoneName.key").ToStr()

func (*TomlConfig) Zone

func (tf *TomlConfig) Zone(key string) *TomlConfig

Example: result := Tome.NewToml(dirname, filename).Zone("zoneName").Get("key").To()

Jump to

Keyboard shortcuts

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