logs

package module
v0.0.0-...-fcce279 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: Apache-2.0 Imports: 18 Imported by: 1

README

log4go

test1

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

This section is empty.

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 ColorByMethod

func ColorByMethod(method string) string

ColorByMethod return color by http code

func ColorByStatus

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

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 GetLastLogTime

func GetLastLogTime() time.Time

func GetLevel

func GetLevel() int

func GetLevelName

func GetLevelName(level int) string

func GetLogger

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

GetLogger returns the default BeeLogger

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

Reset will remove all the adapter

func ResetColor

func ResetColor() string

ResetColor return reset color

func SetLevel

func SetLevel(l int)

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

func SetLogFuncCallDepth

func SetLogFuncCallDepth(d int)

SetLogFuncCallDepth set log funcCallDepth

func SetLogger

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

SetLogger sets a new logger.

func Warning

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

Warning logs a message at warning level.

Types

type Logger

type Logger interface {
	Init(config string) error
	//WriteMsg(when time.Time, msg string, level int) error
	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() Logger

NewConn create new ConnWrite returning as LoggerInterface.

func NewConsole

func NewConsole() Logger

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

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 {
	// contains filtered or unexported fields
}

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

func Async

func Async(msgLen ...int64) *TLogger

func InitGLogger

func InitGLogger(level int) *TLogger

GetLogger returns the default BeeLogger

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

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

Alert Log ALERT level message.

func (*TLogger) Async

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

Async set the log to asynchronous and start the goroutine

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() 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) SetLevel

func (bl *TLogger) SetLevel(l int)

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

Jump to

Keyboard shortcuts

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