Documentation ¶
Overview ¶
Package logs provide a general log interface Usage:
import "github.com/astaxie/beego/logs"
log := NewLogger(10000) log.AddAdapter("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
- Variables
- func Bytes2String(b []byte) string
- func Register(name string, log loggerType)
- func String2Bytes(s string) []byte
- type BeeLogger
- func (bl *BeeLogger) AddAdapter(adapterName string, config string) error
- func (bl *BeeLogger) Alert(format string, v ...interface{})
- func (bl *BeeLogger) Close()
- func (bl *BeeLogger) Critical(format string, v ...interface{})
- func (bl *BeeLogger) Debug(format string, v ...interface{})
- func (bl *BeeLogger) DelAdapter(adapterName string) error
- func (bl *BeeLogger) Emergency(format string, v ...interface{})
- func (bl *BeeLogger) EnableFuncCallDepth(b bool)
- func (bl *BeeLogger) Error(format string, v ...interface{})
- func (bl *BeeLogger) Fatal(format string, v ...interface{})
- func (bl *BeeLogger) Flush()
- func (bl *BeeLogger) GetLogFuncCallDepth() int
- func (bl *BeeLogger) Info(format string, v ...interface{})
- func (bl *BeeLogger) Notice(format string, v ...interface{})
- func (bl *BeeLogger) Reset()
- func (bl *BeeLogger) SetLevel(l int)
- func (bl *BeeLogger) SetLogFuncCallDepth(d int)
- func (bl *BeeLogger) SetMsgChan(channelLen int64)
- func (bl *BeeLogger) Sys(format string, v ...interface{})
- func (bl *BeeLogger) Warn(format string, v ...interface{})
- func (bl *BeeLogger) Write(p []byte) (n int, err error)
- type Logger
- type SMTPWriter
Constants ¶
const ( LevelSystem = iota LevelFatal LevelEmergency LevelAlert LevelCritical LevelError LevelWarning LevelNotice LevelInformational LevelDebug )
log message levels.
Variables ¶
var Prefix = map[int]string{ LevelSystem: "", LevelFatal: "[F]", LevelEmergency: "[M]", LevelAlert: "[A]", LevelCritical: "[C]", LevelError: "[E]", LevelWarning: "[W]", LevelNotice: "[N]", LevelInformational: "[I]", LevelDebug: "[D]", }
Functions ¶
func Bytes2String ¶ added in v0.7.0
Bytes2String直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变。 效率是string([]byte{})的百倍以上,且转换量越大效率优势越明显。
func Register ¶
func Register(name string, log loggerType)
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 String2Bytes ¶ added in v0.7.0
String2Bytes直接转换底层指针,两者指向的相同的内存,改一个另外一个也会变。 效率是string([]byte{})的百倍以上,且转换量越大效率优势越明显。 转换之后若没做其他操作直接改变里面的字符,则程序会崩溃。 如 b:=String2bytes("xxx"); b[1]='d'; 程序将panic。
Types ¶
type BeeLogger ¶
type BeeLogger 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 (*BeeLogger) AddAdapter ¶
AddAdapter provides a given logger adapter into BeeLogger with config string. config need to be correct JSON as string: {"interval":360}.
func (*BeeLogger) Close ¶
func (bl *BeeLogger) Close()
Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func (*BeeLogger) DelAdapter ¶
DelLogger remove a logger adapter in BeeLogger.
func (*BeeLogger) EnableFuncCallDepth ¶
EnableFuncCallDepth enable log funcCallDepth
func (*BeeLogger) GetLogFuncCallDepth ¶
GetLogFuncCallDepth return log funcCallDepth for wrapper
func (*BeeLogger) Reset ¶
func (bl *BeeLogger) Reset()
Reset close all outputs, and set bl.outputs to nil
func (*BeeLogger) 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 (*BeeLogger) SetLogFuncCallDepth ¶
SetLogFuncCallDepth set log funcCallDepth
func (*BeeLogger) SetMsgChan ¶
type Logger ¶
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 }
func (*SMTPWriter) WriteMsg ¶
func (s *SMTPWriter) WriteMsg(lm logMsg) error
WriteMsg write message in smtp writer. it will send an email with subject and only this message.