Documentation
¶
Overview ¶
Package log provides a singular interface to create logs as well as filtering them out based on level. It also provides two types of formatting; json or pretty. The logger doesn't ship any logs.
Index ¶
- Variables
- func Debugd(output string, d interface{})
- func Debugf(format string, a ...interface{})
- func Debugln(output string)
- func Errord(output string, d interface{})
- func Errorf(format string, a ...interface{})
- func Errorln(output string)
- func Fatald(output string, d interface{})
- func Fatalf(format string, a ...interface{})
- func Fatalln(output string)
- func Infod(output string, d interface{})
- func Infof(format string, a ...interface{})
- func Infoln(output string)
- func Logd(level Level, output string, d interface{})
- func Logf(level Level, format string, a ...interface{})
- func Logln(level Level, output string)
- func Recover(in string, err *error)
- func SetupCloudLogger(level Level, tags []string)
- func SetupLocalLogger(level Level)
- func SetupLogger(level Level, format Format, timeFormat TimeFormat, colorizeOutput bool, ...)
- func Stdd(output string, d interface{})
- func Stdf(format string, a ...interface{})
- func Stdln(output string)
- func Traced(output string, d interface{})
- func Tracef(format string, a ...interface{})
- func Traceln(output string)
- func Warnd(output string, d interface{})
- func Warnf(format string, a ...interface{})
- func Warnln(output string)
- type Format
- type Level
- type Logger
- type RequestLogger
- type RequestLoggerConfig
- type TimeFormat
Constants ¶
This section is empty.
Variables ¶
var LoggerSingleton *logger
LoggerSingleton is the main logging instance.
Functions ¶
func Fatalln ¶
func Fatalln(output string)
Fatalln prints the output followed by a newline and calls os.Exit(1).
func Recover ¶ added in v1.2.1
Recover recovers from a panic to keep from crashing the application and logs the problem as an error. The error argument can be used to set an error to be returned by the calling function.
func SetupCloudLogger ¶
SetupCloudLogger is a convenience function for calling SetupLogger with JSON formatted logs, non-colorized output and the given tags.
func SetupLocalLogger ¶
func SetupLocalLogger(level Level)
SetupLocalLogger is a convenience function for calling SetupLogger with pretty formatted logs, colorized output and no tags.
func SetupLogger ¶
func SetupLogger(level Level, format Format, timeFormat TimeFormat, colorizeOutput bool, logCaller bool, tags []string)
SetupLogger creates a new logger.
Types ¶
type Level ¶
type Level int
Level defined the type for a log level.
const ( // LogLevelTrace trace log level LogLevelTrace Level // LogLevelDebug debug log level. LogLevelDebug // LogLevelInfo info log level. LogLevelInfo // LogLevelWarn warn log level. LogLevelWarn // LogLevelError error log level. LogLevelError // LogLevelFatal fatal log level. LogLevelFatal )
type Logger ¶
type Logger interface {
// Base log
Logln(Level, string)
Logf(Level, string, ...interface{})
Logd(Level, string, interface{})
// Trace
Traceln(string)
Tracef(string, ...interface{})
Traced(string, interface{})
// Debug
Debugln(string)
Debugf(string, ...interface{})
Debugd(string, interface{})
// Info
Infoln(string)
Infof(string, ...interface{})
Infod(string, interface{})
// Warn
Warnln(string)
Warnf(string, ...interface{})
Warnd(string, interface{})
// Error
Errorln(string)
Errorf(string, ...interface{})
Errord(string, interface{})
// Fatal
Fatalln(string)
Fatalf(string, ...interface{})
Fatald(string, interface{})
// Create a logger object with additional tags
Sublogger(tags ...string) Logger
// contains filtered or unexported methods
}
type RequestLogger ¶
type RequestLogger struct {
// contains filtered or unexported fields
}
RequestLogger is a configured struct with an HTTP Handler method for logging HTTP requests
func NewRequestLogger ¶
func NewRequestLogger(config RequestLoggerConfig) *RequestLogger
NewRequestLogger returns a configured RequestLogger
func (*RequestLogger) Handle ¶
func (rl *RequestLogger) Handle(next http.Handler) http.Handler
Handle logs incoming HTTP requests, calls the next handler, and logs uncaught errors in the handler chain
func (*RequestLogger) RoundTripper ¶ added in v1.4.0
func (rl *RequestLogger) RoundTripper(client *http.Client) http.RoundTripper
type RequestLoggerConfig ¶
type RequestLoggerConfig struct {
Logger Logger
Client *http.Client
Headers bool
Params bool
GraphQL bool
Body bool
Tags []string
// NormalLevel is the log level to use for requests without context errors
NormalLevel Level
// DeadlineExceededLevel is the log level to use for requests that time out
DeadlineExceededLevel Level
// ContextCancelledLevel is the log level to use for requests that are
// cancelled for reasons other than a timeout
ContextCancelledLevel Level
// ContextErrorLevel is the log level to use for requests that have an other
// context error
ContextErrorLevel Level
}
RequestLoggerConfig defines options for which details should be logged
type TimeFormat ¶ added in v1.3.0
type TimeFormat string
const (
TimeFormatLoggly TimeFormat = "loggly"
)

