Documentation
¶
Index ¶
- Variables
- func Debugf(format string, args ...any)
- func Errorf(format string, args ...any)
- func Printf(format string, args ...any)
- func SetContextData(reader func(context.Context) map[string]any)
- func SetTraceKey(names ...string)
- func Warnf(format string, args ...any)
- type Data
- type Handler
- type Level
- type Logger
- func (l *Logger) Debugf(text string, args ...any)
- func (l *Logger) Errorf(text string, args ...any)
- func (l *Logger) Fatalf(text string, args ...any)
- func (l *Logger) Handlers(h ...Handler) *Logger
- func (l *Logger) Infof(text string, args ...any)
- func (l *Logger) Options(o Option) *Logger
- func (l *Logger) Printf(text string, args ...any)
- func (l *Logger) Tag(name string) *Logger
- func (l *Logger) Trace(depth int) *Logger
- func (l *Logger) Verbosity(m Level) *Logger
- func (l *Logger) Warnf(text string, args ...any)
- func (l *Logger) Write(p []byte) (n int, err error)
- func (l *Logger) Writer(w io.Writer) *Logger
- type Message
- func (m Message) Location(colors bool) string
- func (m Message) MarshalJSON() ([]byte, error)
- func (m Message) MarshalText() ([]byte, error)
- func (m Message) Properties() Data
- func (m Message) Render(o Option) ([]byte, error)
- func (m Message) String() string
- func (m Message) Tag(colors bool) string
- func (m Message) Text(colors, properties bool) string
- func (m Message) Type(colors bool) string
- type Option
Constants ¶
This section is empty.
Variables ¶
var Default = New(os.Stdout, All)
Functions ¶
func SetContextData ¶ added in v1.1.0
SetContextData replaces the reader used for contexts formatted with %+v. The reader must support concurrent calls. A nil reader disables extraction. Changes affect new messages only.
func SetTraceKey ¶ added in v1.1.0
func SetTraceKey(names ...string)
SetTraceKey replaces the trace ID field names, checked in the given order. With no names, it restores automatic recognition. It affects new messages only.
Types ¶
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger support three types(levels) of logging
INF - default, when you want emphasize that something important (not negative) has happened. It should be used for informing about rare situation in your code, such as database connection has been established.
DBG - it meant to be verbose, like every few lines of code, when you decide that part of your code implementation did something important for internal state of your library/code.
ERR - when your code is a place where error is received but there is no good way of handling that situation you might log it todo
- default attributes data added to each Message
- log.Format option
func New ¶
New instance of logger
io.Writer w will receive all messages that are generated internally from strings and arguments that are passed to Logger.Printf.
Option o represents what is going to be included in strings that are passed into io.Writer
func (*Logger) Handlers ¶
Handlers creates new instance of Logger and all Message's are passed into Handler just after it is writer to io.Writer
func (*Logger) Printf ¶
Printf when text is json format and has no arguments a then it will be transformed
type Message ¶
type Message struct {
Tags []string
Level Level
TraceID string
File string
Func string
Line int
ARGS []any
CreatedAt time.Time
// contains filtered or unexported fields
}
func (Message) MarshalJSON ¶
func (Message) MarshalText ¶ added in v1.0.4
func (Message) Properties ¶ added in v1.1.0
type Option ¶
type Option int64
Option ...
const ( // Date render Message with date in 2006/01/02 format Date Option = 1 << iota // Time render Message with time in 15:04:05.000000 format Time // Levels render Message with one of INF, DBG, ERR strings Levels // Tags render Message with tag name Tags // Trace renders the shortened trace ID after tags and the source location after the message. Trace // Properties renders structured %v and %+v data in a Message output string. Properties // Colors render Message with colors Colors // JSON makes output with json format instead text JSON All = Date | Time | Levels | Tags | Trace | Properties | Colors )
