log

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2018 License: MIT Imports: 8 Imported by: 54

Documentation

Overview

Code generated by gommon from log/gommon.yml DO NOT EDIT.

Code generated by gommon from log/logger_generated.go.tmpl DO NOT EDIT.

Package log is not usable yet, see legacy/log

Index

Constants

View Source
const MagicPackageLoggerFunctionName = "init"
View Source
const MagicStructLoggerFunctionName = "LoggerIdentity"

Variables

View Source
var UnknownIdentity = Identity{Package: "unk", Type: UnknownLogger}

Functions

func NewTestHandler

func NewTestHandler() *testHandler

func PreOrderDFS

func PreOrderDFS(root *Logger, visited map[*Logger]bool, cb func(l *Logger))

TODO: test it ....

func SetHandlerRecursive

func SetHandlerRecursive(root *Logger, handler Handler)

func SetLevelRecursive

func SetLevelRecursive(root *Logger, level Level)

func ToStringTree

func ToStringTree(root *Logger) *structure.StringTreeNode

Types

type Field

type Field struct {
	Key   string
	Value interface{}
}

type Fields

type Fields struct {
	Keys   []string
	Values []interface{}
}

type Handler

type Handler interface {
	HandleLog(level Level, msg string)
	Flush()
}
var DefaultHandler Handler = &defaultHandler{}

type HandlerFunc

type HandlerFunc func(level Level, msg string)

HandlerFunc is an adapter to allow use of ordinary functions as log entry handlers

func (HandlerFunc) HandleLog

func (f HandlerFunc) HandleLog(level Level, msg string)

TODO: why the receiver is value instead of pointer https://github.com/dyweb/gommon/issues/30

type Identity

type Identity struct {
	Package  string
	Function string
	Struct   string
	File     string
	Line     int
	Type     LoggerType
}

Identity is based where the logger is initialized, it is NOT exactly where the log happens. It is used for applying filter rules and print logger hierarchy. TODO: example

func NewIdentityFromCaller

func NewIdentityFromCaller(skip int) *Identity

TODO: document all the black magic here ... https://github.com/dyweb/gommon/issues/32

func (*Identity) Diff

func (id *Identity) Diff(parent *Identity) string

TODO: this is used for print tree like structure ... it's hard to maintain exact parent and child logger due to cycle import

func (*Identity) Hash

func (id *Identity) Hash() uint64

func (*Identity) SourceLocation

func (id *Identity) SourceLocation() string

func (*Identity) String

func (id *Identity) String() string

type Level

type Level uint8

Level is log level

const (
	// FatalLevel log error and call `os.Exit(1)`
	// TODO: allow user hook exit?
	FatalLevel Level = iota
	// PanicLevel log error and call `panic`
	PanicLevel
	// ErrorLevel log error
	ErrorLevel
	// WarnLevel log warning
	WarnLevel
	// InfoLevel log info
	InfoLevel
	// DebugLevel log debug message, user should enable DebugLevel logging when report bug
	DebugLevel
	// TraceLevel is very verbose, user should enable it only on packages they are currently investing instead of globally
	TraceLevel
)

func (Level) String

func (level Level) String() string

type LoggableStruct

type LoggableStruct interface {
	GetLogger() *Logger
	SetLogger(logger *Logger)
	LoggerIdentity(justCallMe func() *Identity) *Identity
}

type Logger

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

func NewApplicationLogger

func NewApplicationLogger() *Logger

func NewFunctionLogger

func NewFunctionLogger(packageLogger *Logger) *Logger

func NewLibraryLogger

func NewLibraryLogger() *Logger

func NewMethodLogger

func NewMethodLogger(structLogger *Logger) *Logger

func NewPackageLogger

func NewPackageLogger() *Logger

func NewPackageLoggerWithSkip

func NewPackageLoggerWithSkip(skip int) *Logger

func NewStructLogger

func NewStructLogger(packageLogger *Logger, loggable LoggableStruct) *Logger

func (*Logger) AddChild

func (l *Logger) AddChild(child *Logger)

func (*Logger) Debug

func (l *Logger) Debug(args ...interface{})

func (*Logger) Debugf

func (l *Logger) Debugf(format string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(args ...interface{})

func (*Logger) Errorf

func (l *Logger) Errorf(format string, args ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(args ...interface{})

func (*Logger) Fatalf

func (l *Logger) Fatalf(format string, args ...interface{})

func (*Logger) Identity

func (l *Logger) Identity() *Identity

func (*Logger) Info

func (l *Logger) Info(args ...interface{})

func (*Logger) Infof

func (l *Logger) Infof(format string, args ...interface{})

func (*Logger) IsDebugEnabled

func (l *Logger) IsDebugEnabled() bool

func (*Logger) IsErrorEnabled

func (l *Logger) IsErrorEnabled() bool

func (*Logger) IsInfoEnabled

func (l *Logger) IsInfoEnabled() bool

func (*Logger) IsTraceEnabled

func (l *Logger) IsTraceEnabled() bool

func (*Logger) IsWarnEnabled

func (l *Logger) IsWarnEnabled() bool

func (*Logger) Level

func (l *Logger) Level() Level

func (*Logger) Panic

func (l *Logger) Panic(args ...interface{})

func (*Logger) Panicf

func (l *Logger) Panicf(format string, args ...interface{})

func (*Logger) PrintTree

func (l *Logger) PrintTree()

func (*Logger) PrintTreeTo

func (l *Logger) PrintTreeTo(w io.Writer)

func (*Logger) SetHandler

func (l *Logger) SetHandler(h Handler)

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level)

func (*Logger) Trace

func (l *Logger) Trace(args ...interface{})

func (*Logger) Tracef

func (l *Logger) Tracef(format string, args ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(args ...interface{})

func (*Logger) Warnf

func (l *Logger) Warnf(format string, args ...interface{})

type LoggerType

type LoggerType uint8
const (
	UnknownLogger LoggerType = iota
	ApplicationLogger
	LibraryLogger
	PackageLogger
	FunctionLogger
	StructLogger
	MethodLogger
)

func (LoggerType) String

func (tpe LoggerType) String() string

Directories

Path Synopsis
_examples
simple command
uselib command
handlers
stdio
Package stdio can be used with stderr/stdout/file and all the writer that implemented WriteSyncer interface its code is almost identical with default handler, but we duplicate the code to avoid cycle import
Package stdio can be used with stderr/stdout/file and all the writer that implemented WriteSyncer interface its code is almost identical with default handler, but we duplicate the code to avoid cycle import

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL