simplelog

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

README

simplelog

对GO日志的简易封装

Installation

> go get github.com/ldjx7/simplelog

demo

package main

import (
	"github.com/ldjx7/simplelog"
)

# 显示初始化log配置,指定日志文件路径,文件名称以及日志级别
# 默认路径为applog/logs,日志级别为:info,默认文件名称为root_日期.log
func init() {
	simplelog.InitSimpleLog(&simplelog.Config{
		LogLevel: simplelog.LevelError,
		LogDir:   "logs",
		LogFile:  "log",
	})
}
# 也可以不显示初始化,直接导包使用,所有的配置均为默认
func main() {
	simplelog.Debug("hello world")
	simplelog.Info("hello world")
	simplelog.Warn("hello world")
	simplelog.Error("hello world")
}

Documentation

Index

Constants

View Source
const (
	LevelDebug = "debug"
	LevelInfo  = "info"
	LevelWarn  = "warn"
	LevelError = "error"
	LevelFatal = "fatal"
)

Variables

View Source
var LevelMap = map[string]int{
	LevelDebug: levelDebug,
	LevelInfo:  levelInfo,
	LevelWarn:  levelWarning,
	LevelError: levelError,
	LevelFatal: levelFatal,
}
View Source
var LogFile *os.File

Functions

func Debug

func Debug(format string, v ...any)

func Error

func Error(format string, v ...any)

func Fatal

func Fatal(format string, v ...any)

func Info

func Info(format string, v ...any)

func InitSimpleLog

func InitSimpleLog(config *Config)

InitSimpleLog 日志初始化函数

func Warn

func Warn(format string, v ...any)

Types

type Config

type Config struct {
	LogDir   string
	LogLevel string
	LogFile  string
}

Config 日志配置结构体

type LogBuild

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

func NewLogBuilder

func NewLogBuilder(level int, format, errStack string, v ...any) *LogBuild

Jump to

Keyboard shortcuts

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