beego: github.com/astaxie/beego/core/logs Index | Files | Directories

package logs

import "github.com/astaxie/beego/core/logs"

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

Package Files

access_log.go conn.go console.go file.go formatter.go jianliao.go log.go log_msg.go logger.go multifile.go slack.go smtp.go

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"
    AdapterAliLS     = "alils"
)

Name for adapter with beego official support

const (
    LevelInfo  = LevelInformational
    LevelTrace = LevelDebug
    LevelWarn  = LevelWarning
)

Legacy log level constants to ensure backwards compatibility.

func AccessLog Uses

func AccessLog(r *AccessLogRecord, format string)

AccessLog - Format and print access log.

func Alert Uses

func Alert(f interface{}, v ...interface{})

Alert logs a message at alert level.

func ColorByMethod Uses

func ColorByMethod(method string) string

ColorByMethod return color by http code

func ColorByStatus Uses

func ColorByStatus(code int) string

ColorByStatus return color by http code 2xx return Green 3xx return White 4xx return Yellow 5xx return Red

func Critical Uses

func Critical(f interface{}, v ...interface{})

Critical logs a message at critical level.

func Debug Uses

func Debug(f interface{}, v ...interface{})

Debug logs a message at debug level.

func Emergency Uses

func Emergency(f interface{}, v ...interface{})

Emergency logs a message at emergency level.

func EnableFullFilePath Uses

func EnableFullFilePath(b bool)

EnableFullFilePath enables full file path logging. Disabled by default e.g "/home/Documents/GitHub/beego/mainapp/" instead of "mainapp"

func EnableFuncCallDepth Uses

func EnableFuncCallDepth(b bool)

EnableFuncCallDepth enable log funcCallDepth

func Error Uses

func Error(f interface{}, v ...interface{})

Error logs a message at error level.

func GetLogger Uses

func GetLogger(prefixes ...string) *log.Logger

GetLogger returns the default BeeLogger

func Info Uses

func Info(f interface{}, v ...interface{})

Info compatibility alias for Warning()

func Informational Uses

func Informational(f interface{}, v ...interface{})

Informational logs a message at info level.

func Notice Uses

func Notice(f interface{}, v ...interface{})

Notice logs a message at notice level.

func Register Uses

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 RegisterFormatter Uses

func RegisterFormatter(name string, fmtr LogFormatter)

RegisterFormatter register an formatter. Usually you should use this to extend your custom formatter for example: RegisterFormatter("my-fmt", &MyFormatter{}) logs.SetFormatter(Console, `{"formatter": "my-fmt"}`)

func Reset Uses

func Reset()

Reset will remove all the adapter

func ResetColor Uses

func ResetColor() string

ResetColor return reset color

func SetGlobalFormatter Uses

func SetGlobalFormatter(fmtter string) error

SetGlobalFormatter sets the global formatter for all log adapters don't forget to register the formatter by invoking RegisterFormatter

func SetLevel Uses

func SetLevel(l int)

SetLevel sets the global log level used by the simple logger.

func SetLogFuncCall Uses

func SetLogFuncCall(b bool)

SetLogFuncCall set the CallDepth, default is 4

func SetLogFuncCallDepth Uses

func SetLogFuncCallDepth(d int)

SetLogFuncCallDepth set log funcCallDepth

func SetLogger Uses

func SetLogger(adapter string, config ...string) error

SetLogger sets a new logger.

func SetPrefix Uses

func SetPrefix(s string)

SetPrefix sets the prefix

func Trace Uses

func Trace(f interface{}, v ...interface{})

Trace logs a message at trace level. compatibility alias for Warning()

func Warn Uses

func Warn(f interface{}, v ...interface{})

Warn compatibility alias for Warning()

func Warning Uses

func Warning(f interface{}, v ...interface{})

Warning logs a message at warning level.

type AccessLogRecord Uses

type AccessLogRecord struct {
    RemoteAddr     string        `json:"remote_addr"`
    RequestTime    time.Time     `json:"request_time"`
    RequestMethod  string        `json:"request_method"`
    Request        string        `json:"request"`
    ServerProtocol string        `json:"server_protocol"`
    Host           string        `json:"host"`
    Status         int           `json:"status"`
    BodyBytesSent  int64         `json:"body_bytes_sent"`
    ElapsedTime    time.Duration `json:"elapsed_time"`
    HTTPReferrer   string        `json:"http_referrer"`
    HTTPUserAgent  string        `json:"http_user_agent"`
    RemoteUser     string        `json:"remote_user"`
}

AccessLogRecord is astruct for holding access log data.

type BeeLogger Uses

type BeeLogger struct {
    // contains filtered or unexported fields
}

