Documentation ¶
Index ¶
- Variables
- func Debug(msg string)
- func Debugf(msg string, v ...interface{})
- func DecreasePadding()
- func Error(msg string)
- func Errorf(msg string, v ...interface{})
- func Fatal(msg string)
- func Fatalf(msg string, v ...interface{})
- func IncreasePadding()
- func Info(msg string)
- func Infof(msg string, v ...interface{})
- func NewContext(ctx context.Context, v Interface) context.Context
- func ResetPadding()
- func SetLevel(l Level)
- func SetLevelFromString(s string)
- func Trace(msg string)
- func Tracef(msg string, v ...interface{})
- func Warn(msg string)
- func Warnf(msg string, v ...interface{})
- type Entry
- func (e *Entry) Debug(msg string)
- func (e *Entry) Debugf(msg string, v ...interface{})
- func (e *Entry) DecreasePadding()
- func (e *Entry) Error(msg string)
- func (e *Entry) Errorf(msg string, v ...interface{})
- func (e *Entry) Fatal(msg string)
- func (e *Entry) Fatalf(msg string, v ...interface{})
- func (e *Entry) IncreasePadding()
- func (e *Entry) Info(msg string)
- func (e *Entry) Infof(msg string, v ...interface{})
- func (e *Entry) ResetPadding()
- func (e *Entry) Trace(msg string)
- func (e *Entry) Tracef(msg string, v ...interface{})
- func (e *Entry) Warn(msg string)
- func (e *Entry) Warnf(msg string, v ...interface{})
- func (e *Entry) WithError(err error) *Entry
- func (e *Entry) WithField(key string, value interface{}) *Entry
- func (e *Entry) WithFields(fields Fielder) *Entry
- func (e *Entry) WithoutPadding() *Entry
- type Fielder
- type Fields
- type Interface
- type Level
- type Logger
- func (l *Logger) Debug(msg string)
- func (l *Logger) Debugf(msg string, v ...interface{})
- func (l *Logger) DecreasePadding()
- func (l *Logger) Error(msg string)
- func (l *Logger) Errorf(msg string, v ...interface{})
- func (l *Logger) Fatal(msg string)
- func (l *Logger) Fatalf(msg string, v ...interface{})
- func (l *Logger) IncreasePadding()
- func (l *Logger) Info(msg string)
- func (l *Logger) Infof(msg string, v ...interface{})
- func (l *Logger) ResetPadding()
- func (l *Logger) Trace(msg string)
- func (l *Logger) Tracef(msg string, v ...interface{})
- func (l *Logger) Warn(msg string)
- func (l *Logger) Warnf(msg string, v ...interface{})
- func (l *Logger) WithError(err error) *Entry
- func (l *Logger) WithField(key string, value interface{}) *Entry
- func (l *Logger) WithFields(fields Fielder) *Entry
- func (l *Logger) WithoutPadding() *Entry
Constants ¶
This section is empty.
Variables ¶
var ( DefaultTier int = 0 TierPadding int = 2 ErrorKey = "error" // how far into the line should keypairs be placed KeyPairPosition = 50 )
var ErrInvalidLevel = errors.New("invalid level")
ErrInvalidLevel is returned if the severity level is invalid.
var Now = time.Now
Now returns the current time.
var Strings = [...]string{
FatalLevel: "⨯",
ErrorLevel: "⨯",
WarnLevel: "•",
InfoLevel: "•",
DebugLevel: "•",
TraceLevel: "?",
}
Strings mapping.
var Styles = [...]lipgloss.Style{ FatalLevel: lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true), ErrorLevel: lipgloss.NewStyle().Foreground(lipgloss.Color("9")).Bold(true), WarnLevel: lipgloss.NewStyle().Foreground(lipgloss.Color("11")).Bold(true), InfoLevel: lipgloss.NewStyle().Foreground(lipgloss.Color("12")).Bold(true), DebugLevel: lipgloss.NewStyle().Foreground(lipgloss.Color("15")).Bold(true), TraceLevel: lipgloss.NewStyle().Foreground(lipgloss.Color("8")).Bold(false), }
Styles mapping.
Functions ¶
func Fatalf ¶
func Fatalf(msg string, v ...interface{})
Fatalf level formatted message, followed by an exit.
func NewContext ¶
NewContext returns a new context with logger.
func SetLevelFromString ¶
func SetLevelFromString(s string)
SetLevelFromString sets the log level from a string, panicing when invalid. This is not thread-safe.
Types ¶
type Entry ¶
type Entry struct { Logger *Logger `json:"-"` Fields Fields `json:"fields"` Level Level `json:"level"` Message string `json:"message"` Tier int // contains filtered or unexported fields }
Entry represents a single log entry.
func WithFields ¶
WithFields returns a new entry with `fields` set.
func WithoutPadding ¶
func WithoutPadding() *Entry
WithoutPadding returns a new entry with padding set to default.
func (*Entry) DecreasePadding ¶
func (e *Entry) DecreasePadding()
DecreasePadding decreases the padding 1 times.
func (*Entry) IncreasePadding ¶
func (e *Entry) IncreasePadding()
IncreasePadding increases the padding 1 times.
func (*Entry) ResetPadding ¶
func (e *Entry) ResetPadding()
ResetPadding resets the padding to default.
func (*Entry) WithError ¶
WithError returns a new entry with the "error" set to `err`.
The given error may implement .Fielder, if it does the method will add all its `.Fields()` into the returned entry.
func (*Entry) WithFields ¶
WithFields returns a new entry with `fields` set.
func (*Entry) WithoutPadding ¶
WithoutPadding returns a new entry with padding set to default.
type Fielder ¶
type Fielder interface {
Fields() Fields
}
Fielder is an interface for providing fields to custom types.
type Fields ¶
type Fields map[string]interface{}
Fields represents a map of entry level data used for structured logging.
type Interface ¶
type Interface interface { WithFields(Fielder) *Entry WithField(string, interface{}) *Entry WithError(error) *Entry WithoutPadding() *Entry Trace(string) Debug(string) Info(string) Warn(string) Error(string) Fatal(string) Tracef(string, ...interface{}) Debugf(string, ...interface{}) Infof(string, ...interface{}) Warnf(string, ...interface{}) Errorf(string, ...interface{}) Fatalf(string, ...interface{}) ResetPadding() IncreasePadding() DecreasePadding() }
Interface represents the API of both Logger and Entry.
func FromContext ¶
FromContext returns the logger from context, or log.Log.
type Level ¶
type Level int8
Level of severity.
const ( InvalidLevel Level = iota - 1 FatalLevel ErrorLevel WarnLevel InfoLevel DebugLevel TraceLevel )
Log levels.
func MustParseLevel ¶
MustParseLevel parses level string or panics.
type Logger ¶
type Logger struct { Writer io.Writer Level Level Tier int // contains filtered or unexported fields }
Logger represents a logger with configurable Level and Handler.
func (*Logger) DecreasePadding ¶
func (l *Logger) DecreasePadding()
DecreasePadding decreases the padding 1 times.
func (*Logger) IncreasePadding ¶
func (l *Logger) IncreasePadding()
IncreasePadding increases the padding 1 times.
func (*Logger) ResetPadding ¶
func (l *Logger) ResetPadding()
ResetPadding resets the padding to default.
func (*Logger) WithField ¶
WithField returns a new entry with the `key` and `value` set.
Note that the `key` should not have spaces in it - use camel case or underscores
func (*Logger) WithFields ¶
WithFields returns a new entry with `fields` set.
func (*Logger) WithoutPadding ¶
WithoutPadding returns a new entry with padding set to default.