logs

package
v0.0.0-...-a323839 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

README

logs

logs is a Go logs manager. It can use many logs adapters. The repo is inspired by database/sql .

How to install?

go get github.com/astaxie/beego/logs

What adapters are supported?

As of now this logs support console, file,smtp and conn.

How to use it?

First you must import it

import (
	"github.com/astaxie/beego/logs"
)

Then init a Log (example with console adapter)

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

File adapter

Configure file adapter like this:

log := NewLogger(10000)
log.SetLogger("file", `{"filename":"test.log"}`)

Conn adapter

Configure like this:

log := NewLogger(1000)
log.SetLogger("conn", `{"net":"tcp","addr":":7020"}`)
log.Info("info")

Smtp adapter

Configure like this:

log := NewLogger(10000)
log.SetLogger("smtp", `{"username":"beegotest@gmail.com","password":"xxxxxxxx","host":"smtp.gmail.com:587","sendTos":["xiemengjun@gmail.com"]}`)
log.Critical("sendmail critical")
time.Sleep(time.Second * 30)

Documentation

Overview

Package logs provide a general log interface Usage:

import "github.com/augutoma/beegonew/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
	LevelInformational
	LevelDebug
)

RFC5424 log message levels.

View Source
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

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

Legacy log level constants to ensure backwards compatibility.

View Source
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

This section is empty.

Functions

func Alert

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

Alert logs a message at alert level.

func ColorByMethod

func ColorByMethod(cond bool, method string) string

func ColorByStatus

func ColorByStatus(cond bool, code int) string

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 Debugctx

func Debugctx(ctx context.Context, f interface{}, v ...interface{})

Debugctx logs a message at debug level.

func Debugdb

func Debugdb(ctx context.Context, f interface{}, v ...interface{})

Debug logs a message at debug level.

func Debugref

