目录
func LogSetFileFullName(fullname string)
func LogSetFilePath(filepath string)
func LogSetFileName(filename string)
func LogSetOsPerm(perm os.FileMode)
func LogSetMaxSize(logsize int64)
func LogSetOverPolicy(logop int)
1、github源码
https://github.com/hemy08/Debug
2、使用说明
下载源码,把里面的Debug目录拷贝到你的{GO_PATH}目录下,你可以自己建一个目录。
比如,我库上给的WebServer.go,我就是在{GO_PATH}下创建了WebServer目录,然后把Debug文件夹拷贝进去的。
然后在你的工程中import就可以了。
如import "WebServer/Debug"
3、工具说明
工具当前支持如下的功能:在api.go中有定义。
func LogSetFileFullName(fullname string)
设置日志文件全路径,如:F:\Gland Project\DebugTest\serverlog.log,如果不设置,默认是“./serverlog.log”。
func LogSetFilePath(filepath string)
设置日志文件路径,绝对路径和相对路径都可以,不设置,默认是“./”
func LogSetFileName(filename string)
设置日志文件名,包含后缀名,默认是“serverlog.log”
func LogSetOsFlag(flag int)
设置日志文件的读写模式,这个用在os.open函数中。默认参数是 os.O_RDWR|os.O_CREATE|os.O_APPEND,这些是os包里面的,go的标准库。可选参数如下:
const (
// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
O_RDONLY int = syscall.O_RDONLY // open the file read-only.
O_WRONLY int = syscall.O_WRONLY // open the file write-only.
O_RDWR int = syscall.O_RDWR // open the file read-write.
// The remaining values may be or'ed in to control behavior.
O_APPEND int = syscall.O_APPEND // append data to the file when writing.
O_CREATE int = syscall.O_CREAT // create a new file if none exists.
O_EXCL int = syscall.O_EXCL // used with O_CREATE, file must not exist.
O_SYNC int = syscall.O_SYNC // open for synchronous I/O.
O_TRUNC int = syscall.O_TRUNC // if possible, truncate file when opened.
)
func LogSetOsPerm(perm os.FileMode)
os的一个参数,取值如下:
const (
// The single letters are the abbreviations
// used by the String method's formatting.
ModeDir FileMode = 1 << (32 - 1 - iota) // d: is a directory
ModeAppend // a: append-only
ModeExclusive // l: exclusive use
ModeTemporary // T: temporary file; Plan 9 only
ModeSymlink // L: symbolic link
ModeDevice // D: device file
ModeNamedPipe // p: named pipe (FIFO)
ModeSocket // S: Unix domain socket
ModeSetuid // u: setuid
ModeSetgid // g: setgid
ModeCharDevice // c: Unix character device, when ModeDevice is set
ModeSticky // t: sticky
// Mask for the type bits. For regular files, none will be set.
ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice
ModePerm FileMode = 0777 // Unix permission bits
)
默认值0644
func LogSetLogMode(flag int)
设置日志记录模式。默认是L_DATE | L_LEVEL |L_FILE | L_LINE | L_FUNC,具体取值如下:
const (
L_NONE = 0x00000 //不加参数
L_DATE = 0x00001 //日期
L_LEVEL = 0x00002 //日志级别
L_FILE = 0x00004 //文件名
L_PATH = 0x00008 //文件路径
L_LINE = 0x00010 //文件行数
L_FUNC = 0x00020 //函数名
L_ALL = 0x00040 //全部
L_BUTT = 0xfffff //非法
)
func LogSetMaxSize(logsize int64)
设置日志文件大小,单位是M 默认10M
func LogSetOverPolicy(logop int)
设置日志文件超过设定大小时的策略,当前支持3种:
const (
L_DELETE = 0 //删除
L_RENAME_INDEX = 1 //加索引后缀
L_RENAME_DATE = 2 //加日期后缀
)