Documentation ¶
Index ¶
- Constants
- Variables
- func Close()
- func ColorBytes(attrs ...ColorAttribute) []byte
- func ColorFprintf(w io.Writer, format string, args ...interface{}) (int, error)
- func ColorSprintf(format string, args ...interface{}) string
- func ColorString(attrs ...ColorAttribute) string
- func Critical(format string, v ...interface{})
- func CriticalWithSkip(skip int, format string, v ...interface{})
- func Debug(format string, v ...interface{})
- func DelLogger(name string) error
- func DelNamedLogger(name string)
- func Error(format string, v ...interface{})
- func ErrorWithSkip(skip int, format string, v ...interface{})
- func Fatal(format string, v ...interface{})
- func FatalWithSkip(skip int, format string, v ...interface{})
- func FlagsFromString(from string) int
- func Info(format string, v ...interface{})
- func IsCritical() bool
- func IsDebug() bool
- func IsErrDuplicateName(err error) bool
- func IsErrTimeout(err error) bool
- func IsErrUnknownProvider(err error) bool
- func IsError() bool
- func IsFatal() bool
- func IsInfo() bool
- func IsTrace() bool
- func IsWarn() bool
- func Levels() []string
- func Log(skip int, level Level, format string, v ...interface{})
- func NewNamedLogger(name string, bufLen int64, subname, provider, config string, noCaller bool) error
- func NewSimpleLogger(logBufferLength int64, mode, level, stacktraceLevel, logPath string, ...)
- func Pause()
- func Register(name string, log loggerProvider)
- func ReleaseReopen() error
- func Resume()
- func Stack(skip int) string
- func Trace(format string, v ...interface{})
- func Warn(format string, v ...interface{})
- type BufferLogger
- type ChannelledLog
- func (l *ChannelledLog) Close()
- func (l *ChannelledLog) Flush()
- func (l *ChannelledLog) GetLevel() Level
- func (l *ChannelledLog) GetName() string
- func (l *ChannelledLog) GetStacktraceLevel() Level
- func (l *ChannelledLog) LogEvent(event *Event) error
- func (l *ChannelledLog) ReleaseReopen() error
- func (l *ChannelledLog) Start()
- type ColorAttribute
- type ColorFormatted
- type ColoredValue
- func ColoredMethod(method string) *ColoredValue
- func ColoredStatus(status int, s ...string) *ColoredValue
- func ColoredTime(duration time.Duration) *ColoredValue
- func NewColoredIDValue(value interface{}) *ColoredValue
- func NewColoredValue(value interface{}, color ...ColorAttribute) *ColoredValue
- func NewColoredValueBytes(value interface{}, colorBytes *[]byte) *ColoredValue
- func NewColoredValuePointer(value *interface{}, color ...ColorAttribute) *ColoredValue
- type ConnLogger
- type ConsoleLogger
- type Entry
- func (e *Entry) Critical(format string, v ...interface{})
- func (e *Entry) Debug(format string, v ...interface{})
- func (e *Entry) Error(format string, v ...interface{})
- func (e *Entry) Fatal(format string, v ...interface{})
- func (e *Entry) Info(format string, v ...interface{})
- func (e *Entry) Trace(format string, v ...interface{})
- func (e *Entry) Warn(format string, v ...interface{})
- func (e *Entry) WithError(err error) *Entry
- func (e *Entry) WithField(key string, value interface{}) *Entry
- func (e *Entry) WithFields(fields Fields) *Entry
- type ErrDuplicateName
- type ErrTimeout
- type ErrUnknownProvider
- type Event
- type EventLogger
- type Fields
- type FileLogger
- type Level
- type LevelLogger
- type LevelLoggerLogger
- func (l *LevelLoggerLogger) Critical(format string, v ...interface{})
- func (l *LevelLoggerLogger) CriticalWithSkip(skip int, format string, v ...interface{})
- func (l *LevelLoggerLogger) Debug(format string, v ...interface{})
- func (l *LevelLoggerLogger) Error(format string, v ...interface{})
- func (l *LevelLoggerLogger) ErrorWithSkip(skip int, format string, v ...interface{})
- func (l *LevelLoggerLogger) Fatal(format string, v ...interface{})
- func (l *LevelLoggerLogger) FatalWithSkip(skip int, format string, v ...interface{})
- func (l *LevelLoggerLogger) Info(format string, v ...interface{})
- func (l *LevelLoggerLogger) IsCritical() bool
- func (l *LevelLoggerLogger) IsDebug() bool
- func (l *LevelLoggerLogger) IsError() bool
- func (l *LevelLoggerLogger) IsFatal() bool
- func (l *LevelLoggerLogger) IsInfo() bool
- func (l *LevelLoggerLogger) IsTrace() bool
- func (l *LevelLoggerLogger) IsWarn() bool
- func (l *LevelLoggerLogger) Trace(format string, v ...interface{})
- func (l *LevelLoggerLogger) Warn(format string, v ...interface{})
- type Logger
- type LoggerAsWriter
- type LoggerProvider
- type MultiChannelledLog
- func (m *MultiChannelledLog) AddLogger(logger EventLogger) error
- func (m *MultiChannelledLog) Close()
- func (m *MultiChannelledLog) DelLogger(name string) bool
- func (m *MultiChannelledLog) Flush()
- func (m *MultiChannelledLog) GetEventLogger(name string) EventLogger
- func (m *MultiChannelledLog) GetEventLoggerNames() []string
- func (m *MultiChannelledLog) GetLevel() Level
- func (m *MultiChannelledLog) GetLoggerProviderContent(name string) (string, error)
- func (m *MultiChannelledLog) GetName() string
- func (m *MultiChannelledLog) GetStacktraceLevel() Level
- func (m *MultiChannelledLog) LogEvent(event *Event) error
- func (m *MultiChannelledLog) Pause()
- func (m *MultiChannelledLog) ReleaseReopen() error
- func (m *MultiChannelledLog) ResetLevel() Level
- func (m *MultiChannelledLog) Resume()
- func (m *MultiChannelledLog) Start()
- type MultiChannelledLogger
- func (l *MultiChannelledLogger) DelLogger(name string) (bool, error)
- func (l *MultiChannelledLogger) Log(skip int, level Level, format string, v ...interface{}) error
- func (l *MultiChannelledLogger) SendLog(level Level, caller, filename string, line int, msg, stack string) error
- func (l *MultiChannelledLogger) SetLogger(name, provider, config string) error
- type MuxWriter
- type SMTPLogger
- type SettableLogger
- type StacktraceLogger
- type WriterLogger
- func (logger *WriterLogger) Close()
- func (logger *WriterLogger) GetLevel() Level
- func (logger *WriterLogger) GetName() string
- func (logger *WriterLogger) GetStacktraceLevel() Level
- func (logger *WriterLogger) LogEvent(event *Event) error
- func (logger *WriterLogger) Match(event *Event) bool
- func (logger *WriterLogger) NewWriterLogger(out io.WriteCloser, level ...Level)
Constants ¶
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 ¶
var ( // DEFAULT is the name of the default logger DEFAULT = "default" // NamedLoggers map of named loggers NamedLoggers loggerMap )
var CanColorStderr = true
CanColorStderr reports if we can color the Stderr
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 ColorBytes ¶
func ColorBytes(attrs ...ColorAttribute) []byte
ColorBytes converts a list of ColorAttributes to a byte array
func ColorFprintf ¶
ColorFprintf will write to the provided writer similar to ColorSprintf
func ColorSprintf ¶
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 CriticalWithSkip ¶
CriticalWithSkip records critical log from "skip" calls back from this function
func DelNamedLogger ¶
func DelNamedLogger(name string)
DelNamedLogger closes and deletes the named logger
func ErrorWithSkip ¶
ErrorWithSkip records error log from "skip" calls back from this function
func FatalWithSkip ¶
FatalWithSkip records fatal log from "skip" calls back from this function
func FlagsFromString ¶
FlagsFromString takes a comma separated list of flags and returns the flags for this string
func IsErrDuplicateName ¶
IsErrDuplicateName checks if an error is a ErrDuplicateName.
func IsErrTimeout ¶
IsErrTimeout checks if an error is a ErrTimeout.
func IsErrUnknownProvider ¶
IsErrUnknownProvider checks if an error is a ErrUnknownProvider.
func Log ¶
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 Register ¶
func Register(name string, log loggerProvider)
Register registers given logger provider to providers.
func Stack ¶
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...
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) 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) 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
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) 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 WithFields ¶
func (*Entry) WithFields ¶
type ErrDuplicateName ¶
type ErrDuplicateName struct {
Name string
}
ErrDuplicateName represents a Duplicate Name error
func (ErrDuplicateName) Error ¶
func (err ErrDuplicateName) Error() string
type ErrTimeout ¶
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 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 ¶
FromString takes a level string and returns a Level
func GetStacktraceLevel ¶
func GetStacktraceLevel() Level
GetStacktraceLevel returns the minimum logger level
func (Level) MarshalJSON ¶
MarshalJSON takes a Level and turns it into text
func (*Level) UnmarshalJSON ¶
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
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.
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) 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) 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.
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) 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) 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.