import "code.gitea.io/gitea/modules/log"
colors.go colors_router.go conn.go console.go errors.go event.go file.go flags.go level.go log.go logger.go multichannel.go provider.go smtp.go stack.go writer.go
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
var ( // DEFAULT is the name of the default logger DEFAULT = "default" // NamedLoggers map of named loggers NamedLoggers loggerMap )
CanColorStderr reports if we can color the Stderr
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
func Close()
Close closes all the loggers
func ColorBytes(attrs ...ColorAttribute) []byte
ColorBytes converts a list of ColorAttributes to a byte array
ColorFprintf will write to the provided writer similar to ColorSprintf
ColorSprintf returns a colored string from a format and arguments arguments will be wrapped in ColoredValues to protect against color spoofing
func ColorString(attrs ...ColorAttribute) string
ColorString converts a list of ColorAttributes to a color string
Critical records critical log
CriticalWithSkip records critical log from "skip" calls back from this function
Debug records debug log
DelLogger removes the named sublogger from the default logger
DelNamedLogger closes and deletes the named logger
Error records error log
ErrorWithSkip records error log from "skip" calls back from this function
Fatal records fatal log and exit process
FatalWithSkip records fatal log from "skip" calls back from this function
FlagsFromString takes a comma separated list of flags and returns the flags for this string
Info records info log
IsCritical returns true if at least one logger is CRITICAL
IsDebug returns true if at least one logger is DEBUG
IsErrDuplicateName checks if an error is a ErrDuplicateName.
IsErrTimeout checks if an error is a ErrTimeout.
IsErrUnknownProvider checks if an error is a ErrUnknownProvider.
IsError returns true if at least one logger is ERROR
IsFatal returns true if at least one logger is FATAL
IsInfo returns true if at least one logger is INFO
IsTrace returns true if at least one logger is TRACE
IsWarn returns true if at least one logger is WARN
Levels returns all the possible logging levels
Log a message with defined skip and at logging level A skip of 0 refers to the caller of this command
NewNamedLogger creates a new named logger for a given configuration
func Pause()
Pause pauses all the loggers
Register registers given logger provider to providers.
ReleaseReopen releases and reopens logging files
func Resume()
Resume resumes all the loggers
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...
Trace records trace log
Warn records warning log
type ChannelledLog struct {
// contains filtered or unexported fields
}
ChannelledLog represents a cached channel to a LoggerProvider
func NewChannelledLog(name, provider, config string, bufferLength int64) (*ChannelledLog, error)
NewChannelledLog a new logger instance with given logger provider and config.
func (l *ChannelledLog) Close()
Close this ChannelledLog
func (l *ChannelledLog) Flush()
Flush this ChannelledLog
func (l *ChannelledLog) GetLevel() Level
GetLevel gets the level of this ChannelledLog
func (l *ChannelledLog) GetName() string
GetName returns the name of this ChannelledLog
func (l *ChannelledLog) GetStacktraceLevel() Level
GetStacktraceLevel gets the level of this ChannelledLog
func (l *ChannelledLog) LogEvent(event *Event) error
LogEvent logs an event to this ChannelledLog
func (l *ChannelledLog) ReleaseReopen() error
ReleaseReopen this ChannelledLog
func (l *ChannelledLog) Start()
Start processing the ChannelledLog
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(from string) ColorAttribute
ColorAttributeFromString will return a ColorAttribute given a string
func (c *ColorAttribute) String() string
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 struct { Value *interface{} // contains filtered or unexported fields }
ColoredValue will Color the provided value
func ColoredMethod(method string) *ColoredValue
ColoredMethod addes colors for HtTP methos on log
func ColoredStatus(status int, s ...string) *ColoredValue
ColoredStatus addes colors for HTTP status
func ColoredTime(duration time.Duration) *ColoredValue
ColoredTime addes colors for time on log
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(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(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(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 (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 (cv *ColoredValue) SetColorBytes(colorBytes []byte)
SetColorBytes will allow a user to set the colorBytes of a colored value
func (cv *ColoredValue) SetColorBytesPointer(colorBytes *[]byte)
SetColorBytesPointer will allow a user to set the colorBytes pointer of a colored value
func (cv *ColoredValue) SetResetBytes(resetBytes []byte)
SetResetBytes will allow a user to set the resetBytes pointer of a colored value
func (cv *ColoredValue) SetResetBytesPointer(resetBytes *[]byte)
SetResetBytesPointer will allow a user to set the resetBytes pointer of a colored value
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 (log *ConnLogger) Flush()
Flush does nothing for this implementation
func (log *ConnLogger) GetName() string
GetName returns the default name for this implementation
func (log *ConnLogger) Init(jsonconfig string) error
Init inits connection writer with json config. json config only need key "level".
func (log *ConnLogger) ReleaseReopen() error
ReleaseReopen causes the ConnLogger to reconnect to the server
type ConsoleLogger struct { WriterLogger Stderr bool `json:"stderr"` }
ConsoleLogger implements LoggerProvider and writes messages to terminal.
func (log *ConsoleLogger) Flush()
Flush when log should be flushed
func (log *ConsoleLogger) GetName() string
GetName returns the default name for this implementation
func (log *ConsoleLogger) Init(config string) error
Init inits connection writer with json config. json config only need key "level".
func (log *ConsoleLogger) ReleaseReopen() error
ReleaseReopen causes the console logger to reconnect to os.Stdout
ErrDuplicateName represents a Duplicate Name error
func (err ErrDuplicateName) Error() string
ErrTimeout represents a "Timeout" kind of error.
func (err ErrTimeout) Error() string
ErrUnknownProvider represents a "Unknown Provider" kind of error.
func (err ErrUnknownProvider) Error() string
type Event struct {
// contains filtered or unexported fields
}
Event represents a logging event
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 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 (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 (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 (log *FileLogger) GetName() string
GetName returns the default name for this implementation
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 (log *FileLogger) ReleaseReopen() error
ReleaseReopen releases and reopens log files
func (log *FileLogger) StartLogger() error
StartLogger start file logger. create log file and set to locker-inside file writer.
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 )
FromString takes a level string and returns a Level
GetLevel returns the minimum logger level
GetStacktraceLevel returns the minimum logger level
Color returns the color string for this Level
MarshalJSON takes a Level and turns it into text
UnmarshalJSON takes text and turns it into a Level
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 struct { LevelLogger }
LevelLoggerLogger wraps a LevelLogger as a Logger
func (l *LevelLoggerLogger) Critical(format string, v ...interface{})
Critical records critical log
func (l *LevelLoggerLogger) CriticalWithSkip(skip int, format string, v ...interface{})
CriticalWithSkip records critical log from "skip" calls back from this function
func (l *LevelLoggerLogger) Debug(format string, v ...interface{})
Debug records debug log
func (l *LevelLoggerLogger) Error(format string, v ...interface{})
Error records error log
func (l *LevelLoggerLogger) ErrorWithSkip(skip int, format string, v ...interface{})
ErrorWithSkip records error log from "skip" calls back from this function
func (l *LevelLoggerLogger) Fatal(format string, v ...interface{})
Fatal records fatal log and exit the process
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 (l *LevelLoggerLogger) Info(format string, v ...interface{})
Info records information log
func (l *LevelLoggerLogger) IsCritical() bool
IsCritical returns true if the logger is CRITICAL
func (l *LevelLoggerLogger) IsDebug() bool
IsDebug returns true if the logger is DEBUG
func (l *LevelLoggerLogger) IsError() bool
IsError returns true if the logger is ERROR
func (l *LevelLoggerLogger) IsFatal() bool
IsFatal returns true if the logger is FATAL
func (l *LevelLoggerLogger) IsInfo() bool
IsInfo returns true if the logger is INFO
func (l *LevelLoggerLogger) IsTrace() bool
IsTrace returns true if the logger is TRACE
func (l *LevelLoggerLogger) IsWarn() bool
IsWarn returns true if the logger is WARN
func (l *LevelLoggerLogger) Trace(format string, v ...interface{})
Trace records trace log
func (l *LevelLoggerLogger) Warn(format string, v ...interface{})
Warn records warning log
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 struct {
// contains filtered or unexported fields
}
LoggerAsWriter is a io.Writer shim around the gitea log
func NewLoggerAsWriter(level string, ourLoggers ...*MultiChannelledLogger) *LoggerAsWriter
NewLoggerAsWriter creates a Writer representation of the logger with setable log level
func (l *LoggerAsWriter) Log(msg string)
Log takes a given string and logs it at the set log-level
func (l *LoggerAsWriter) Write(p []byte) (int, error)
Write implements the io.Writer interface to allow spoofing of macaron
type LoggerProvider interface { Init(config string) error EventLogger }
LoggerProvider represents behaviors of a logger provider.
func NewConn() LoggerProvider
NewConn creates new ConnLogger returning as LoggerProvider.
func NewConsoleLogger() LoggerProvider
NewConsoleLogger create ConsoleLogger returning as LoggerProvider.
func NewFileLogger() LoggerProvider
NewFileLogger create a FileLogger returning as LoggerProvider.
func NewSMTPLogger() LoggerProvider
NewSMTPLogger creates smtp writer.
type MultiChannelledLog struct {
// contains filtered or unexported fields
}
MultiChannelledLog represents a cached channel to a LoggerProvider
func NewMultiChannelledLog(name string, bufferLength int64) *MultiChannelledLog
NewMultiChannelledLog a new logger instance with given logger provider and config.
func (m *MultiChannelledLog) AddLogger(logger EventLogger) error
AddLogger adds a logger to this MultiChannelledLog
func (m *MultiChannelledLog) Close()
Close this MultiChannelledLog
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 (m *MultiChannelledLog) Flush()
Flush this ChannelledLog
func (m *MultiChannelledLog) GetEventLogger(name string) EventLogger
GetEventLogger returns a sub logger from this MultiChannelledLog
func (m *MultiChannelledLog) GetEventLoggerNames() []string
GetEventLoggerNames returns a list of names
func (m *MultiChannelledLog) GetLevel() Level
GetLevel gets the level of this MultiChannelledLog
func (m *MultiChannelledLog) GetName() string
GetName gets the name of this MultiChannelledLog
func (m *MultiChannelledLog) GetStacktraceLevel() Level
GetStacktraceLevel gets the level of this MultiChannelledLog
func (m *MultiChannelledLog) LogEvent(event *Event) error
LogEvent logs an event to this MultiChannelledLog
func (m *MultiChannelledLog) Pause()
Pause pauses this Logger
func (m *MultiChannelledLog) ReleaseReopen() error
ReleaseReopen causes this logger to tell its subloggers to release and reopen
func (m *MultiChannelledLog) ResetLevel() Level
ResetLevel will reset the level of this MultiChannelledLog
func (m *MultiChannelledLog) Resume()
Resume resumes this Logger
func (m *MultiChannelledLog) Start()
Start processing the MultiChannelledLog
type MultiChannelledLogger struct { LevelLoggerLogger *MultiChannelledLog // contains filtered or unexported fields }
MultiChannelledLogger is default logger in the Gitea application. it can contain several providers and log message into all providers.
func GetLogger(name string) *MultiChannelledLogger
GetLogger returns either a named logger or the default logger
func NewLogger(bufLen int64, name, provider, config string) *MultiChannelledLogger
NewLogger create a logger for the default logger
func (l *MultiChannelledLogger) DelLogger(name string) (bool, error)
DelLogger deletes a sublogger from this logger.
Log msg at the provided level with the provided caller defined by skip (0 being the function that calls this function)
func (l *MultiChannelledLogger) SendLog(level Level, caller, filename string, line int, msg string, stack string) error
SendLog sends a log event at the provided level with the information given
func (l *MultiChannelledLogger) SetLogger(name, provider, config string) error
SetLogger sets new logger instance with given logger provider and config.
type MuxWriter struct {
// contains filtered or unexported fields
}
MuxWriter an *os.File writer with locker.
Close the internal writer
SetFd sets os.File in writer.
Write writes to os.File.
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 (log *SMTPLogger) Flush()
Flush when log should be flushed
func (log *SMTPLogger) GetName() string
GetName returns the default name for this implementation
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 (log *SMTPLogger) ReleaseReopen() error
ReleaseReopen does nothing
type SettableLogger interface { SetLogger(name, provider, config string) error DelLogger(name string) (bool, error) }
SettableLogger is the interface of loggers which have subloggers
StacktraceLogger is a logger that can log stacktraces
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 Gitea
func (logger *WriterLogger) Close()
Close the base logger
func (logger *WriterLogger) GetLevel() Level
GetLevel returns the logging level for this logger
func (logger *WriterLogger) GetName() string
GetName returns empty for these provider loggers
func (logger *WriterLogger) GetStacktraceLevel() Level
GetStacktraceLevel returns the stacktrace logging level for this logger
func (logger *WriterLogger) LogEvent(event *Event) error
LogEvent logs the event to the internal writer
func (logger *WriterLogger) Match(event *Event) bool
Match checks if the given event matches the logger's regexp expression
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.
Package log imports 20 packages (graph) and is imported by 870 packages. Updated 2021-01-22. Refresh now. Tools for package owners.