func Debugref(data map[interface{}]interface{}, 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 EnableFuncCallDepth

func EnableFuncCallDepth(b bool)

EnableFuncCallDepth enable log funcCallDepth

func Error

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

Error logs a message at error level.

func Errorctx

func Errorctx(ctx context.Context, f interface{}, v ...interface{})

Errorctx logs a message at debug level.

func Errorref

func Errorref(data map[interface{}]interface{}, f interface{}, v ...interface{})

Debug logs a message at debug level.

func GetLogger

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

GetLogger returns the default BeeLogger

func Info

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

Info compatibility alias for Warning()

func Infoctx

func Infoctx(ctx context.Context, f interface{}, v ...interface{})

Infoctx logs a message at debug level.

func Inforef

func Inforef(data map[interface{}]interface{}, f interface{}, v ...interface{})

Debug logs a message at debug level.

func Informational

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

Informational logs a message at info level.

func NewAnsiColorWriter

func NewAnsiColorWriter(w io.Writer) io.Writer

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

func NewModeAnsiColorWriter(w io.Writer, mode outputMode) io.Writer

NewModeAnsiColorWriter create and initializes a new ansiColorWriter by specifying the outputMode.

func Notice

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

Notice logs a message at notice level.

func Noticectx

func Noticectx(ctx context.Context, f interface{}, v ...interface{})

Noticectx logs a message at debug level.

func Noticeref

func Noticeref(data map[interface{}]interface{}, 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 SetLevel

func SetLevel(l int)

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

func SetLogFuncCall

func SetLogFuncCall(b bool)

SetLogFuncCall set the CallDepth, default is 4

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 Trace

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

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

func Tracectx

func Tracectx(ctx context.Context, f interface{}, v ...interface{})

Tracectx logs a message at debug level.

func Traceref

func Traceref(data map[interface{}]interface{}, f interface{}, v ...interface{})

Debug logs a message at debug level.

func W32Debug

func W32Debug(msg string)

Helper method to output colored logs in Windows terminals

func Warn

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

Warn compatibility alias for Warning()

func Warnctx

func Warnctx(ctx context.Context, f interface{}, v ...interface{})

Warnctx logs a message at debug level.

func Warning

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

Warning logs a message at warning level.

func Warnref

func Warnref(data map[interface{}]interface{}, f interface{}, v ...interface{})

Debug logs a message at debug level.

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 Async

func Async(msgLen ...int64) *BeeLogger

func GetBeeLogger

func GetBeeLogger() *BeeLogger

GetLogger returns the default BeeLogger

func NewLogger

func NewLogger(channelLens ...int64) *BeeLogger

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(format string, v ...interface{})

Alert Log ALERT level message.

func (*BeeLogger) Async

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

Async set the log to asynchronous and start the goroutine

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(format string, v ...interface{})

Critical Log CRITICAL level message.

func (*BeeLogger) Debug

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

Debug Log DEBUG level message.

func (*BeeLogger) Debugctx

func (bl *BeeLogger) Debugctx(ctx context.Context, format string, v ...interface{})

Debugctx Log DEBUG level message.

func (*BeeLogger) Debugdb

func (bl *BeeLogger) Debugdb(ctx context.Context, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) Debugref

func (bl *BeeLogger) Debugref(data map[interface{}]interface{}, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) DelLogger

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

DelLogger remove a logger adapter in BeeLogger.

func (*BeeLogger) Emergency

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

Emergency Log EMERGENCY level message.

func (*BeeLogger) EnableFuncCallDepth

func (bl *BeeLogger) EnableFuncCallDepth(b bool)

EnableFuncCallDepth enable log funcCallDepth

func (*BeeLogger) Error

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

Error Log ERROR level message.

func (*BeeLogger) Errorctx

func (bl *BeeLogger) Errorctx(ctx context.Context, format string, v ...interface{})

Errorctx Log ERROR level message.

func (*BeeLogger) Errorref

func (bl *BeeLogger) Errorref(data map[interface{}]interface{}, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) Flush

func (bl *BeeLogger) Flush()

Flush flush all chan data.

func (*BeeLogger) GetLogFuncCallDepth

func (bl *BeeLogger) GetLogFuncCallDepth() int

GetLogFuncCallDepth return log funcCallDepth for wrapper

func (*BeeLogger) Info

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

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

func (*BeeLogger) Infoctx

func (bl *BeeLogger) Infoctx(ctx context.Context, format string, v ...interface{})

Infoctx Log INFO level message.

func (*BeeLogger) Inforef

func (bl *BeeLogger) Inforef(data map[interface{}]interface{}, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) Informational

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

Informational Log INFORMATIONAL level message.

func (*BeeLogger) Notice

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

Notice Log NOTICE level message.

func (*BeeLogger) Noticectx

func (bl *BeeLogger) Noticectx(ctx context.Context, format string, v ...interface{})

Noticectx Log NOTICE level message.

func (*BeeLogger) Noticeref

func (bl *BeeLogger) Noticeref(data map[interface{}]interface{}, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) Reset

func (bl *BeeLogger) Reset()

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

func (*BeeLogger) SetLevel

func (bl *BeeLogger) 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 (*BeeLogger) SetLogFuncCallDepth

func (bl *BeeLogger) SetLogFuncCallDepth(d int)

SetLogFuncCallDepth set log funcCallDepth

func (*BeeLogger) SetLogger

func (bl *BeeLogger) 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 (*BeeLogger) Trace

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

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

func (*BeeLogger) Tracectx

func (bl *BeeLogger) Tracectx(ctx context.Context, format string, v ...interface{})

Tracectx Log TRACE level message.

func (*BeeLogger) Traceref

func (bl *BeeLogger) Traceref(data map[interface{}]interface{}, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) Warn

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

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

func (*BeeLogger) Warnctx

func (bl *BeeLogger) Warnctx(ctx context.Context, format string, v ...interface{})

Warnctx Log WARN level message.

func (*BeeLogger) Warning

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

Warning Log WARNING level message.

func (*BeeLogger) Warnref

func (bl *BeeLogger) Warnref(data map[interface{}]interface{}, format string, v ...interface{})

Debugdb Log DEBUG level message.

func (*BeeLogger) Write

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

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

func (*JLWriter) Destroy

func (s *JLWriter) Destroy()

Destroy implementing method. empty.

func (*JLWriter) Flush

func (s *JLWriter) Flush()

Flush implementing method. empty.

func (*JLWriter) Init

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

Init JLWriter with json config string

func (*JLWriter) WriteMsg

func (s *JLWriter) WriteMsg(when time.Time, msg string, level int) error

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

type Logger

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

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

SLACKWriter implements beego LoggerInterface and is used to send jiaoliao webhook

func (*SLACKWriter) Destroy

func (s *SLACKWriter) Destroy()

Destroy implementing method. empty.

func (*SLACKWriter) Flush

func (s *SLACKWriter) Flush()

Flush implementing method. empty.

func (*SLACKWriter) Init

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

Init SLACKWriter with json config string

func (*SLACKWriter) WriteMsg

func (s *SLACKWriter) WriteMsg(when time.Time, msg string, level int) error

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

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(when time.Time, msg string, level int) error

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

Directories

Path Synopsis
Package sls implements the SDK(v0.5.0) of Simple Log Service(abbr.
Package sls implements the SDK(v0.5.0) of Simple Log Service(abbr.

Jump to

Keyboard shortcuts

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