log

package
v0.0.0-...-85b91c5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 27 Imported by: 97

Documentation

Index

Constants

View Source
const (
	Ldate          = 1 << iota // the date in the local time zone: 2009/01/23
	Ltime                      // the time in the local time zone: 01:23:23
	Lmicroseconds              // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                  // full file name and line number: /a/logger/c/d.go:23
	Lshortfile                 // final file name element and line number: d.go:23. overrides Llongfile
	Lfuncname                  // function name of the caller: runtime.Caller()
	Lshortfuncname             // last part of the function name
	LUTC                       // if Ldate or Ltime is set, use UTC rather than the local time zone
	Llevelinitial              // Initial character of the provided level in brackets eg. [I] for info
	Llevel                     // Provided level in brackets [INFO]

	// Last 20 characters of the filename
	Lmedfile = Lshortfile | Llongfile

	// LstdFlags is the initial value for the standard logger
	LstdFlags = Ldate | Ltime | Lmedfile | Lshortfuncname | Llevelinitial
)

These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only if more than time is stated is specified. For example, flags Ldate | Ltime produce, 2009/01/23 01:23:23 message. The standard is: 2009/01/23 01:23:23 ...a/logger/c/d.go:23:runtime.Caller() [I]: message

Variables

View Source
var (
	// DEFAULT is the name of the default logger
	DEFAULT = "default"
	// NamedLoggers map of named loggers
	NamedLoggers loggerMap
)
View Source
var CanColorStderr = true

CanColorStderr reports if we can color the Stderr

View Source
var CanColorStdout = true

CanColorStdout reports if we can color the Stdout Although we could do terminal sniffing and the like - in reality most tools on *nix are happy to display ansi colors. We will terminal sniff on Windows in console_windows.go

Functions

func Close

func Close()

Close closes all the loggers

func ColorBytes

func ColorBytes(attrs ...ColorAttribute) []byte

ColorBytes converts a list of ColorAttributes to a byte array

func ColorFprintf

func ColorFprintf(w io.Writer, format string, args ...interface{}) (int, error)

ColorFprintf will write to the provided writer similar to ColorSprintf

func ColorSprintf

func ColorSprintf(format string, args ...interface{}) string

ColorSprintf returns a colored string from a format and arguments arguments will be wrapped in ColoredValues to protect against color spoofing

func ColorString

func ColorString(attrs ...ColorAttribute) string

ColorString converts a list of ColorAttributes to a color string

func Critical

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

Critical records critical log

func CriticalWithSkip

func CriticalWithSkip(skip int, format string, v ...interface{})

CriticalWithSkip records critical log from "skip" calls back from this function

func Debug

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

Debug records debug log

func DelLogger

func DelLogger(name string) error

DelLogger removes the named sublogger from the default logger

func DelNamedLogger

func DelNamedLogger(name string)

DelNamedLogger closes and deletes the named logger

func Error

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

Error records error log

func ErrorWithSkip

func ErrorWithSkip(skip int, format string, v ...interface{})

ErrorWithSkip records error log from "skip" calls back from this function

func Fatal

func Fatal(format string, v ...interface{})

Fatal records fatal log and exit process

func FatalWithSkip

func FatalWithSkip(skip int, format string, v ...interface{})

FatalWithSkip records fatal log from "skip" calls back from this function

func FlagsFromString

func FlagsFromString(from string) int

FlagsFromString takes a comma separated list of flags and returns the flags for this string

func Info

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

Info records info log

func IsCritical

func IsCritical() bool

IsCritical returns true if at least one logger is CRITICAL

func IsDebug

func IsDebug() bool

IsDebug returns true if at least one logger is DEBUG

func IsErrDuplicateName

func IsErrDuplicateName(err error) bool

IsErrDuplicateName checks if an error is a ErrDuplicateName.

func IsErrTimeout

func IsErrTimeout(err error) bool

IsErrTimeout checks if an error is a ErrTimeout.

func IsErrUnknownProvider

func IsErrUnknownProvider(err error) bool