BeeLogger is default logger in beego application. Can contain several providers and log message into all providers.

func Async Uses

func Async(msgLen ...int64) *BeeLogger

Async set the beelogger with Async mode and hold msglen messages

func GetBeeLogger Uses

func GetBeeLogger() *BeeLogger

GetBeeLogger returns the default BeeLogger

func NewLogger Uses

func NewLogger(channelLens ...int64) *BeeLogger

NewLogger returns a new BeeLogger. channelLen: 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 Uses

func (bl *BeeLogger) Alert(format string, v ...interface{})

Alert Log ALERT level message.

func (*BeeLogger) Async Uses

func (bl *BeeLogger) Async(msgLen ...int64) *BeeLogger

Async sets the log to asynchronous and start the goroutine

func (*BeeLogger) Close Uses

func (bl *BeeLogger) Close()

Close close logger, flush all chan data and destroy all adapters in BeeLogger.

func (*BeeLogger) Critical Uses

func (bl *BeeLogger) Critical(format string, v ...interface{})

Critical Log CRITICAL level message.

func (*BeeLogger) Debug Uses

func (bl *BeeLogger) Debug(format string, v ...interface{})

Debug Log DEBUG level message.

func (*BeeLogger) DelLogger Uses

func (bl *BeeLogger) DelLogger(adapterName string) error

DelLogger removes a logger adapter in BeeLogger.

func (*BeeLogger) Emergency Uses

func (bl *BeeLogger) Emergency(format string, v ...interface{})

Emergency Log EMERGENCY level message.

func (*BeeLogger) EnableFuncCallDepth Uses

func (bl *BeeLogger) EnableFuncCallDepth(b bool)

EnableFuncCallDepth enable log funcCallDepth

func (*BeeLogger) Error Uses

func (bl *BeeLogger) Error(format string, v ...interface{})

Error Log ERROR level message.

func (*BeeLogger) Flush Uses

func (bl *BeeLogger) Flush()

Flush flush all chan data.

func (*BeeLogger) GetLevel Uses

func (bl *BeeLogger) GetLevel() int

GetLevel Get Current log message level.

func (*BeeLogger) GetLogFuncCallDepth Uses

func (bl *BeeLogger) GetLogFuncCallDepth() int

GetLogFuncCallDepth return log funcCallDepth for wrapper

func (*BeeLogger) Info Uses

func (bl *BeeLogger) Info(format string, v ...interface{})

Info Log INFO level message. compatibility alias for Informational()

func (*BeeLogger) Informational Uses

func (bl *BeeLogger) Informational(format string, v ...interface{})

Informational Log INFORMATIONAL level message.

func (*BeeLogger) Notice Uses

func (bl *BeeLogger) Notice(format string, v ...interface{})

Notice Log NOTICE level message.

func (*BeeLogger) Reset Uses

func (bl *BeeLogger) Reset()

Reset close all outputs, and set bl.outputs to nil

func (*BeeLogger) SetLevel Uses

func (bl *BeeLogger) SetLevel(l int)

SetLevel sets log message level. If message level (such as LevelDebug) is higher than logger level (such as LevelWarning), log providers will not be sent the message.

func (*BeeLogger) SetLogFuncCallDepth Uses

func (bl *BeeLogger) SetLogFuncCallDepth(d int)

SetLogFuncCallDepth set log funcCallDepth

func (*BeeLogger) SetLogger Uses

func (bl *BeeLogger) SetLogger(adapterName string, configs ...string) error

SetLogger provides a given logger adapter into BeeLogger with config string. config must in in JSON format like {"interval":360}}

func (*BeeLogger) SetPrefix Uses

func (bl *BeeLogger) SetPrefix(s string)

set prefix

func (*BeeLogger) Trace Uses

func (bl *BeeLogger) Trace(format string, v ...interface{})

Trace Log TRACE level message. compatibility alias for Debug()

func (*BeeLogger) Warn Uses

func (bl *BeeLogger) Warn(format string, v ...interface{})

Warn Log WARN level message. compatibility alias for Warning()

func (*BeeLogger) Warning Uses

func (bl *BeeLogger) Warning(format string, v ...interface{})

Warning Log WARNING level message.

func (*BeeLogger) Write Uses

func (bl *BeeLogger) Write(p []byte) (n int, err error)

type JLWriter Uses

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"`

    Formatter string `json:"formatter"`
    // contains filtered or unexported fields
}

JLWriter implements beego LoggerInterface and is used to send jiaoliao webhook

func (*JLWriter) Destroy Uses

func (s *JLWriter) Destroy()

Destroy implementing method. empty.

func (*JLWriter) Flush Uses

