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