IsErrUnknownProvider checks if an error is a ErrUnknownProvider.

func IsError

func IsError() bool

IsError returns true if at least one logger is ERROR

func IsFatal

func IsFatal() bool

IsFatal returns true if at least one logger is FATAL

func IsInfo

func IsInfo() bool

IsInfo returns true if at least one logger is INFO

func IsTrace

func IsTrace() bool

IsTrace returns true if at least one logger is TRACE

func IsWarn

func IsWarn() bool

IsWarn returns true if at least one logger is WARN

func Levels

func Levels() []string

Levels returns all the possible logging levels

func Log

func Log(skip int, level Level, format string, v ...interface{})

Log a message with defined skip and at logging level A skip of 0 refers to the caller of this command

func NewNamedLogger

func NewNamedLogger(name string, bufLen int64, subname, provider, config string, noCaller bool) error

NewNamedLogger creates a new named logger for a given configuration

func NewSimpleLogger

func NewSimpleLogger(logBufferLength int64, mode, level, stacktraceLevel, logPath string, noCaller bool)

mode can be console, file

func Pause

func Pause()

Pause pauses all the loggers

func Register

func Register(name string, log loggerProvider)

Register registers given logger provider to providers.

func ReleaseReopen

func ReleaseReopen() error

ReleaseReopen releases and reopens logging files

func Resume

func Resume()

Resume resumes all the loggers

func Stack

func Stack(skip int) string

Stack will skip back the provided number of frames and return a stack trace with source code. Although we could just use debug.Stack(), this routine will return the source code and skip back the provided number of frames - i.e. allowing us to ignore preceding function calls. A skip of 0 returns the stack trace for the calling function, not including this call. If the problem is a lack of memory of course all this is not going to work...

func Trace

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

Trace records trace log

func Warn

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

Warn records warning log

Types

type BufferLogger

type BufferLogger struct {
	WriterLogger
}

BufferLogger implements LoggerProvider and writes messages in a buffer.

func (*BufferLogger) Content

func (log *BufferLogger) Content() (string, error)

Content returns the content accumulated in the content provider

func (*BufferLogger) Flush

func (log *BufferLogger) Flush()

Flush when log should be flushed

func (*BufferLogger) GetName

func (log *BufferLogger) GetName() string

GetName returns the default name for this implementation

func (*BufferLogger) Init

func (log *BufferLogger) Init(string) error

Init inits connection writer

func (*BufferLogger) ReleaseReopen

func (log *BufferLogger) ReleaseReopen() error

ReleaseReopen does nothing

type ChannelledLog

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

ChannelledLog represents a cached channel to a LoggerProvider

func NewChannelledLog

func NewChannelledLog(parent context.Context, name, provider, config string, bufferLength int64) (*ChannelledLog, error)

NewChannelledLog a new logger instance with given logger provider and config.

func (*ChannelledLog) Close

func (l *ChannelledLog) Close()

Close this ChannelledLog

func (*ChannelledLog) Flush

func (l *ChannelledLog) Flush()

Flush this ChannelledLog

func (*ChannelledLog) GetLevel

func (l *ChannelledLog) GetLevel() Level

GetLevel gets the level of this ChannelledLog

func (*ChannelledLog) GetName

func (l *ChannelledLog) GetName() string

GetName returns the name of this ChannelledLog

func (*ChannelledLog) GetStacktraceLevel

func (l *ChannelledLog) GetStacktraceLevel() Level

GetStacktraceLevel gets the level of this ChannelledLog

func (*ChannelledLog) LogEvent

func (l *ChannelledLog) LogEvent(event *Event) error

LogEvent logs an event to this ChannelledLog

func (*ChannelledLog) ReleaseReopen

func (l *ChannelledLog) ReleaseReopen() error

ReleaseReopen this ChannelledLog

func (*ChannelledLog) Start

func (l *ChannelledLog) Start()

Start processing the ChannelledLog

type ColorAttribute

type ColorAttribute int

ColorAttribute defines a single SGR Code

