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 ColorByMethod(cond bool, method string) string
- func ColorByStatus(cond bool, code int) string
- func Critical(f interface{}, v ...interface{})
- func Debug(f interface{}, v ...interface{})
- func Emergency(f interface{}, v ...interface{})
- func EnableFuncCallDepth(b bool)
- func Error(f interface{}, v ...interface{})
- func GetLogger(prefixes ...string) *log.Logger
- func Info(f interface{}, v ...interface{})
- func Informational(f interface{}, v ...interface{})
- func NewAnsiColorWriter(w io.Writer) io.Writer
- func NewModeAnsiColorWriter(w io.Writer, mode outputMode) io.Writer
- func Notice(f interface{}, v ...interface{})
- func Register(name string, log newLoggerFunc)
- func Reset()
- func SetLevel(l int)
- func SetLogFuncCall(b bool)
- func SetLogFuncCallDepth(d int)
- func SetLogger(adapter string, config ...string) error
- func Trace(f interface{}, v ...interface{})
- func W32Debug(msg string)
- func Warn(f interface{}, v ...interface{})
- func Warning(f interface{}, v ...interface{})
- type BeeLogger
- func (bl *BeeLogger) Alert(format string, v ...interface{})
- func (bl *BeeLogger) Async(msgLen ...int64) *BeeLogger
- func (bl *BeeLogger) Close()
- func (bl *BeeLogger) Critical(format string, v ...interface{})
- func (bl *BeeLogger) Debug(format string, v ...interface{})
- func (bl *BeeLogger) DelLogger(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) Flush()
- func (bl *BeeLogger) GetLogFuncCallDepth() int
- func (bl *BeeLogger) Info(format string, v ...interface{})
- func (bl *BeeLogger) Informational(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) SetLogger(adapterName string, configs ...string) error
- func (bl *BeeLogger) Trace(format string, v ...interface{})
- func (bl *BeeLogger) Warn(format string, v ...interface{})
- func (bl *BeeLogger) Warning(format string, v ...interface{})
- func (bl *BeeLogger) Write(p []byte) (n int, err error)
- type Logger
- type SMTPWriter
Constants ¶
const ( LevelEmergency = iota LevelAlert LevelCritical LevelError LevelWarning LevelNotice LevelInformational LevelDebug )
RFC5424 log message levels.
const ( AdapterConsole = "console" AdapterFile = "file" AdapterMultiFile = "multifile" AdapterMail = "stmp" AdapterConn = "conn" AdapterEs = "es" )
Name for adapter with beego official support
const ( LevelInfo = LevelInformational LevelTrace = LevelDebug LevelWarn = LevelWarning )
Legacy log level constants to ensure backwards compatibility.
const ( DiscardNonColorEscSeq outputMode OutputNonColorEscSeq )
DiscardNonColorEscSeq supports the divided color escape sequence. But non-color escape sequence is not output. Please use the OutputNonColorEscSeq If you want to output a non-color escape sequences such as ncurses. However, it does not support the divided color escape sequence.
Variables ¶
This section is empty.
Functions ¶
func Alert ¶ added in v1.7.0
func Alert(f interface{}, v ...interface{})
Alert logs a message at alert level.
func ColorByMethod ¶ added in v1.7.0
func ColorByStatus ¶ added in v1.7.0
func Critical ¶ added in v1.7.0
func Critical(f interface{}, v ...interface{})
Critical logs a message at critical level.
func Debug ¶ added in v1.7.0
func Debug(f interface{}, v ...interface{})
Debug logs a message at debug level.
func Emergency ¶ added in v1.7.0
func Emergency(f interface{}, v ...interface{})
Emergency logs a message at emergency level.
func EnableFuncCallDepth ¶ added in v1.7.0
func EnableFuncCallDepth(b bool)
EnableFuncCallDepth enable log funcCallDepth
func Error ¶ added in v1.7.0
func Error(f interface{}, v ...interface{})
Error logs a message at error level.
func Info ¶ added in v1.7.0
func Info(f interface{}, v ...interface{})
Info compatibility alias for Warning()
func Informational ¶ added in v1.7.0
func Informational(f interface{}, v ...interface{})
Informational logs a message at info level.
func NewAnsiColorWriter ¶ added in v1.7.0
NewAnsiColorWriter creates and initializes a new ansiColorWriter using io.Writer w as its initial contents. In the console of Windows, which change the foreground and background colors of the text by the escape sequence. In the console of other systems, which writes to w all text.
func NewModeAnsiColorWriter ¶ added in v1.7.0
NewModeAnsiColorWriter create and initializes a new ansiColorWriter by specifying the outputMode.
func Notice ¶ added in v1.7.0
func Notice(f interface{}, v ...interface{})
Notice logs a message at notice level.
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 SetLevel ¶ added in v1.7.0
func SetLevel(l int)
SetLevel sets the global log level used by the simple logger.
func SetLogFuncCall ¶ added in v1.7.0
func SetLogFuncCall(b bool)
SetLogFuncCall set the CallDepth, default is 3
func SetLogFuncCallDepth ¶ added in v1.7.0
func SetLogFuncCallDepth(d int)
SetLogFuncCallDepth set log funcCallDepth
func Trace ¶ added in v1.7.0
func Trace(f interface{}, v ...interface{})
Trace logs a message at trace level. compatibility alias for Warning()
func W32Debug ¶ added in v1.7.0
func W32Debug(msg string)
Helper method to output colored logs in Windows terminals
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 GetBeeLogger ¶ added in v1.7.0
func GetBeeLogger() *BeeLogger
GetLogger returns the default BeeLogger
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) Close ¶
func (bl *BeeLogger) Close()
Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func (*BeeLogger) EnableFuncCallDepth ¶
EnableFuncCallDepth enable log funcCallDepth
func (*BeeLogger) GetLogFuncCallDepth ¶ added in v1.5.0
GetLogFuncCallDepth return log funcCallDepth for wrapper
func (*BeeLogger) Informational ¶ added in v1.4.0
Informational Log INFORMATIONAL level message.
func (*BeeLogger) Reset ¶ added in v1.6.1
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) SetLogger ¶
SetLogger provides a given logger adapter into BeeLogger with config string. config need to be correct JSON as string: {"interval":360}.
type Logger ¶ added in v1.6.0
type Logger interface { Init(config string) error WriteMsg(when time.Time, msg string, level int) error Destroy() Flush() }
Logger defines the behavior of a log provider.
func NewConsole ¶
func NewConsole() Logger
NewConsole create ConsoleWriter returning as LoggerInterface.
type SMTPWriter ¶ added in v1.6.0
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) Destroy ¶ added in v1.6.0
func (s *SMTPWriter) Destroy()
Destroy implementing method. empty.
func (*SMTPWriter) Flush ¶ added in v1.6.0
func (s *SMTPWriter) Flush()
Flush implementing method. empty.
func (*SMTPWriter) Init ¶ added in v1.6.0
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 }