Documentation ¶
Overview ¶
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 Debug(v ...interface{})
- func Error(v ...interface{})
- func Info(v ...interface{})
- func Pretty(message string, v interface{})
- func Register(name string, log loggerType)
- func SetFileLogger(file string)
- func SetLoggerLevel(l int)
- func Warn(v ...interface{})
- type Brush
- type ConnWriter
- type ConsoleWriter
- type FileLogWriter
- type Logger
- func (bl *Logger) Close()
- func (bl *Logger) Debug(v ...interface{})
- func (bl *Logger) DelLogger(adaptername string) error
- func (bl *Logger) EnableFuncCallDepth(b bool)
- func (bl *Logger) Error(v ...interface{})
- func (bl *Logger) Flush()
- func (bl *Logger) Info(v ...interface{})
- func (bl *Logger) Pretty(message string, v interface{})
- func (bl *Logger) SetLevel(l int)
- func (bl *Logger) SetLogFuncCallDepth(d int)
- func (bl *Logger) SetLogger(adaptername string, config string) error
- func (bl *Logger) Warn(v ...interface{})
- type LoggerInterface
- type MuxWriter
- type SmtpWriter
Constants ¶
const ( LevelError = iota LevelWarn LevelInfo LevelDebug )
RFC5424 log message levels.
Variables ¶
This section is empty.
Functions ¶
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 SetFileLogger ¶
func SetFileLogger(file string)
// set file logger with json config. // jsonconfig like: // { // "filename":"logs/sample.log", // "maxlines":10000, // "maxsize":1<<30, // "daily":true, // "maxdays":15, // "rotate":true // }
func SetLoggerLevel ¶
func SetLoggerLevel(l int)
Types ¶
type ConnWriter ¶
type ConnWriter struct { ReconnectOnMsg bool `json:"reconnectOnMsg"` Reconnect bool `json:"reconnect"` Net string `json:"net"` Addr string `json:"addr"` Level int `json:"level"` // contains filtered or unexported fields }
ConnWriter implements LoggerInterface. it writes messages in keep-live tcp connection.
func (*ConnWriter) Destroy ¶
func (c *ConnWriter) Destroy()
destroy connection writer and close tcp listener.
func (*ConnWriter) Init ¶
func (c *ConnWriter) Init(jsonconfig string) error
init connection writer with json config. json config only need key "level".
type ConsoleWriter ¶
type ConsoleWriter struct { Level int `json:"level"` // contains filtered or unexported fields }
ConsoleWriter implements LoggerInterface and writes messages to terminal.
func (*ConsoleWriter) Init ¶
func (c *ConsoleWriter) Init(jsonconfig string) error
init console logger. jsonconfig like '{"level":LevelTrace}'.
type FileLogWriter ¶
type FileLogWriter struct { *log.Logger // The opened file Filename string `json:"filename"` Maxlines int `json:"maxlines"` // Rotate at size Maxsize int `json:"maxsize"` // Rotate daily Daily bool `json:"daily"` Maxdays int64 `json:"maxdays"` Rotate bool `json:"rotate"` Level int `json:"level"` // contains filtered or unexported fields }
FileLogWriter implements LoggerInterface. It writes messages by lines limit, file size limit, or time frequency.
func (*FileLogWriter) Destroy ¶
func (w *FileLogWriter) Destroy()
destroy file logger, close file writer.
func (*FileLogWriter) DoRotate ¶
func (w *FileLogWriter) DoRotate() error
DoRotate means it need to write file in new file. new file name like xx.log.2013-01-01.2
func (*FileLogWriter) Flush ¶
func (w *FileLogWriter) Flush()
flush file logger. there are no buffering messages in file logger in memory. flush file means sync file from disk.
func (*FileLogWriter) Init ¶
func (w *FileLogWriter) Init(jsonconfig string) error
Init file logger with json config. jsonconfig like:
{ "filename":"logs/sample.log", "maxlines":10000, "maxsize":1<<30, "daily":true, "maxdays":15, "rotate":true }
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is default logger in beego application. it can contain several providers and log message into all providers.
func NewFileLogger ¶
func NewLogger ¶
NewLogger returns a new Logger. channellen means the number of messages in chan. if the buffering chan is full, logger adapters write to file or other way.
func (*Logger) Close ¶
func (bl *Logger) Close()
close logger, flush all chan data and destroy all adapters in Logger.
func (*Logger) EnableFuncCallDepth ¶
enable log funcCallDepth
func (*Logger) 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 (*Logger) SetLogFuncCallDepth ¶
set log funcCallDepth
type LoggerInterface ¶
type LoggerInterface interface { Init(config string) error WriteMsg(msg string, level int) error Destroy() Flush() }
LoggerInterface defines the behavior of a log provider.
func NewConsole ¶
func NewConsole() LoggerInterface
create ConsoleWriter returning as LoggerInterface.
func NewFileWriter ¶
func NewFileWriter() LoggerInterface
create a FileLogWriter 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) GetSmtpAuth ¶
func (s *SmtpWriter) GetSmtpAuth(host string) smtp.Auth
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 }