dlog

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2020 License: Apache-2.0 Imports: 11 Imported by: 5

Documentation

Overview

Package dlog provides logging functions with caller file and line information, logging levels and level and text filters.

Index

Constants

This section is empty.

Variables

View Source
var CreateLogFile = func() {}

CreateLogFile creates a file for logs to be written to by log functions. This is a NOP if fullOakLogger is not set by SetLogger.

View Source
var Error = func(...interface{}) {}

Error will write a log if the debug level is not NONE

View Source
var FileWrite = func(...interface{}) {}

FileWrite logs by writing to file (if possible) but does not log to console as well. This is a NOP if fullOakLogger is not set by SetLogger.

View Source
var GetLogLevel = func() Level {
	return NONE
}

GetLogLevel returns the log level of the fullOakLogger, or NONE if there is not fullOakLogger.

View Source
var Info = func(...interface{}) {}

Info will write a log if the debug level is higher than WARN

View Source
var SetDebugFilter = func(string) {}

SetDebugFilter defines a string that all logs should be checked against-- if the log message does not contain the input string the log will not log. This is a NOP if fullOakLogger is not set by SetLogger.

View Source
var SetDebugLevel = func(Level) {}

SetDebugLevel sets the log level of the fullOakLogger. This is a NOP if fullOakLogger is not set by SetLogger.

View Source
var Verb = func(...interface{}) {}

Verb will write a log if the debug level is higher than INFO

View Source
var Warn = func(...interface{}) {}

Warn will write a log if the debug level is higher than ERROR

Functions

func ErrorCheck

func ErrorCheck(in error) error

ErrorCheck checks that the input is not nil, then calls Error on it if it is not. Otherwise it does nothing. Emits the input error as is for additional processing if desired.

func SetLogger

func SetLogger(l Logger)

SetLogger defines what logger should be used for oak's internal logging. If this is NOT called before oak.Init is called (assuming this is being used with oak), then it will be called with the default logger as a part of oak.Init.

Types

type FullLogger

type FullLogger interface {
	Logger
	GetLogLevel() Level
	FileWrite(in ...interface{})
	SetDebugFilter(filter string)
	SetDebugLevel(dL Level)
	CreateLogFile()
}

A FullLogger supports, in addition to Logger's functions, the ability to set and get a log level, and create and write logs directly to file.

type Level

type Level int

Level represents the levels a debug message can have

const (
	NONE Level = iota
	ERROR
	WARN
	INFO
	VERBOSE
)

Level values const

func ParseDebugLevel

func ParseDebugLevel(s string) (Level, error)

ParseDebugLevel parses the input string as a known debug levels

type Logger

type Logger interface {
	Error(...interface{})
	Warn(...interface{})
	Info(...interface{})
	Verb(...interface{})
}

A Logger is a minimal log interface for the content oak wants to log: four levels of logging.

func NewLogger

func NewLogger() Logger

NewLogger returns an instance of the default logger with no filter, no file, and level set to ERROR

type RegexLogger added in v2.4.0

type RegexLogger struct {

	// FilterOverrideLevel is the log level at which
	// logs will be shown regardless of the filter.
	FilterOverrideLevel Level
	// contains filtered or unexported fields
}

RegexLogger is a logger implementation that offers some additional features on top of the default logger. Todo v3: combine logger implementations.

func NewRegexLogger added in v2.4.0

func NewRegexLogger(level Level) *RegexLogger

NewRegexLogger returns a custom logger that writes to os.Stdout and overrides filters on WARN or higher messages.

func (*RegexLogger) CreateLogFile added in v2.4.0

func (l *RegexLogger) CreateLogFile()

CreateLogFile creates a file in the 'logs' directory of the starting point of this program to write logs to

func (*RegexLogger) Error added in v2.4.0

func (l *RegexLogger) Error(in ...interface{})

Error will write a dlog if the debug level is not NONE

func (*RegexLogger) FileWrite added in v2.4.0

func (l *RegexLogger) FileWrite(in ...interface{})

FileWrite acts just like a regular write on a RegexLogger. It does not respect overrides.

func (*RegexLogger) GetLogLevel added in v2.4.0

func (l *RegexLogger) GetLogLevel() Level

GetLogLevel returns the current log level, i.e WARN or INFO...

func (*RegexLogger) Info added in v2.4.0

func (l *RegexLogger) Info(in ...interface{})

Info will write a dLog if the debug level is higher than WARN

func (*RegexLogger) SetDebugFilter added in v2.4.0

func (l *RegexLogger) SetDebugFilter(filter string)

SetDebugFilter sets the string which determines what debug messages get printed. Only messages which contain the filer as a pseudo-regex

func (*RegexLogger) SetDebugLevel added in v2.4.0

func (l *RegexLogger) SetDebugLevel(dL Level)

SetDebugLevel sets what message levels of debug will be printed.

func (*RegexLogger) SetWriter added in v2.4.0

func (l *RegexLogger) SetWriter(w io.Writer) error

SetWriter sets the writer that RegexLogger logs to

func (*RegexLogger) Verb added in v2.4.0

func (l *RegexLogger) Verb(in ...interface{})

Verb will write a dLog if the debug level is higher than INFO

func (*RegexLogger) Warn added in v2.4.0

func (l *RegexLogger) Warn(in ...interface{})

Warn will write a dLog if the debug level is higher than ERROR

Jump to

Keyboard shortcuts

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