Documentation
ΒΆ
Overview ΒΆ
Package logger is an easy-to-use, super-fast and extendable logging package for Go
Index ΒΆ
- Constants
- func Data(stackLevel int, logLevel LogLevel, message string, args ...KeyValue)
- func Errorfmt(stackLevel int, format string, v ...interface{})
- func Errorln(stackLevel int, v ...interface{})
- func Fatal(v ...interface{})
- func Fatalf(format string, v ...interface{})
- func Fatalln(v ...interface{})
- func FileTag(level int) string
- func FileTagComponents(level int) []string
- func NoFileData(logLevel LogLevel, message string, args ...KeyValue)
- func NoFilePrintf(format string, v ...interface{})
- func NoFilePrintln(v ...interface{})
- func Panic(v ...interface{})
- func Panicf(format string, v ...interface{})
- func Panicln(v ...interface{})
- func Print(v ...interface{})
- func Printf(format string, v ...interface{})
- func Println(v ...interface{})
- func SetImplementation(impl Logger)
- type GormLogLevel
- type GormLoggerInterface
- type KeyValue
- type LogClient
- func (l *LogClient) Connect() error
- func (l *LogClient) Fatal(v ...interface{})
- func (l *LogClient) Fatalf(format string, v ...interface{})
- func (l *LogClient) Fatalln(v ...interface{})
- func (l *LogClient) Panic(v ...interface{})
- func (l *LogClient) Panicf(format string, v ...interface{})
- func (l *LogClient) Panicln(v ...interface{})
- func (l *LogClient) Print(v ...interface{})
- func (l *LogClient) Printf(format string, v ...interface{})
- func (l *LogClient) Println(v ...interface{})
- func (l *LogClient) ProcessQueue()
- type LogLevel
- type Logger
- type Parameter
Examples ΒΆ
Constants ΒΆ
const ( LogEntriesPort = "10000" // 80, 514, 443, 10000 LogEntriesTestEndpoint = "52.214.43.195" // This is an IP for now, since GitHub Actions fails on resolving the domains LogEntriesURL = "data.logentries.com" // "data.insight.rapid7.com" "eu.data.logs.insight.rapid7.com" MaxRetryDelay = 2 * time.Minute RetryDelay = 100 * time.Millisecond )
Package constants
const SlowQueryThreshold = 5 * time.Second
SlowQueryThreshold is the time cut-off for considering a query as "slow"
Variables ΒΆ
This section is empty.
Functions ΒΆ
func Data ΒΆ
Data will format the log message to a standardized log entries compatible format. stackLevel 2 will tag the log with the location from where Data is called. This will print using the implementation's Println function
func Errorfmt ΒΆ
Errorfmt is equivalent to Printf with a custom stack level, see Errorln for details
func Errorln ΒΆ
func Errorln(stackLevel int, v ...interface{})
Errorln is equivalent to Println() except the stack level can be set to generate the correct log tag. A stack level of 2 is will tag the log with the location from where Errorln is called, and is equivalent to Println. Larger numbers step further back in the stack
func Fatal ΒΆ added in v0.2.3
func Fatal(v ...interface{})
Fatal is equivalent to Print() followed by a call to os.Exit(1)
func Fatalf ΒΆ
func Fatalf(format string, v ...interface{})
Fatalf is equivalent to Printf() followed by a call to os.Exit(1)
func Fatalln ΒΆ
func Fatalln(v ...interface{})
Fatalln is equivalent to Println() followed by a call to os.Exit(1)
func FileTag ΒΆ
FileTag tag file
Example ΒΆ
ExampleFileTag example using FileTag()
// fileTag := FileTag(1) fileTag := "go-logger/logger_test.go:go-logger.ExampleFileTag:102" fmt.Println(fileTag)
Output: go-logger/logger_test.go:go-logger.ExampleFileTag:102
func FileTagComponents ΒΆ
FileTagComponents file tag components
Example ΒΆ
ExampleFileTagComponents example using FileTagComponents()
fileTag := FileTagComponents(1) fmt.Println(fileTag[0])
Output: go-logger/logger_test.go
func NoFileData ΒΆ added in v0.1.3
NoFileData will format the log message to a standardized log entries compatible format. This will print using the implementation's Println function
func NoFilePrintf ΒΆ added in v0.1.3
func NoFilePrintf(format string, v ...interface{})
NoFilePrintf calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Printf.
func NoFilePrintln ΒΆ added in v0.1.3
func NoFilePrintln(v ...interface{})
NoFilePrintln calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Println.
func Panic ΒΆ added in v0.2.3
func Panic(v ...interface{})
Panic is equivalent to Print() followed by a call to os.Exit(1)
func Panicf ΒΆ added in v0.2.3
func Panicf(format string, v ...interface{})
Panicf is equivalent to Printf() followed by a call to os.Exit(1)
func Panicln ΒΆ added in v0.2.3
func Panicln(v ...interface{})
Panicln is equivalent to Println() followed by a call to os.Exit(1)
func Print ΒΆ added in v0.2.3
func Print(v ...interface{})
Print calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Print.
func Printf ΒΆ
func Printf(format string, v ...interface{})
Printf calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Printf.
func Println ΒΆ
func Println(v ...interface{})
Println calls Output to print to the connected logger. Arguments are handled in the manner of fmt.Println.
func SetImplementation ΒΆ
func SetImplementation(impl Logger)
SetImplementation allows the log implementation to be swapped at runtime
Types ΒΆ
type GormLogLevel ΒΆ added in v0.3.0
type GormLogLevel int
GormLogLevel is the GORM log level
const ( // Silent silent log level Silent GormLogLevel = iota + 1 // Error error log level Error // Warn warn log level Warn // Info info log level Info )
type GormLoggerInterface ΒΆ added in v0.3.0
type GormLoggerInterface interface {
Error(ctx context.Context, s string, v ...interface{})
GetMode() GormLogLevel
GetStackLevel() int
Info(ctx context.Context, s string, v ...interface{})
SetMode(gl GormLogLevel) GormLoggerInterface
SetStackLevel(level int)
Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)
Warn(ctx context.Context, s string, v ...interface{})
}
GormLoggerInterface is a logger interface to help work with GORM
func NewGormLogger ΒΆ added in v0.3.0
func NewGormLogger(debugging bool, stackLevel int) GormLoggerInterface
NewGormLogger will return a basic logger interface
type KeyValue ΒΆ
type KeyValue interface {
Key() string
Value() interface{}
}
KeyValue key value for errors
type LogClient ΒΆ added in v0.1.4
type LogClient struct {
// contains filtered or unexported fields
}
LogClient configuration
func NewLogEntriesClient ΒΆ
NewLogEntriesClient new client
func (*LogClient) Fatal ΒΆ added in v0.2.3
func (l *LogClient) Fatal(v ...interface{})
Fatal overloads built-in method
func (*LogClient) Fatalln ΒΆ added in v0.1.4
func (l *LogClient) Fatalln(v ...interface{})
Fatalln overloads built-in method
func (*LogClient) Panic ΒΆ added in v0.2.3
func (l *LogClient) Panic(v ...interface{})
Panic overloads built-in method
func (*LogClient) Panicln ΒΆ added in v0.2.3
func (l *LogClient) Panicln(v ...interface{})
Panicln overloads built-in method
func (*LogClient) Print ΒΆ added in v0.2.3
func (l *LogClient) Print(v ...interface{})
Print overloads built-in method
func (*LogClient) Println ΒΆ added in v0.1.4
func (l *LogClient) Println(v ...interface{})
Println overloads built-in method
func (*LogClient) ProcessQueue ΒΆ added in v0.1.4
func (l *LogClient) ProcessQueue()
ProcessQueue process the queue
type Logger ΒΆ
type Logger interface {
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Fatalln(v ...interface{})
Panic(v ...interface{})
Panicf(s string, v ...interface{})
Panicln(v ...interface{})
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
}
Logger interface describes the functionality that a log service must implement
func GetImplementation ΒΆ added in v0.2.3
func GetImplementation() Logger
GetImplementation gets the current logger implementation
type Parameter ΒΆ added in v0.0.2
type Parameter struct {
K string `json:"key"`
V interface{} `json:"value"`
}
Parameter is a standardized parameter struct for logger.Data()
func MakeParameter ΒΆ added in v0.0.2
MakeParameter creates a new Parameter (key/value)
