logs

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 8, 2019 License: Apache-2.0 Imports: 16 Imported by: 51

Documentation

Index

Constants

View Source
const (
	LevelNothing = iota - 1
	LevelApp     // only for pholcus
	LevelEmergency
	LevelAlert
	LevelCritical
	LevelError
	LevelWarning
	LevelNotice
	LevelInformational
	LevelDebug
)

RFC5424 log message levels.

View Source
const (
	NULL = iota - 1
	WORK
	REST
	CLOSE
)

BeeLogger's status

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.

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

func NewLogger(channellen int64, stealLevel ...int) *BeeLogger

NewLogger returns a new BeeLogger. channellen means the number of messages in chan. if the buffering chan is full, logger adapters write to file or other way.

func (*BeeLogger) Alert

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

Log ALERT level message.

func (*BeeLogger) App

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

Log APP level message.

func (*BeeLogger) Async

func (bl *BeeLogger) Async(enable bool) *BeeLogger

func (*BeeLogger) Close

func (bl *BeeLogger) Close()

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

func (*BeeLogger) Critical

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

Log CRITICAL level message.

func (*BeeLogger) Debug

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

Log DEBUG level message.

func (*BeeLogger) DelLogger

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

remove a logger adapter in BeeLogger.

func (*BeeLogger) Emergency

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

Log EMERGENCY level message.

func (*BeeLogger) EnableFuncCallDepth

func (bl *BeeLogger) EnableFuncCallDepth(b bool)

enable log funcCallDepth

func (*BeeLogger) EnableStealOne

func (bl *BeeLogger) EnableStealOne(enable bool)

EnableStealOne set whether to enable steal-one.

func (*BeeLogger) Error

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

Log ERROR level message.

func (*BeeLogger) Flush

func (bl *BeeLogger) Flush()

flush all chan data.

func (*BeeLogger) GetLogFuncCallDepth

func (bl *BeeLogger) GetLogFuncCallDepth() int

get log funcCallDepth for wrapper

func (*BeeLogger) GoOn

func (bl *BeeLogger) GoOn()

func (*BeeLogger) Informational

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

Log INFORMATIONAL level message.

func (*BeeLogger) Notice

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

Log NOTICE level message.

func (*BeeLogger) Rest

func (bl *BeeLogger) Rest()

func (*BeeLogger) SetLevel

func (bl *BeeLogger) SetLevel(l int)

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

func (bl *BeeLogger) SetLogFuncCallDepth(d int)

set log funcCallDepth

func (*BeeLogger) SetLogger

func (bl *BeeLogger) SetLogger(adaptername string, config map[string]interface{}) error

SetLogger provides a given logger adapter into BeeLogger with config string.

func (*BeeLogger) SetStatus

func (bl *BeeLogger) SetStatus(status int)

func (*BeeLogger) SetStealLevel

func (bl *BeeLogger) SetStealLevel(l int)

func (*BeeLogger) Status

func (bl *BeeLogger) Status() (int, string)

func (*BeeLogger) StealOne

func (bl *BeeLogger) StealOne() (level int, msg string, ok bool)

get a log message

func (*BeeLogger) Warning

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

Log WARNING level message.

type Brush

type Brush func(string) string

func NewBrush

func NewBrush(color string) Brush

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) Flush

func (c *ConnWriter) Flush()

implementing method. empty.

func (*ConnWriter) Init

func (c *ConnWriter) Init(config map[string]interface{}) error

init connection writer with json config. json config only need key "level".

func (*ConnWriter) WriteMsg

func (c *ConnWriter) WriteMsg(msg string, level int) error

write message in connection. if connection is down, try to re-connect.

type ConsoleWriter

type ConsoleWriter struct {
	Level int `json:"level"`
	// contains filtered or unexported fields
}

ConsoleWriter implements LoggerInterface and writes messages to terminal.

func (*ConsoleWriter) Destroy

func (c *ConsoleWriter) Destroy()

implementing method. empty.

func (*ConsoleWriter) Flush

func (c *ConsoleWriter) Flush()

implementing method. empty.

func (*ConsoleWriter) Init

func (c *ConsoleWriter) Init(config map[string]interface{}) error

init console logger. config like map[string]interface{}{"level":LevelTrace,"writer":os.Stdout}.

func (*ConsoleWriter) WriteMsg

func (c *ConsoleWriter) WriteMsg(msg string, level int) error

write message in console.

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(config map[string]interface{}) error

Init file logger with json config. config like:

{
"filename":"logs/beego.log",
"maxlines":10000,
"maxsize":1<<30,
"daily":true,
"maxdays":15,
"rotate":true
}

func (*FileLogWriter) WriteMsg

func (w *FileLogWriter) WriteMsg(msg string, level int) error

write logger message into file.

type LoggerInterface

type LoggerInterface interface {
	Init(config map[string]interface{}) error
	WriteMsg(msg string, level int) error
	Destroy()
	Flush()
}

LoggerInterface defines the behavior of a log provider.

func NewConn

func NewConn() LoggerInterface

create new ConnWrite returning as LoggerInterface.

func NewConsole

func NewConsole() LoggerInterface

create ConsoleWriter returning as LoggerInterface.

func NewFileWriter

func NewFileWriter() LoggerInterface

create a FileLogWriter returning as LoggerInterface.

func NewSmtpWriter

func NewSmtpWriter() LoggerInterface

create smtp writer.

type MuxWriter

type MuxWriter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

an *os.File writer with locker.

func (*MuxWriter) SetFd

func (l *MuxWriter) SetFd(fd *os.File)

set os.File in writer.

func (*MuxWriter) Write

func (l *MuxWriter) Write(b []byte) (int, error)

write to os.File.

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) Destroy

func (s *SmtpWriter) Destroy()

implementing method. empty.

func (*SmtpWriter) Flush

func (s *SmtpWriter) Flush()

implementing method. empty.

func (*SmtpWriter) GetSmtpAuth

func (s *SmtpWriter) GetSmtpAuth(host string) smtp.Auth

func (*SmtpWriter) Init

func (s *SmtpWriter) Init(config map[string]interface{}) 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(msg string, level int) error

write message in smtp writer. it will send an email with subject and only this message.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL