Documentation ¶
Overview ¶
Package logs provide a general log interface Usage:
import "github.com/astaxie/beego/logs"
log := NewLogger(10000) log.SetLogger("console", "") > the first params stand for how many channel
Use it like this:
log.Trace("trace") log.Info("info") log.Warn("warning") log.Debug("debug") log.Critical("critical") more docs http://beego.me/docs/module/logs.md
Index ¶
- Constants
- func Alert(f interface{}, v ...interface{})
- func Begin()
- func CheckError(pos string, err error)
- func ColorByMethod(method string) string
- func ColorByStatus(code int) string
- func Critical(f interface{}, v ...interface{})
- func Debug(f interface{}, v ...interface{})
- func Emergency(f interface{}, v ...interface{})
- func End()
- func Error(f interface{}, v ...interface{})
- func GetLastLogTime() time.Time
- func GetLevel() int
- func GetLevelName(level int) string
- func GetLogger(prefixes ...string) *log.Logger
- func GetNow() (result time.Time)
- func GetParamBool(name string, flag_value bool) bool
- func GetParamInt(name string, flag_value int) int
- func GetParamString(name string, flag_value, default_value string) string
- func Info(f interface{}, v ...interface{})
- func Notice(f interface{}, v ...interface{})
- func Print(f interface{}, v ...interface{})
- func Register(name string, log newLoggerFunc)
- func Reset()
- func ResetColor() string
- func SetLevel(l int)
- func SetLogFuncCallDepth(d int)
- func SetLogger(adapter string, config ...string) error
- func Warning(f interface{}, v ...interface{})
- type Logger
- type SMTPWriter
- type TLogger
- func (bl *TLogger) Alert(format string, v ...interface{})
- func (bl *TLogger) Async(msgLen ...int64) *TLogger
- func (bl *TLogger) Begin()
- func (bl *TLogger) Close()
- func (bl *TLogger) Critical(format string, v ...interface{})
- func (bl *TLogger) Debug(format string, v ...interface{})
- func (bl *TLogger) DelLogger(adapterName string) error
- func (bl *TLogger) Emergency(format string, v ...interface{})
- func (bl *TLogger) End()
- func (bl *TLogger) Error(format string, v ...interface{})
- func (bl *TLogger) Flush()
- func (bl *TLogger) GetCallStack() (level int, stack string, file string, line int)
- func (bl *TLogger) GetClassName(func_name string) string
- func (bl *TLogger) GetLastLogTime() time.Time
- func (bl *TLogger) GetLevel() int
- func (bl *TLogger) GetLogFuncCallDepth() int
- func (bl *TLogger) Info(format string, v ...interface{})
- func (bl *TLogger) Notice(format string, v ...interface{})
- func (bl *TLogger) Print(format string, v ...interface{})
- func (bl *TLogger) Reset()
- func (bl *TLogger) SetLevel(l int)
- func (bl *TLogger) SetLogFuncCallDepth(d int)
- func (bl *TLogger) SetLogger(adapterName string, configs ...string) error
- func (bl *TLogger) Warning(format string, v ...interface{})
- func (bl *TLogger) Write(p []byte) (n int, err error)
Constants ¶
const ( LevelEmergency = iota //事故 LevelAlert //警报 LevelCritical //危险 LevelError //错误 LevelWarning //警告 LevelNotice //通知 LevelInfo //信息 LevelDebug //调试 LevelPrint //打印(直接显示内容,不显示前缀) )
RFC5424 log message levels.
const ( AdapterConsole = "console" AdapterFile = "file" AdapterMultiFile = "multifile" AdapterMail = "smtp" AdapterConn = "conn" AdapterEs = "es" AdapterJianLiao = "jianliao" AdapterSlack = "slack" )
Name for adapter with beego official support
Variables ¶
This section is empty.
Functions ¶
func CheckError ¶
func ColorByMethod ¶
ColorByMethod return color by http code
func ColorByStatus ¶
ColorByStatus return color by http code 2xx return Green 3xx return White 4xx return Yellow 5xx return Red
func Critical ¶
func Critical(f interface{}, v ...interface{})
Critical logs a message at critical level.
func Emergency ¶
func Emergency(f interface{}, v ...interface{})
Emergency logs a message at emergency level.
func GetLastLogTime ¶
func GetLevelName ¶
func GetParamBool ¶
func GetParamInt ¶
func GetParamString ¶
func Register ¶
func Register(name string, log newLoggerFunc)
Register makes a log provide available by the provided name. If Register is called twice with the same name or if driver is nil, it panics.
func SetLogFuncCallDepth ¶
func SetLogFuncCallDepth(d int)
SetLogFuncCallDepth set log funcCallDepth
Types ¶
type Logger ¶
type Logger interface { Init(config string) error //WriteMsg(when time.Time, msg string, level int) error WriteMsg(fileName string, fileLine int, callLevel int, callFunc string, logLevel int, when time.Time, msg string) error Destroy() Flush() }
Logger defines the behavior of a log provider.
func NewConsole ¶
func NewConsole() Logger
NewConsole create ConsoleWriter returning as LoggerInterface.
type SMTPWriter ¶
type SMTPWriter struct { Username string `json:"username"` Password string `json:"password"` Host string `json:"host"` Subject string `json:"subject"` FromAddress string `json:"fromAddress"` RecipientAddresses []string `json:"sendTos"` Level int `json:"level"` }
SMTPWriter implements LoggerInterface and is used to send emails via given SMTP-server.
func (*SMTPWriter) Init ¶
func (s *SMTPWriter) Init(jsonconfig string) error
Init smtp writer with json config. config like:
{ "username":"example@gmail.com", "password:"password", "host":"smtp.gmail.com:465", "subject":"email title", "fromAddress":"from@example.com", "sendTos":["email1","email2"], "level":LevelError }
type TLogger ¶
type TLogger struct {
// contains filtered or unexported fields
}
BeeLogger is default logger in beego application. it can contain several providers and log message into all providers.
func NewLogger ¶
NewLogger returns a new BeeLogger. channelLen means the number of messages in chan(used where asynchronous is true). if the buffering chan is full, logger adapters write to file or other way.
func (*TLogger) Close ¶
func (bl *TLogger) Close()
Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func (*TLogger) GetCallStack ¶
func (*TLogger) GetClassName ¶
github.com/tea4go/application/myproxy/service.THTTP.StartServer
func (*TLogger) GetLastLogTime ¶
func (*TLogger) GetLogFuncCallDepth ¶
GetLogFuncCallDepth return log funcCallDepth for wrapper
func (*TLogger) Reset ¶
func (bl *TLogger) Reset()
Reset close all outputs, and set bl.outputs to nil
func (*TLogger) SetLevel ¶
SetLevel Set log message level. If message level (such as LevelDebug) is higher than logger level (such as LevelWarning), log providers will not even be sent the message.
func (*TLogger) SetLogFuncCallDepth ¶
SetLogFuncCallDepth set log funcCallDepth
func (*TLogger) SetLogger ¶
SetLogger provides a given logger adapter into BeeLogger with config string. config need to be correct JSON as string: {"interval":360}.