const (
	Reset ColorAttribute = iota
	Bold
	Faint
	Italic
	Underline
	BlinkSlow
	BlinkRapid
	ReverseVideo
	Concealed
	CrossedOut
)

Base ColorAttributes

const (
	FgBlack ColorAttribute = iota + 30
	FgRed
	FgGreen
	FgYellow
	FgBlue
	FgMagenta
	FgCyan
	FgWhite
)

Foreground text colors

const (
	FgHiBlack ColorAttribute = iota + 90
	FgHiRed
	FgHiGreen
	FgHiYellow
	FgHiBlue
	FgHiMagenta
	FgHiCyan
	FgHiWhite
)

Foreground Hi-Intensity text colors

const (
	BgBlack ColorAttribute = iota + 40
	BgRed
	BgGreen
	BgYellow
	BgBlue
	BgMagenta
	BgCyan
	BgWhite
)

Background text colors

const (
	BgHiBlack ColorAttribute = iota + 100
	BgHiRed
	BgHiGreen
	BgHiYellow
	BgHiBlue
	BgHiMagenta
	BgHiCyan
	BgHiWhite
)

Background Hi-Intensity text colors

func ColorAttributeFromString

func ColorAttributeFromString(from string) ColorAttribute

ColorAttributeFromString will return a ColorAttribute given a string

func (*ColorAttribute) String

func (c *ColorAttribute) String() string

type ColorFormatted

type ColorFormatted interface {
	// ColorFormat provides the colored representation of the value
	ColorFormat(s fmt.State)
}

ColorFormatted structs provide their own colored string when formatted with ColorSprintf

type ColoredValue

type ColoredValue struct {
	Value *interface{}
	// contains filtered or unexported fields
}

ColoredValue will Color the provided value

func ColoredMethod

func ColoredMethod(method string) *ColoredValue

ColoredMethod adds colors for HTTP methods on log

func ColoredStatus

func ColoredStatus(status int, s ...string) *ColoredValue

ColoredStatus adds colors for HTTP status

func ColoredTime

func ColoredTime(duration time.Duration) *ColoredValue

ColoredTime converts the provided time to a ColoredValue for logging. The duration is always formatted in milliseconds.

func NewColoredIDValue

func NewColoredIDValue(value interface{}) *ColoredValue

NewColoredIDValue is a helper function to create a ColoredValue from a Value The Value will be colored with FgCyan If a ColoredValue is provided it is not changed

func NewColoredValue

func NewColoredValue(value interface{}, color ...ColorAttribute) *ColoredValue

NewColoredValue is a helper function to create a ColoredValue from a Value If no color is provided it defaults to Bold with standard Reset If a ColoredValue is provided it is not changed

func NewColoredValueBytes

func NewColoredValueBytes(value interface{}, colorBytes *[]byte) *ColoredValue

NewColoredValueBytes creates a value from the provided value with color bytes If a ColoredValue is provided it is not changed

func NewColoredValuePointer

func NewColoredValuePointer(value *interface{}, color ...ColorAttribute) *ColoredValue

NewColoredValuePointer is a helper function to create a ColoredValue from a Value Pointer If no color is provided it defaults to Bold with standard Reset If a ColoredValue is provided it is not changed

func (*ColoredValue) Format

func (cv *ColoredValue) Format(s fmt.State, c rune)

Format will format the provided value and protect against ANSI color spoofing within the value If the wrapped value is ColorFormatted and the format is "%-v" then its ColorString will be used. It is presumed that this ColorString is safe.

func (*ColoredValue) SetColorBytes

func (cv *ColoredValue) SetColorBytes(colorBytes []byte)

SetColorBytes will allow a user to set the colorBytes of a colored value

func (*ColoredValue) SetColorBytesPointer

func (cv *ColoredValue) SetColorBytesPointer(colorBytes *[]byte)

SetColorBytesPointer will allow a user to set the colorBytes pointer of a colored value

func (*ColoredValue) SetResetBytes

func (cv *ColoredValue) SetResetBytes(resetBytes []byte)

