gwtools

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

README

gwtools

一、介绍

日志及一些公共函数、工具的集合

二、文件
  1. gwlog:日志,包含输出日志到cmd、文件、udp输出3个选择
  2. gwutils:一些功能函数
三、版本更迭
版本标记 发行版版本号 说明
20220606: true RandomString v1.0.5
20220621: divide v1.0.6
20220704: Local_path v1.0.7
四、发行版v1.0.7
1. 说明

更新了 Local_path 、 Local_exe 的获取方式(使用Args[0]获取绝对路径)

五、发行版v1.0.6
1. 下载

直接下载指定版本:

go get gitee.com/ahaqvv/gwtools@v1.0.6

使用go mod:

go mod tidy

go mod download gitee.com/ahaqvv/gwtools@v1.0.6

2.更新内容
  1. 增加按照小时划分日志的功能
  2. 命令行输出不使用管道
  3. 优化退出逻辑
  4. 删除gwutils中,进程调用函数及第三方库
  5. 删除LogM函数
  6. 增加LogE函数,提供err功能的直接输出
3. 直接输出到命令行

示例:

gwtools.LogK("sts",time.Now())

输出:

[16:30:14 10 sts] 2022-06-21 16:30:14.4579175 +0800 CST m=+0.004449501

示例:

gwtools.StartLog("cmd")
defer gwtools.StopLog()
gwtools.LogK("sts",time.Now())

输出:

[16:38:58 13 sts] 2022-06-21 16:38:58.9847457 +0800 CST m=+0.023670701
4.输出到日志(默认程序路径)

示例:

gwtools.StartLog("file")
defer gwtools.StopLog()
gwtools.LogK("here","here")

输出:

[16:31:19 0 sts] -----------start program-----------
[16:31:19 12 here] here 

说明:

将在程序路径生成 "log+程序名" 的文件夹,日志按照时间划分存入其中
5.输出到日志(指定路径)

示例:

gwtools.NewByOption(gwtools.WithPath("C:\\ttt"))
gwtools.StartLog("file")
defer gwtools.StopLog()
gwtools.LogK("here","here")
6.输出到udp端口

示例:

gwtools.NewByOption(gwtools.WithUdp("127.0.0.1",7000))
gwtools.StartLog("udp")
defer gwtools.StopLog()
gwtools.LogK("here","here")
7.日志输出时,按照时间划分文件

默认按照 "天" 划分文件,一天一个日志,按照 yyyy-MM-dd.log 格式生成日志文件

可配置按照 ”小时“ 划分文件,一个小时一个日志,按照 yyyy-MM-dd-hh.log 格式生成日志文件

示例:

gwtools.NewByOption(gwtools.WithDivide("h"))
gwtools.StartLog("file")
defer gwtools.StopLog()
for true {
	gwtools.LogK("here",time.Now().String())
	time.Sleep(time.Second*20)
}

Documentation

Index

Constants

View Source
const (
	TimeYMD = "2006-01-02"
	TimeHMS = "15:04:05"
)

Variables

View Source
var (
	Local_path string
	Local_exe  string
	Local_sep  string
)

Functions

func GTime

func GTime() string

func GetFirst

func GetFirst(list []string) (str string)

func GetLast

func GetLast(list []string) (str string)

func GetVersion

func GetVersion() (ver string)

func Gfl

func Gfl() (fl string)

func LogE added in v1.0.6

func LogE(msg ...interface{})

func LogK

func LogK(kind string, msg ...interface{})

func LogSkip added in v1.0.6

func LogSkip(msg interface{}, kind string, skip int)

func NewByOption

func NewByOption(opts ...Option)

func PathExists

func PathExists(path string) (bool, error)

判断文件夹是否存在

func RandomString

func RandomString(n int, allowedChars ...[]rune) string

RandomString returns a random string with a fixed length

func RandomStringFake added in v1.0.5

func RandomStringFake(n int, allowedChars ...[]rune) string

Fake Random string

func Slice2String

func Slice2String(msg []interface{}) (str string)

func StartLog

func StartLog(log_type ...string)

初始化日志参数,并启动日志系统

func StopLog

func StopLog() bool

func TempLog

func TempLog(temp string)

func TestLog

func TestLog()

func TimeExitLog added in v1.0.4

func TimeExitLog(d time.Duration, msg string) (sigmsg os.Signal)

func TimeLog

func TimeLog(d time.Duration, msg string)

持续运行日志,必须使用协程运行

Types

type Gwlog

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

单条日志数据

func (*Gwlog) GetString

func (this *Gwlog) GetString() (str string)

type LogOption

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

用于option模式

type Option

type Option func(lo *LogOption)

func WithDivide added in v1.0.6

func WithDivide(divide string) Option

func WithPath

func WithPath(path string) Option

func WithUdp

func WithUdp(ip string, port int) Option

Jump to

Keyboard shortcuts

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