logs

package
v0.0.0-...-377a973 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UNKNOWN logLevel = iota
	DEBUG
	TRACE
	INFO
	WARNING
	ERROR
	FATAL
)

从上往下,日志级别越高

Variables

View Source
var (
	Flog *FileLog   //文件日志对象
	Slog *StdoutLog //标准输出对象
	Elog *EmailLog  //email对象

)

Functions

func Close

func Close()

func Debug

func Debug(out, format string, a ...interface{})

func Dial

func Dial(addr string) (*smtp.Client, error)

return a smtp client

func Error

func Error(out, format string, a ...interface{})

func Fatal

func Fatal(out, format string, a ...interface{})

func GetLevel

func GetLevel(levelStr string) (level logLevel, err error)

获取等级

func GetLevelStr

func GetLevelStr(level logLevel) (levelStr string)

获取等级的字符串

func Info

func Info(out, format string, a ...interface{})

func InitLog

func InitLog()

初始化日志

func SendMailUsingTLS

func SendMailUsingTLS(addr string, auth smtp.Auth, from string,
	to []string, msg []byte) (err error)

参考net/smtp的func SendMail() 使用net.Dial连接tls(ssl)端口时,smtp.NewClient()会卡住且不提示err len(to)>1时,to[1]开始提示是密送

func Trace

func Trace(out, format string, a ...interface{})

func Warning

func Warning(out, format string, a ...interface{})

Types

type EmailLog

type EmailLog struct {
	Enable       bool            `conf:"enable"`         //配置文件中,是否启用
	Level        logLevel        `conf:"run_level"`      //配置文件中,email日志等级.
	Host         string          `conf:"host"`           // 邮箱服务器地址,如smtp.163.com
	Port         int             `conf:"port"`           //邮箱服务器端口,如25,465
	SendEmail    string          `conf:"send_email"`     //发件人邮箱地址
	SendPasswd   string          `conf:"send_passwd"`    //发件人邮箱密码(明文形式)
	Recipient    string          `conf:"recipient"`      // 接收者.如有多个,则以英文逗号(,)隔开
	EmailCC      string          `conf:"emailCC"`        // 抄送者.如有多个,则以英文逗号(,)隔开
	MaxEmailChan int             `conf:"max_email_chan"` //异步发送邮件,最大缓存邮件数
	Mail         *gomail.Message //发邮件对象
	EmailChan    chan *emailMsg  //邮件日志存放管道
}

func NewEmailLog

func NewEmailLog(enable bool, levelStr, host string, port int, sendEmail, sendPasswd, recipient, emailCC string, maxEmailChan int) *EmailLog

func (*EmailLog) Close

func (e *EmailLog) Close()

func (*EmailLog) Debug

func (e *EmailLog) Debug(format string, a ...interface{})

func (*EmailLog) Error

func (e *EmailLog) Error(format string, a ...interface{})

func (*EmailLog) Fatal

func (e *EmailLog) Fatal(format string, a ...interface{})

func (*EmailLog) Info

func (e *EmailLog) Info(format string, a ...interface{})

func (*EmailLog) SendEmailLog

func (e *EmailLog) SendEmailLog(subject, body string)

SendEmail body支持html格式字符串

func (*EmailLog) Trace

func (e *EmailLog) Trace(format string, a ...interface{})

func (*EmailLog) Unknown

func (e *EmailLog) Unknown(format string, a ...interface{})

func (*EmailLog) Warning

func (e *EmailLog) Warning(format string, a ...interface{})

type FileLog

type FileLog struct {
	Enable      bool         `conf:"enable"`        //配置文件中,是否启用
	Level       logLevel     `conf:"run_level"`     //配置文件中,file日志等级.
	FilePath    string       `conf:"file_path"`     //配置文件中,文件路径.
	FileName    string       `conf:"file_name"`     //配置文件中,文件名.
	MaxFileSize int64        `conf:"max_file_size"` //配置文件中,日志文件最大大小.
	MaxLogChan  int          `conf:"max_log_chan"`  //配置文件中,日志存放管道最大数
	FileObj     *os.File     //标准日志文件对象.
	ErrFileObj  *os.File     //单独错误日志文件对象.
	LogChan     chan *logMsg //日志存放管道
}

输出到文件.

func NewFileLog

func NewFileLog(enable bool, levelStr, filePath, fileName string, maxFileSize int64, maxLogChan int) (fileLog *FileLog)

func (*FileLog) Close

func (f *FileLog) Close()

func (*FileLog) Debug

func (f *FileLog) Debug(format string, a ...interface{})

func (*FileLog) Error

func (f *FileLog) Error(format string, a ...interface{})

func (*FileLog) Fatal

func (f *FileLog) Fatal(format string, a ...interface{})

func (*FileLog) Info

func (f *FileLog) Info(format string, a ...interface{})

func (*FileLog) Trace

func (f *FileLog) Trace(format string, a ...interface{})

func (*FileLog) Unknown

func (f *FileLog) Unknown(format string, a ...interface{})

func (*FileLog) Warning

func (f *FileLog) Warning(format string, a ...interface{})

type StdoutLog

type StdoutLog struct {
	Enable bool     `conf:"enable"`    //配置文件中,是否启用
	Level  logLevel `conf:"run_level"` //配置文件中,标准输出日志等级.
}

输出到标准控制台.

func NewStdoutLog

func NewStdoutLog(enable bool, levelStr string) *StdoutLog

func (*StdoutLog) Close

func (c *StdoutLog) Close()

func (*StdoutLog) Debug

func (c *StdoutLog) Debug(format string, a ...interface{})

func (*StdoutLog) Error

func (c *StdoutLog) Error(format string, a ...interface{})

func (*StdoutLog) Fatal

func (c *StdoutLog) Fatal(format string, a ...interface{})

func (*StdoutLog) Info

func (c *StdoutLog) Info(format string, a ...interface{})

func (*StdoutLog) Trace

func (c *StdoutLog) Trace(format string, a ...interface{})

func (*StdoutLog) Unknown

func (c *StdoutLog) Unknown(format string, a ...interface{})

func (*StdoutLog) Warning

func (c *StdoutLog) Warning(format string, a ...interface{})

Jump to

Keyboard shortcuts

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