SetResetBytes will allow a user to set the resetBytes pointer of a colored value

func (*ColoredValue) SetResetBytesPointer

func (cv *ColoredValue) SetResetBytesPointer(resetBytes *[]byte)

SetResetBytesPointer will allow a user to set the resetBytes pointer of a colored value

type ConnLogger

type ConnLogger struct {
	WriterLogger
	ReconnectOnMsg bool   `json:"reconnectOnMsg"`
	Reconnect      bool   `json:"reconnect"`
	Net            string `json:"net"`
	Addr           string `json:"addr"`
}

ConnLogger implements LoggerProvider. it writes messages in keep-live tcp connection.

func (*ConnLogger) Content

func (log *ConnLogger) Content() (string, error)

Content returns the content accumulated in the content provider

func (*ConnLogger) Flush

func (log *ConnLogger) Flush()

Flush does nothing for this implementation

func (*ConnLogger) GetName

func (log *ConnLogger) GetName() string

GetName returns the default name for this implementation

func (*ConnLogger) Init

func (log *ConnLogger) Init(jsonconfig string) error

Init inits connection writer with json config. json config only need key "level".

func (*ConnLogger) ReleaseReopen

func (log *ConnLogger) ReleaseReopen() error

ReleaseReopen causes the ConnLogger to reconnect to the server

type ConsoleLogger

type ConsoleLogger struct {
	WriterLogger
	Stderr bool `json:"stderr"`
}

ConsoleLogger implements LoggerProvider and writes messages to terminal.

func (*ConsoleLogger) Content

func (log *ConsoleLogger) Content() (string, error)

Content returns the content accumulated in the content provider

func (*ConsoleLogger) Flush

func (log *ConsoleLogger) Flush()

Flush when log should be flushed

func (*ConsoleLogger) GetName

func (log *ConsoleLogger) GetName() string

GetName returns the default name for this implementation

func (*ConsoleLogger) Init

func (log *ConsoleLogger) Init(config string) error

Init inits connection writer with json config. json config only need key "level".

func (*ConsoleLogger) ReleaseReopen

func (log *ConsoleLogger) ReleaseReopen() error

ReleaseReopen causes the console logger to reconnect to os.Stdout

type Entry

type Entry struct {
	Data map[string]interface{}
	// contains filtered or unexported fields
}

func NewEntry

func NewEntry() *Entry

func WithError

func WithError(err error) *Entry

func WithField

func WithField(key string, value interface{}) *Entry

func WithFields

func WithFields(fields Fields) *Entry

func (*Entry) Critical

func (e *Entry) Critical(format string, v ...interface{})

func (*Entry) Debug

func (e *Entry) Debug(format string, v ...interface{})

func (*Entry) Error

func (e *Entry) Error(format string, v ...interface{})

func (*Entry) Fatal

func (e *Entry) Fatal(format string, v ...interface{})

func (*Entry) Info

func (e *Entry) Info(format string, v ...interface{})

func (*Entry) Trace

func (e *Entry) Trace(format string, v ...interface{})

func (*Entry) Warn

func (e *Entry) Warn(format string, v ...interface{})

func (*Entry) WithError

func (e *Entry) WithError(err error) *Entry

func (*Entry) WithField

func (e *Entry) WithField(key string, value interface{}) *Entry

func (*Entry) WithFields

func (e *Entry) WithFields(fields Fields) *Entry

type ErrDuplicateName

type ErrDuplicateName struct {
	Name string
}

ErrDuplicateName represents a Duplicate Name error

func (ErrDuplicateName) Error

func (err ErrDuplicateName) Error() string

type ErrTimeout

type ErrTimeout struct {
	Name     string
	Provider string
}

ErrTimeout represents a "Timeout" kind of error.

func (ErrTimeout) Error

func (err ErrTimeout) Error() string

type ErrUnknownProvider

type ErrUnknownProvider struct {
	Provider string
}

ErrUnknownProvider represents a "Unknown Provider" kind of error.

func (ErrUnknownProvider) Error

