logs

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

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

View Source
const (
	LevelEmergency = iota //事故
	LevelAlert            //警报
	LevelCritical         //危险
	LevelError            //错误
	LevelWarning          //警告
	LevelNotice           //通知
	LevelInfo             //信息
	LevelDebug            //调试
	LevelPrint            //打印(直接显示内容,不显示前缀)
)

RFC5424 log message levels.

View Source
const (
	AdapterConsole   = "console"
	AdapterFile      = "file"
	AdapterMultiFile = "multifile"
	AdapterMail      = "smtp"
	AdapterConn      = "conn"
	AdapterEs        = "es"
	AdapterJianLiao  = "jianliao"
	AdapterSlack     = "slack"
)

Name for adapter with beego official support

Variables

View Source
var IsDebug bool = false

Functions

func Alert

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

Alert logs a message at alert level.

func Begin

func Begin()

Debug logs a message at debug level.

func CheckError

func CheckError(pos string, err error)

func Critical

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

Critical logs a message at critical level.

func Debug

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

Debug logs a message at debug level.

func Emergency

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

Emergency logs a message at emergency level.

func End

func End()

Debug logs a message at debug level.

func Error

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

Error logs a message at error level.

func FDebug added in v1.0.1

func FDebug(f string, v ...interface{})

func Flush added in v1.0.1

func Flush()

func GetFileLines added in v1.0.1

func GetFileLines(filename string) (int, error)

获取文件行数

func GetLastLogTime

func GetLastLogTime() time.Time

func GetLevel

func GetLevel(adapter ...string) int

func GetLevelName

func GetLevelName(level int) string

func GetNetError added in v1.0.9

func GetNetError(err error) string

在日志库里有一个相同代理,需要同步修改。

func GetNow

func GetNow() (result time.Time)

func GetParamBool

func GetParamBool(name string, flag_value bool) bool

func GetParamInt

func GetParamInt(name string, flag_value int) int

func GetParamString

func GetParamString(name string, flag_value, default_value string) string

func Info

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

Info logs a message at info level.

func Notice

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

Notice logs a message at notice level.

func Print

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

Debug logs a message at debug 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 Reset

func Reset()

func SetFDebug added in v1.0.1

func SetFDebug(l bool)

func SetLevel

func SetLevel(l int, adapters ...string)

func SetLogFuncCallDepth

func SetLogFuncCallDepth(d int)

func SetLogger

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

func Warning

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

Warning logs a message at warning level.

Types

type ILogger added in v1.0.1

type ILogger interface {
	Init(config string) error
	SetLevel(l int)
	GetLevel() int
	WriteMsg(fileName string, fileLine int, callLevel int, callFunc string, logLevel int, when time.Time, msg string) error
	Destroy()
	Flush()
}

Logger defines the behavior of a log provider.

func NewConn

func NewConn() ILogger

NewConn create new ConnWrite returning as LoggerInterface.

func NewConsole

func NewConsole() ILogger

NewConsole create ConsoleWriter 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) Destroy

func (s *SMTPWriter) Destroy()

Destroy implementing method. empty.

func (*SMTPWriter) Flush

func (s *SMTPWriter) Flush()

Flush implementing method. empty.

func (*SMTPWriter) GetLevel added in v1.0.1

func (w *SMTPWriter) GetLevel() int

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) SetLevel added in v1.0.1

func (w *SMTPWriter) SetLevel(l int)

func (*SMTPWriter) WriteMsg

func (s *SMTPWriter) WriteMsg(fileName string, fileLine int, callLevel int, callFunc string, logLevel int, when time.Time, msg string) error

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

type TLogger

type TLogger struct {
	Async_flag bool // 是否异步消息
	// contains filtered or unexported fields
}

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

func InitGLogger

func InitGLogger(level int) *TLogger

func NewLogger

func NewLogger(channelLens ...int64) *TLogger

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 SetSync added in v1.0.1

func SetSync(msgLen ...int64) *TLogger

func (*TLogger) Alert

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

Alert Log ALERT level message.

func (*TLogger) Begin

func (bl *TLogger) Begin()

Debug Log DEBUG level message.

func (*TLogger) Close

func (bl *TLogger) Close()

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

func (*TLogger) Critical

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

Critical Log CRITICAL level message.

func (*TLogger) Debug

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

Debug Log DEBUG level message.

func (*TLogger) DelLogger

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

DelLogger remove a logger adapter in BeeLogger.

func (*TLogger) Emergency

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

Emergency Log EMERGENCY level message.

func (*TLogger) End

func (bl *TLogger) End()

Debug Log DEBUG level message.

func (*TLogger) Error

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

Error Log ERROR level message.

func (*TLogger) Flush

func (bl *TLogger) Flush()

Flush flush all chan data.

func (*TLogger) GetCallStack

func (bl *TLogger) GetCallStack() (level int, stack string, file string, line int)

func (*TLogger) GetClassName

func (bl *TLogger) GetClassName(func_name string) string

github.com/tea4go/application/myproxy/service.THTTP.StartServer

func (*TLogger) GetLastLogTime

func (bl *TLogger) GetLastLogTime() time.Time

func (*TLogger) GetLevel

func (bl *TLogger) GetLevel(adapters ...string) int

func (*TLogger) GetLogFuncCallDepth

func (bl *TLogger) GetLogFuncCallDepth() int

GetLogFuncCallDepth return log funcCallDepth for wrapper

func (*TLogger) Info

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

Info Log Info level message.

func (*TLogger) Notice

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

Notice Log NOTICE level message.

func (*TLogger) Print

func (bl *TLogger) Print(format string, v ...interface{})

Debug Log DEBUG level message.

func (*TLogger) Reset

func (bl *TLogger) Reset()

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

func (*TLogger) SetFDebug added in v1.0.1

func (bl *TLogger) SetFDebug(l bool)

func (*TLogger) SetLevel

func (bl *TLogger) SetLevel(l int, adapters ...string)

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 (*TLogger) SetLogFuncCallDepth

func (bl *TLogger) SetLogFuncCallDepth(d int)

SetLogFuncCallDepth set log funcCallDepth

func (*TLogger) SetLogger

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

SetLogger provides a given logger adapter into BeeLogger with config string. config need to be correct JSON as string: {"interval":360}.

func (*TLogger) SetSync added in v1.0.1

func (bl *TLogger) SetSync(msgLen ...int64) *TLogger

func (*TLogger) Warning

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

Warning Log WARNING level message.

func (*TLogger) Write

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

Directories

Path Synopsis
testlog

Jump to

Keyboard shortcuts

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