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
Copyright 2014 mqant Author. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- Variables
- 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 FormatTimeHeader(when time.Time) ([]byte, int)
- func GetCallStack(skip int, frames int, filter string) (CallStack, sf string)
- 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(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Async(msgLen ...int64) *BeeLogger
- func (bl *BeeLogger) BiReport(msg string)
- func (bl *BeeLogger) Close()
- func (bl *BeeLogger) Critical(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Debug(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) DelLogger(adapterName string) error
- func (bl *BeeLogger) Emergency(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) EnableFuncCallDepth(b bool)
- func (bl *BeeLogger) Error(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Flush()
- func (bl *BeeLogger) GetLogFuncCallDepth() int
- func (bl *BeeLogger) Info(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Informational(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Notice(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Reset()
- func (bl *BeeLogger) SetContentType(b string)
- func (bl *BeeLogger) SetFormatFunc(d FormatFunc)
- 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(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Warn(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Warning(span *BeegoTraceSpan, format string, v ...interface{})
- func (bl *BeeLogger) Write(p []byte) (n int, err error)
- type BeegoTraceSpan
- type DingtalkWriter
- type FormatFunc
- type JLWriter
- type JsonStruct
- type Logger
- type SLACKWriter
- 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 = "smtp" AdapterConn = "conn" AdapterEs = "es" AdapterJianLiao = "jianliao" AdapterSlack = "slack" AdapterDingtalk = "dingtalk" AdapterAliLS = "alils" )
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 ¶
var LevelPrefix = [LevelDebug + 1]string{"[Emergency] ", "[Alert] ", "[Critical] ", "[Error] ", "[Warn] ", "[Notice] ", "[Info] ", "[Debug] "}
Functions ¶
func ColorByMethod ¶
ColorByMethod return color by http code GET return Blue POST return Cyan PUT return Yellow DELETE return Red PATCH return Green HEAD return Magenta OPTIONS return WHITE
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 EnableFuncCallDepth ¶
func EnableFuncCallDepth(b bool)
EnableFuncCallDepth enable log funcCallDepth
func GetCallStack ¶
GetCallStack returns the current call stack information as a string. The skip parameter specifies how many top frames should be skipped, while the frames parameter specifies at most how many frames should be returned.
func Informational ¶
func Informational(f interface{}, v ...interface{})
Informational logs a message at info level.
func NewAnsiColorWriter ¶
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 ¶
NewModeAnsiColorWriter create and initializes a new ansiColorWriter by specifying the outputMode.
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
func Trace ¶
func Trace(f interface{}, v ...interface{})
Trace logs a message at trace level. compatibility alias for Warning()
Types ¶
type BeeLogger ¶
type BeeLogger struct { ProcessID string // 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) Alert ¶
func (bl *BeeLogger) Alert(span *BeegoTraceSpan, format string, v ...interface{})
Alert Log ALERT level message.
func (*BeeLogger) Close ¶
func (bl *BeeLogger) Close()
Close close logger, flush all chan data and destroy all adapters in BeeLogger.
func (*BeeLogger) Critical ¶
func (bl *BeeLogger) Critical(span *BeegoTraceSpan, format string, v ...interface{})
Critical Log CRITICAL level message.
func (*BeeLogger) Debug ¶
func (bl *BeeLogger) Debug(span *BeegoTraceSpan, format string, v ...interface{})
Debug Log DEBUG level message.
func (*BeeLogger) Emergency ¶
func (bl *BeeLogger) Emergency(span *BeegoTraceSpan, format string, v ...interface{})
Emergency Log EMERGENCY level message.
func (*BeeLogger) EnableFuncCallDepth ¶
EnableFuncCallDepth enable log funcCallDepth
func (*BeeLogger) Error ¶
func (bl *BeeLogger) Error(span *BeegoTraceSpan, format string, v ...interface{})
Error Log ERROR level message.
func (*BeeLogger) GetLogFuncCallDepth ¶
GetLogFuncCallDepth return log funcCallDepth for wrapper
func (*BeeLogger) Info ¶
func (bl *BeeLogger) Info(span *BeegoTraceSpan, format string, v ...interface{})
Info Log INFO level message. compatibility alias for Informational()
func (*BeeLogger) Informational ¶
func (bl *BeeLogger) Informational(span *BeegoTraceSpan, format string, v ...interface{})
Informational Log INFORMATIONAL level message.
func (*BeeLogger) Notice ¶
func (bl *BeeLogger) Notice(span *BeegoTraceSpan, format string, v ...interface{})
Notice Log NOTICE level message.
func (*BeeLogger) Reset ¶
func (bl *BeeLogger) Reset()
Reset close all outputs, and set bl.outputs to nil
func (*BeeLogger) SetContentType ¶
func (*BeeLogger) SetFormatFunc ¶
func (bl *BeeLogger) SetFormatFunc(d FormatFunc)
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}.
func (*BeeLogger) Trace ¶
func (bl *BeeLogger) Trace(span *BeegoTraceSpan, format string, v ...interface{})
Trace Log TRACE level message. compatibility alias for Debug()
func (*BeeLogger) Warn ¶
func (bl *BeeLogger) Warn(span *BeegoTraceSpan, format string, v ...interface{})
Warn Log WARN level message. compatibility alias for Warning()
func (*BeeLogger) Warning ¶
func (bl *BeeLogger) Warning(span *BeegoTraceSpan, format string, v ...interface{})
Warning Log WARNING level message.
type BeegoTraceSpan ¶
type DingtalkWriter ¶
SLACKWriter implements beego LoggerInterface and is used to send jiaoliao webhook
func (*DingtalkWriter) Destroy ¶
func (s *DingtalkWriter) Destroy()
Destroy implementing method. empty.
func (*DingtalkWriter) Init ¶
func (s *DingtalkWriter) Init(jsonconfig string) error
Init SLACKWriter with json config string
func (*DingtalkWriter) WriteMsg ¶
WriteMsg write message in smtp writer. it will send an email with subject and only this message.
func (*DingtalkWriter) WriteOriginalMsg ¶
type FormatFunc ¶
type FormatFunc func(when time.Time, span *BeegoTraceSpan, logLevel int, msg string, v ...interface{}) (string, error)
func DefineErrorLogFunc ¶
func DefineErrorLogFunc(processId string, loggerFuncCallDepth int) FormatFunc
type JLWriter ¶
type JLWriter struct { AuthorName string `json:"authorname"` Title string `json:"title"` WebhookURL string `json:"webhookurl"` RedirectURL string `json:"redirecturl,omitempty"` ImageURL string `json:"imageurl,omitempty"` Level int `json:"level"` }
JLWriter implements beego LoggerInterface and is used to send jiaoliao webhook
type JsonStruct ¶
type JsonStruct struct { FormatTime string `json:"formattime"` TimeStamp int64 `json:"timestamp"` EventId string `json:"event_id"` SubEventId interface{} `json:"sub_event_id,omitempty"` ErrorMsg interface{} `json:"error_msg,omitempty"` ErrorReport interface{} `json:"error_report,omitempty"` EventParams interface{} `json:"event_params,omitempty"` Rparam interface{} `json:"rparam,omitempty"` ContextParam interface{} `json:"context_param,omitempty"` Message string `json:"message"` File string `json:"file"` Stack string `json:"stack"` ProcessId string `json:"processid"` Level string `json:"level"` TraceId string `json:"trace_id"` TraceSpan string `json:"trace_span"` }
type Logger ¶
type Logger interface { Init(config string) error WriteMsg(when time.Time, msg string, level int) error WriteOriginalMsg(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.
func NewFileWriter ¶
func NewFileWriter() Logger
newFileWriter create a FileLogWriter returning as LoggerInterface.
type SLACKWriter ¶
SLACKWriter implements beego LoggerInterface and is used to send jiaoliao webhook
func (*SLACKWriter) Init ¶
func (s *SLACKWriter) Init(jsonconfig string) error
Init SLACKWriter with json config string
func (*SLACKWriter) WriteMsg ¶
WriteMsg write message in smtp writer. it will send an email with subject and only this message.
func (*SLACKWriter) WriteOriginalMsg ¶
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 ¶
WriteMsg write message in smtp writer. it will send an email with subject and only this message.