func (err ErrUnknownProvider) Error() string

type Event

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

Event represents a logging event

type EventLogger

type EventLogger interface {
	LogEvent(event *Event) error
	Close()
	Flush()
	GetLevel() Level
	GetStacktraceLevel() Level
	GetName() string
	ReleaseReopen() error
}

EventLogger represents the behaviours of a logger

type Fields

type Fields map[string]interface{}

type FileLogger

type FileLogger struct {
	WriterLogger

	// The opened file
	Filename string `json:"filename"`

	// Rotate at size
	Maxsize int `json:"maxsize"`

	// Rotate daily
	Daily   bool  `json:"daily"`
	Maxdays int64 `json:"maxdays"`

	Rotate bool `json:"rotate"`

	Compress         bool `json:"compress"`
	CompressionLevel int  `json:"compressionLevel"`
	// contains filtered or unexported fields
}

FileLogger implements LoggerProvider. It writes messages by lines limit, file size limit, or time frequency.

func (*FileLogger) Content

func (log *FileLogger) Content() (string, error)

Content returns the content accumulated in the content provider

func (*FileLogger) DoRotate

func (log *FileLogger) DoRotate() error

DoRotate means it need to write file in new file. new file name like xx.log.2013-01-01.2

func (*FileLogger) Flush

func (log *FileLogger) Flush()

Flush flush file logger. there are no buffering messages in file logger in memory. flush file means sync file from disk.

func (*FileLogger) GetName

func (log *FileLogger) GetName() string

GetName returns the default name for this implementation

func (*FileLogger) Init

func (log *FileLogger) Init(config string) error

Init file logger with json config. config like:

{
"filename":"log/gogs.log",
"maxsize":1<<30,
"daily":true,
"maxdays":15,
"rotate":true
}

func (*FileLogger) ReleaseReopen

func (log *FileLogger) ReleaseReopen() error

ReleaseReopen releases and reopens log files

func (*FileLogger) StartLogger

func (log *FileLogger) StartLogger() error

StartLogger start file logger. create log file and set to locker-inside file writer.

type Level

type Level int

Level is the level of the logger

const (
	// TRACE represents the lowest log level
	TRACE Level = iota
	// DEBUG is for debug logging
	DEBUG
	// INFO is for information
	INFO
	// WARN is for warning information
	WARN
	// ERROR is for error reporting
	ERROR
	// CRITICAL is for critical errors
	CRITICAL
	// FATAL is for fatal errors
	FATAL
	// NONE is for no logging
	NONE
)

func FromString

func FromString(level string) Level

FromString takes a level string and returns a Level

func GetLevel

func GetLevel() Level

GetLevel returns the minimum logger level

func GetStacktraceLevel

func GetStacktraceLevel() Level

GetStacktraceLevel returns the minimum logger level

func (Level) Color

func (l Level) Color() *[]byte

Color returns the color string for this Level

func (Level) Icon

func (l Level) Icon() []byte

func (Level) MarshalJSON

func (l Level) MarshalJSON() ([]byte, error)

MarshalJSON takes a Level and turns it into text

func (Level) String

func (l Level) String() string

func (*Level) UnmarshalJSON

func (l *Level) UnmarshalJSON(b []byte) error

UnmarshalJSON takes text and turns it into a Level

type LevelLogger

type LevelLogger interface {
	Flush()
	Close()
	GetLevel() Level
	Log(skip int, level Level, format string, v ...interface{}) error
}

LevelLogger is the simplest logging interface

type LevelLoggerLogger

type LevelLoggerLogger struct {
	LevelLogger
}

LevelLoggerLogger wraps a LevelLogger as a Logger

func (*LevelLoggerLogger) Critical

func (l *LevelLoggerLogger) Critical(format string, v ...interface{})

Critical records critical log

func (*LevelLoggerLogger) CriticalWithSkip

func (l *LevelLoggerLogger) CriticalWithSkip(skip int, format string, v ...interface{})

CriticalWithSkip records critical log from "skip" calls back from this function

