...

Package logger

import "github.com/gonitro/nitro/app/logger"
Overview
Index

Overview ▾

Package log provides a log interface

Index ▾

func Debug(args ...interface{})
func Debugf(template string, args ...interface{})
func Error(args ...interface{})
func Errorf(template string, args ...interface{})
func Fatal(args ...interface{})
func Fatalf(template string, args ...interface{})
func Info(args ...interface{})
func Infof(template string, args ...interface{})
func Init(opts ...Option) error
func Log(level Level, v ...interface{})
func Logf(level Level, format string, v ...interface{})
func NewContext(ctx context.Context, l Logger) context.Context
func String() string
func Trace(args ...interface{})
func Tracef(template string, args ...interface{})
func V(lvl Level, log Logger) bool
func Warn(args ...interface{})
func Warnf(template string, args ...interface{})
type Helper
    func NewHelper(log Logger) *Helper
    func (h *Helper) Debug(args ...interface{})
    func (h *Helper) Debugf(template string, args ...interface{})
    func (h *Helper) Error(args ...interface{})
    func (h *Helper) Errorf(template string, args ...interface{})
    func (h *Helper) Fatal(args ...interface{})
    func (h *Helper) Fatalf(template string, args ...interface{})
    func (h *Helper) Info(args ...interface{})
    func (h *Helper) Infof(template string, args ...interface{})
    func (h *Helper) Trace(args ...interface{})
    func (h *Helper) Tracef(template string, args ...interface{})
    func (h *Helper) Warn(args ...interface{})
    func (h *Helper) Warnf(template string, args ...interface{})
    func (h *Helper) WithError(err error) *Helper
    func (h *Helper) WithFields(fields map[string]interface{}) *Helper
type Level
    func GetLevel(levelStr string) (Level, error)
    func (l Level) Enabled(lvl Level) bool
    func (l Level) String() string
type Logger
    func Fields(fields map[string]interface{}) Logger
    func FromContext(ctx context.Context) (Logger, bool)
    func NewLogger(opts ...Option) Logger
type Option
    func SetOption(k, v interface{}) Option
    func WithCallerSkipCount(c int) Option
    func WithFields(fields map[string]interface{}) Option
    func WithLevel(level Level) Option
    func WithOutput(out io.Writer) Option
type Options

Package files

context.go default.go helper.go level.go logger.go options.go

func Debug

func Debug(args ...interface{})

func Debugf

func Debugf(template string, args ...interface{})

func Error

func Error(args ...interface{})

func Errorf

func Errorf(template string, args ...interface{})

func Fatal

func Fatal(args ...interface{})

func Fatalf

func Fatalf(template string, args ...interface{})

func Info

func Info(args ...interface{})

func Infof

func Infof(template string, args ...interface{})

func Init

func Init(opts ...Option) error

func Log

func Log(level Level, v ...interface{})

func Logf

func Logf(level Level, format string, v ...interface{})

func NewContext

func NewContext(ctx context.Context, l Logger) context.Context

func String

func String() string

func Trace

func Trace(args ...interface{})

func Tracef

func Tracef(template string, args ...interface{})

func V

func V(lvl Level, log Logger) bool

Returns true if the given level is at or lower the current logger level

func Warn

func Warn(args ...interface{})

func Warnf

func Warnf(template string, args ...interface{})

type Helper

type Helper struct {
    Logger
    // contains filtered or unexported fields
}

func NewHelper

func NewHelper(log Logger) *Helper

func (*Helper) Debug

func (h *Helper) Debug(args ...interface{})

func (*Helper) Debugf

func (h *Helper) Debugf(template string, args ...interface{})

func (*Helper) Error

func (h *Helper) Error(args ...interface{})

func (*Helper) Errorf

func (h *Helper) Errorf(template string, args ...interface{})

func (*Helper) Fatal

func (h *Helper) Fatal(args ...interface{})

func (*Helper) Fatalf

func (h *Helper) Fatalf(template string, args ...interface{})

func (*Helper) Info

func (h *Helper) Info(args ...interface{})

func (*Helper) Infof

func (h *Helper) Infof(template string, args ...interface{})

func (*Helper) Trace

func (h *Helper) Trace(args ...interface{})

func (*Helper) Tracef

func (h *Helper) Tracef(template string, args ...interface{})

func (*Helper) Warn

func (h *Helper) Warn(args ...interface{})

func (*Helper) Warnf

func (h *Helper) Warnf(template string, args ...interface{})

func (*Helper) WithError

func (h *Helper) WithError(err error) *Helper

func (*Helper) WithFields

func (h *Helper) WithFields(fields map[string]interface{}) *Helper

type Level

type Level int8
const (
    // TraceLevel level. Designates finer-grained informational events than the Debug.
    TraceLevel Level = iota - 2
    // DebugLevel level. Usually only enabled when debugging. Very verbose logging.
    DebugLevel
    // InfoLevel is the default logging priority.
    // General operational entries about what's going on inside the application.
    InfoLevel
    // WarnLevel level. Non-critical entries that deserve eyes.
    WarnLevel
    // ErrorLevel level. Logs. Used for errors that should definitely be noted.
    ErrorLevel
    // FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
    FatalLevel
)

func GetLevel

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) Enabled

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) String

func (l Level) String() string

type Logger

Logger is a generic logging interface

type Logger interface {
    // Init initialises options
    Init(options ...Option) error
    // The Logger options
    Options() Options
    // Fields set fields to always be logged
    Fields(fields map[string]interface{}) Logger
    // Log writes a log entry
    Log(level Level, v ...interface{})
    // Logf writes a formatted log entry
    Logf(level Level, format string, v ...interface{})
    // String returns the name of logger
    String() string
}
var (
    // Default logger
    DefaultLogger Logger = NewHelper(NewLogger())
)

func Fields

func Fields(fields map[string]interface{}) Logger

func FromContext

func FromContext(ctx context.Context) (Logger, bool)

func NewLogger

func NewLogger(opts ...Option) Logger

NewLogger builds a new logger based on options

type Option

type Option func(*Options)

func SetOption

func SetOption(k, v interface{}) Option

func WithCallerSkipCount

func WithCallerSkipCount(c int) Option

WithCallerSkipCount set frame count to skip

func WithFields

func WithFields(fields map[string]interface{}) Option

WithFields set default fields for the logger

func WithLevel

func WithLevel(level Level) Option

WithLevel set default level for the logger

func WithOutput

func WithOutput(out io.Writer) Option

WithOutput set default output writer for the logger

type Options

type Options struct {
    // The logging level the logger should log at. default is `InfoLevel`
    Level Level
    // fields to always be logged
    Fields map[string]interface{}
    // It's common to set this to a file, or leave it default which is `os.Stderr`
    Out io.Writer
    // Caller skip frame count for file:line info
    CallerSkipCount int
    // Alternative options
    Context context.Context
}