Documentation ¶
Overview ¶
usage:
level := astro.DebugLevel formatter := astro.ConsoleFormatter if os.Gentenv("GO_ENV") == "production" { level = astro.InfoLevel formatter = astro.JSONFormatter } log.Config( // or log.Config astro.Token(...), astro.With({"app" "api"}, {"host": host}), astro.DisplayLogLevel(level), astro.Formatter(formatter), astro.Sample(sampler), // DisableTimeSTamp // default astro.SendLogLevel(astro.InfoLevel), ) .... log.With("port", Port).Info("server stared")
```
Index ¶
- Constants
- func HTTPHandler(logger Logger) func(next http.Handler) http.Handler
- type CLIFormatter
- type ConsoleFormatter
- type Event
- type Formatter
- type Hook
- type JSONFormatter
- type Level
- type LogfmtFormatter
- type Logger
- func (logger *Logger) Config(options ...LoggerOption) error
- func (logger Logger) Debug(message string)
- func (logger Logger) Debugf(format string, a ...interface{})
- func (logger Logger) Error(message string)
- func (logger Logger) Errorf(format string, a ...interface{})
- func (logger Logger) Fatal(message string)
- func (logger Logger) Fatalf(format string, a ...interface{})
- func (logger Logger) Info(message string)
- func (logger Logger) Infof(format string, a ...interface{})
- func (logger Logger) Track(fields ...interface{})
- func (logger Logger) Warn(message string)
- func (logger Logger) Warnf(format string, a ...interface{})
- func (logger Logger) With(fields ...interface{}) Logger
- type LoggerOption
- func AddFields(fields ...interface{}) LoggerOption
- func AddHook(hook Hook) LoggerOption
- func SetFields(fields ...interface{}) LoggerOption
- func SetFormatter(formatter Formatter) LoggerOption
- func SetInsertTimestampField(insert bool) LoggerOption
- func SetLevel(level Level) LoggerOption
- func SetLevelFieldName(fieldName string) LoggerOption
- func SetMessageFieldName(fieldName string) LoggerOption
- func SetTimestampFieldName(fieldName string) LoggerOption
- func SetTimestampFunc(fn func() time.Time) LoggerOption
- func SetWriter(writer io.Writer) LoggerOption
- type StdoutWriter
Constants ¶
View Source
const ( TimestampFieldName = "timestamp" MessageFieldName = "message" LevelFieldName = "level" )
View Source
const (
// Version is the astroflow's library version
Version = "0.10.6"
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CLIFormatter ¶
type CLIFormatter struct { NoColor bool TimestampFieldName string LevelFieldName string MessageFieldName string }
func NewCLIFormatter ¶
func NewCLIFormatter() CLIFormatter
func (CLIFormatter) Format ¶
func (formatter CLIFormatter) Format(event Event) []byte
type ConsoleFormatter ¶
type ConsoleFormatter struct { TimestampFieldName string MessageFieldName string LevelFieldName string NoColor bool }
func NewConsoleFormatter ¶
func NewConsoleFormatter() ConsoleFormatter
func (ConsoleFormatter) Format ¶
func (formatter ConsoleFormatter) Format(event Event) []byte
type JSONFormatter ¶
type JSONFormatter struct{}
func (JSONFormatter) Format ¶
func (formatter JSONFormatter) Format(entry Event) []byte
type LogfmtFormatter ¶
type LogfmtFormatter struct{}
func (LogfmtFormatter) Format ¶
func (formatter LogfmtFormatter) Format(event Event) []byte
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
func NewLogger ¶
func NewLogger(options ...LoggerOption) Logger
NewLogger returns a new logger with default configuration. Additional can be provided
func (*Logger) Config ¶
func (logger *Logger) Config(options ...LoggerOption) error
Config configure the logger
func (Logger) Track ¶ added in v0.6.0
func (logger Logger) Track(fields ...interface{})
Track an event without message nor level
type LoggerOption ¶
func AddFields ¶
func AddFields(fields ...interface{}) LoggerOption
AddFields add the provided fields to the logger's internal fields
func AddHook ¶
func AddHook(hook Hook) LoggerOption
func SetFields ¶
func SetFields(fields ...interface{}) LoggerOption
SetFields replace the logger's internal fields with the provided fields
func SetFormatter ¶
func SetFormatter(formatter Formatter) LoggerOption
func SetInsertTimestampField ¶
func SetInsertTimestampField(insert bool) LoggerOption
func SetLevel ¶
func SetLevel(level Level) LoggerOption
func SetLevelFieldName ¶
func SetLevelFieldName(fieldName string) LoggerOption
func SetMessageFieldName ¶
func SetMessageFieldName(fieldName string) LoggerOption
func SetTimestampFieldName ¶
func SetTimestampFieldName(fieldName string) LoggerOption
func SetTimestampFunc ¶
func SetTimestampFunc(fn func() time.Time) LoggerOption
func SetWriter ¶
func SetWriter(writer io.Writer) LoggerOption
type StdoutWriter ¶ added in v0.6.0
type StdoutWriter struct{}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.