func (*LevelLoggerLogger) Debug

func (l *LevelLoggerLogger) Debug(format string, v ...interface{})

Debug records debug log

func (*LevelLoggerLogger) Error

func (l *LevelLoggerLogger) Error(format string, v ...interface{})

Error records error log

func (*LevelLoggerLogger) ErrorWithSkip

func (l *LevelLoggerLogger) ErrorWithSkip(skip int, format string, v ...interface{})

ErrorWithSkip records error log from "skip" calls back from this function

func (*LevelLoggerLogger) Fatal

func (l *LevelLoggerLogger) Fatal(format string, v ...interface{})

Fatal records fatal log and exit the process

func (*LevelLoggerLogger) FatalWithSkip

func (l *LevelLoggerLogger) FatalWithSkip(skip int, format string, v ...interface{})

FatalWithSkip records fatal log from "skip" calls back from this function and exits the process

func (*LevelLoggerLogger) Info

func (l *LevelLoggerLogger) Info(format string, v ...interface{})

Info records information log

func (*LevelLoggerLogger) IsCritical

func (l *LevelLoggerLogger) IsCritical() bool

IsCritical returns true if the logger is CRITICAL

func (*LevelLoggerLogger) IsDebug

func (l *LevelLoggerLogger) IsDebug() bool

IsDebug returns true if the logger is DEBUG

func (*LevelLoggerLogger) IsError

func (l *LevelLoggerLogger) IsError() bool

IsError returns true if the logger is ERROR

func (*LevelLoggerLogger) IsFatal

func (l *LevelLoggerLogger) IsFatal() bool

IsFatal returns true if the logger is FATAL

func (*LevelLoggerLogger) IsInfo

func (l *LevelLoggerLogger) IsInfo() bool

IsInfo returns true if the logger is INFO

func (*LevelLoggerLogger) IsTrace

func (l *LevelLoggerLogger) IsTrace() bool

IsTrace returns true if the logger is TRACE

func (*LevelLoggerLogger) IsWarn

func (l *LevelLoggerLogger) IsWarn() bool

IsWarn returns true if the logger is WARN

func (*LevelLoggerLogger) Trace

func (l *LevelLoggerLogger) Trace(format string, v ...interface{})

Trace records trace log

func (*LevelLoggerLogger) Warn

func (l *LevelLoggerLogger) Warn(format string, v ...interface{})

Warn records warning log

type Logger

type Logger interface {
	LevelLogger
	Trace(format string, v ...interface{})
	IsTrace() bool
	Debug(format string, v ...interface{})
	IsDebug() bool
	Info(format string, v ...interface{})
	IsInfo() bool
	Warn(format string, v ...interface{})
	IsWarn() bool
	Error(format string, v ...interface{})
	ErrorWithSkip(skip int, format string, v ...interface{})
	IsError() bool
	Critical(format string, v ...interface{})
	CriticalWithSkip(skip int, format string, v ...interface{})
	IsCritical() bool
	Fatal(format string, v ...interface{})
	FatalWithSkip(skip int, format string, v ...interface{})
	IsFatal() bool
}

Logger is the basic interface for logging

type LoggerAsWriter

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

LoggerAsWriter is a io.Writer shim around the gitbundle log

func NewLoggerAsWriter

func NewLoggerAsWriter(level string, ourLoggers ...*MultiChannelledLogger) *LoggerAsWriter

NewLoggerAsWriter creates a Writer representation of the logger with setable log level

func (*LoggerAsWriter) Log

func (l *LoggerAsWriter) Log(msg string)

Log takes a given string and logs it at the set log-level

func (*LoggerAsWriter) Write

func (l *LoggerAsWriter) Write(p []byte) (int, error)

Write implements the io.Writer interface to allow spoofing of chi

type LoggerProvider

type LoggerProvider interface {
	Init(config string) error
	Content() (string, error)
	EventLogger
}

LoggerProvider represents behaviors of a logger provider.

func NewBufferLogger

func NewBufferLogger() LoggerProvider