func (s *JLWriter) Flush()

Flush implementing method. empty.

func (*JLWriter) Format Uses

func (s *JLWriter) Format(lm *LogMsg) string

func (*JLWriter) Init Uses

func (s *JLWriter) Init(config string) error

Init JLWriter with json config string

func (*JLWriter) SetFormatter Uses

func (s *JLWriter) SetFormatter(f LogFormatter)

func (*JLWriter) WriteMsg Uses

func (s *JLWriter) WriteMsg(lm *LogMsg) error

WriteMsg writes message in smtp writer. Sends an email with subject and only this message.

type LogFormatter Uses

type LogFormatter interface {
    Format(lm *LogMsg) string
}

func GetFormatter Uses

func GetFormatter(name string) (LogFormatter, bool)

type LogMsg Uses

type LogMsg struct {
    Level      int
    Msg        string
    When       time.Time
    FilePath   string
    LineNumber int
    Args       []interface{}
    Prefix     string
    // contains filtered or unexported fields
}

func (*LogMsg) OldStyleFormat Uses

func (lm *LogMsg) OldStyleFormat() string

OldStyleFormat you should never invoke this

type Logger Uses

type Logger interface {
    Init(config string) error
    WriteMsg(lm *LogMsg) error
    Destroy()
    Flush()
    SetFormatter(f LogFormatter)
}

Logger defines the behavior of a log provider.

func NewConn Uses

func NewConn() Logger

NewConn creates new ConnWrite returning as LoggerInterface.

func NewConsole Uses

func NewConsole() Logger

NewConsole creates ConsoleWriter returning as LoggerInterface.

type PatternLogFormatter Uses

type PatternLogFormatter struct {
    Pattern    string
    WhenFormat string
}

PatternLogFormatter provides a quick format method for example: tes := &PatternLogFormatter{Pattern: "%F:%n|%w %t>> %m", WhenFormat: "2006-01-02"} RegisterFormatter("tes", tes) SetGlobalFormatter("tes")

func (*PatternLogFormatter) Format Uses

func (p *PatternLogFormatter) Format(lm *LogMsg) string

func (*PatternLogFormatter) ToString Uses

func (p *PatternLogFormatter) ToString(lm *LogMsg) string

'w' when, 'm' msg,'f' filename,'F' full path,'n' line number 'l' level number, 't' prefix of level type, 'T' full name of level type

type SLACKWriter Uses

type SLACKWriter struct {
    WebhookURL string `json:"webhookurl"`
    Level      int    `json:"level"`

    Formatter string `json:"formatter"`
    // contains filtered or unexported fields
}

SLACKWriter implements beego LoggerInterface and is used to send jiaoliao webhook

func (*SLACKWriter) Destroy Uses

func (s *SLACKWriter) Destroy()

Destroy implementing method. empty.

func (*SLACKWriter) Flush Uses

func (s *SLACKWriter) Flush()

Flush implementing method. empty.

func (*SLACKWriter) Format Uses

func (s *SLACKWriter) Format(lm *LogMsg) string

func (*SLACKWriter) Init Uses

func (s *SLACKWriter) Init(config string) error

Init SLACKWriter with json config string

func (*SLACKWriter) SetFormatter Uses

func (s *SLACKWriter) SetFormatter(f LogFormatter)

func (*SLACKWriter) WriteMsg Uses

func (s *SLACKWriter) WriteMsg(lm *LogMsg) error

WriteMsg write message in smtp writer. Sends an email with subject and only this message.

type SMTPWriter Uses

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"`

    Formatter string `json:"formatter"`
    // contains filtered or unexported fields
}

SMTPWriter implements LoggerInterface and is used to send emails via given SMTP-server.

func (*SMTPWriter) Destroy Uses

func (s *SMTPWriter) Destroy()

Destroy implementing method. empty.

func (*SMTPWriter) Flush Uses

func (s *SMTPWriter) Flush()

Flush implementing method. empty.

func (*SMTPWriter) Format Uses

func (s *SMTPWriter) Format(lm *LogMsg) string

func (*SMTPWriter) Init Uses

func (s *SMTPWriter) Init(config 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) SetFormatter Uses

func (s *SMTPWriter) SetFormatter(f LogFormatter)

func (*SMTPWriter) WriteMsg Uses

func (s *SMTPWriter) WriteMsg(lm *LogMsg) error

WriteMsg writes message in smtp writer. Sends an email with subject and only this message.

Directories

PathSynopsis
alilsPackage alils implements the SDK(v0.5.0) of Simple Log Service(abbr.
es

Package logs imports 21 packages (graph) and is imported by 17 packages. Updated 2020-11-18. Refresh now. Tools for package owners.