NewBufferLogger create BufferLogger returning as LoggerProvider.

func NewConn

func NewConn() LoggerProvider

NewConn creates new ConnLogger returning as LoggerProvider.

func NewConsoleLogger

func NewConsoleLogger() LoggerProvider

NewConsoleLogger create ConsoleLogger returning as LoggerProvider.

func NewFileLogger

func NewFileLogger() LoggerProvider

NewFileLogger create a FileLogger returning as LoggerProvider.

func NewSMTPLogger

func NewSMTPLogger() LoggerProvider

NewSMTPLogger creates smtp writer.

type MultiChannelledLog

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

MultiChannelledLog represents a cached channel to a LoggerProvider

func NewMultiChannelledLog

func NewMultiChannelledLog(name string, bufferLength int64) *MultiChannelledLog

NewMultiChannelledLog a new logger instance with given logger provider and config.

func (*MultiChannelledLog) AddLogger

func (m *MultiChannelledLog) AddLogger(logger EventLogger) error

AddLogger adds a logger to this MultiChannelledLog

func (*MultiChannelledLog) Close

func (m *MultiChannelledLog) Close()

Close this MultiChannelledLog

func (*MultiChannelledLog) DelLogger

func (m *MultiChannelledLog) DelLogger(name string) bool

DelLogger removes a sub logger from this MultiChannelledLog NB: If you delete the last sublogger this logger will simply drop log events

func (*MultiChannelledLog) Flush

func (m *MultiChannelledLog) Flush()

Flush this ChannelledLog

func (*MultiChannelledLog) GetEventLogger

func (m *MultiChannelledLog) GetEventLogger(name string) EventLogger

GetEventLogger returns a sub logger from this MultiChannelledLog

func (*MultiChannelledLog) GetEventLoggerNames

func (m *MultiChannelledLog) GetEventLoggerNames() []string

GetEventLoggerNames returns a list of names

func (*MultiChannelledLog) GetLevel

func (m *MultiChannelledLog) GetLevel() Level

GetLevel gets the level of this MultiChannelledLog

func (*MultiChannelledLog) GetLoggerProviderContent

func (m *MultiChannelledLog) GetLoggerProviderContent(name string) (string, error)

GetEventProvider returns a sub logger provider content from this MultiChannelledLog

func (*MultiChannelledLog) GetName

func (m *MultiChannelledLog) GetName() string

GetName gets the name of this MultiChannelledLog

func (*MultiChannelledLog) GetStacktraceLevel

func (m *MultiChannelledLog) GetStacktraceLevel() Level

GetStacktraceLevel gets the level of this MultiChannelledLog

func (*MultiChannelledLog) LogEvent

func (m *MultiChannelledLog) LogEvent(event *Event) error

LogEvent logs an event to this MultiChannelledLog

func (*MultiChannelledLog) Pause

func (m *MultiChannelledLog) Pause()

Pause pauses this Logger

func (*MultiChannelledLog) ReleaseReopen

func (m *MultiChannelledLog) ReleaseReopen() error

ReleaseReopen causes this logger to tell its subloggers to release and reopen

func (*MultiChannelledLog) ResetLevel

func (m *MultiChannelledLog) ResetLevel() Level

ResetLevel will reset the level of this MultiChannelledLog

func (*MultiChannelledLog) Resume

func (m *MultiChannelledLog) Resume()

Resume resumes this Logger

func (*MultiChannelledLog) Start

func (m *MultiChannelledLog) Start()

Start processing the MultiChannelledLog

type MultiChannelledLogger

type MultiChannelledLogger struct {
	LevelLoggerLogger
	*MultiChannelledLog
	// contains filtered or unexported fields
}

MultiChannelledLogger is default logger in the GitBundle application. it can contain several providers and log message into all providers.

func GetLogger

func GetLogger(name string) *MultiChannelledLogger

GetLogger returns either a named logger or the default logger

func NewLogger

func NewLogger(bufLen int64, name, provider, config string, noCaller bool) *MultiChannelledLogger

NewLogger create a logger for the default logger

func (*MultiChannelledLogger) DelLogger

func (l *MultiChannelledLogger) DelLogger(name string) (bool, error)

DelLogger deletes a sublogger from this logger.

func (*MultiChannelledLogger) Log

func (l *MultiChannelledLogger) Log(skip int, level Level, format string, v ...interface{}) error

Log msg at the provided level with the provided caller defined by skip (0 being the function that calls this function)

func (*MultiChannelledLogger) SendLog

func (l *MultiChannelledLogger) SendLog(level Level, caller, filename string, line int, msg, stack string) error

SendLog sends a log event at the provided level with the information given

func (*MultiChannelledLogger) SetLogger

func (l *MultiChannelledLogger) SetLogger(name, provider, config string) error

SetLogger sets new logger instance with given logger provider and config.

type MuxWriter

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

MuxWriter an *os.File writer with locker.

func (*MuxWriter) Close

func (mw *MuxWriter) Close() error

Close the internal writer

func (*MuxWriter) SetFd

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

SetFd sets os.File in writer.

func (*MuxWriter) Write

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

Write writes to os.File.

type SMTPLogger

type SMTPLogger struct {
	WriterLogger
	Username           string   `json:"Username"`
	Password           string   `json:"password"`
	Host               string   `json:"host"`
	Subject            string   `json:"subject"`
	RecipientAddresses []string `json:"sendTos"`
	// contains filtered or unexported fields
}

SMTPLogger implements LoggerProvider and is used to send emails via given SMTP-server.

func (*SMTPLogger) Content

func (log *SMTPLogger) Content() (string, error)

Content returns the content accumulated in the content provider

func (*SMTPLogger) Flush

func (log *SMTPLogger) Flush()

Flush when log should be flushed

func (*SMTPLogger) GetName

func (log *SMTPLogger) GetName() string

GetName returns the default name for this implementation

func (*SMTPLogger) Init

func (log *SMTPLogger) 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",
	"sendTos":["email1","email2"],
	"level":LevelError
}

func (*SMTPLogger) ReleaseReopen

func (log *SMTPLogger) ReleaseReopen() error

ReleaseReopen does nothing

type SettableLogger

type SettableLogger interface {
	SetLogger(name, provider, config string) error
	DelLogger(name string) (bool, error)
}

SettableLogger is the interface of loggers which have subloggers

type StacktraceLogger

type StacktraceLogger interface {
	GetStacktraceLevel() Level
}

StacktraceLogger is a logger that can log stacktraces

type WriterLogger

type WriterLogger struct {
	Level           Level  `json:"level"`
	StacktraceLevel Level  `json:"stacktraceLevel"`
	Flags           int    `json:"flags"`
	Prefix          string `json:"prefix"`
	Colorize        bool   `json:"colorize"`
	Expression      string `json:"expression"`
	// contains filtered or unexported fields
}

WriterLogger represent a basic logger for GitBundle

func (*WriterLogger) Close

func (logger *WriterLogger) Close()

Close the base logger

func (*WriterLogger) GetLevel

func (logger *WriterLogger) GetLevel() Level

GetLevel returns the logging level for this logger

func (*WriterLogger) GetName

func (logger *WriterLogger) GetName() string

GetName returns empty for these provider loggers

func (*WriterLogger) GetStacktraceLevel

func (logger *WriterLogger) GetStacktraceLevel() Level

GetStacktraceLevel returns the stacktrace logging level for this logger

func (*WriterLogger) LogEvent

func (logger *WriterLogger) LogEvent(event *Event) error

LogEvent logs the event to the internal writer

func (*WriterLogger) Match

func (logger *WriterLogger) Match(event *Event) bool

Match checks if the given event matches the logger's regexp expression

func (*WriterLogger) NewWriterLogger

func (logger *WriterLogger) NewWriterLogger(out io.WriteCloser, level ...Level)

NewWriterLogger creates a new WriterLogger from the provided WriteCloser. Optionally the level can be changed at the same time.

Jump to

Keyboard shortcuts

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