log

package module
v0.0.0-...-5167237 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2019 License: BSD-3-Clause Imports: 9 Imported by: 8

README

Log

Some aspects of logging have proven difficult to test with automated testing. The logtest directory provides some test cases that can be run manually.

GoDoc

Documentation

Overview

Package log provides logging for dist.ribut.us.

Index

Constants

View Source
const (
	// Truncate is a reference to os.O_TRUNC
	Truncate = os.O_TRUNC

	// Append is a reference to os.O_APPEND
	Append = os.O_APPEND
)

Variables

View Source
var Contents = Append

Contents determines how the existing contents of the log will be treated. It should be set to either Truncate or Append.

View Source
var Formatter = Format

Formatter is what the log uses to format values to strings. It defaults to Format, but can be replaced.

View Source
var PathDepth = 1

PathDepth sets how many directories to include when showing file names in calls to Line

View Source
var TimeFormat = "2006-01-02_15:04:05.00"

TimeFormat to format time in the log

View Source
var Trim uint = 2

Trim removes the bottom layers from the stack trace when calling Line. These are always the runtime and so not useful information.

Functions

func Debug

func Debug(data ...interface{})

Debug for the default logger

func Error

func Error(err error) bool

Error method for the default logger

func Fatal

func Fatal(err error)

Fatal method for the defulat logger

func Format

func Format(value interface{}) string

Format takes a value and converts it to a string. It makes sure any string values are wrapped in quotes. Anything fulfilling Val takes priority.

func GetDebug

func GetDebug() bool

GetDebug for the default logger

func Go

func Go()

Go wraps log from the Go standard library so it will write the default log.

func Info

func Info(data ...interface{})

Info writes data to the default logger

func Mute

func Mute()

Mute default logger by setting the writer to nil

func NoTrace

func NoTrace()

NoTrace disables SetTrace

func Panic

func Panic(err error)

Panic method for the defulat logger

func SetDebug

func SetDebug(debug bool)

SetDebug for the default logger

func SetTrace

func SetTrace(start, end, pathDepth int)

SetTrace to include line in default logger log messages

func To

func To(w io.Writer)

To sets the writer for the default logger

func ToFile

func ToFile(path ...string) error

ToFile sets the default logger to log to a file. If no path is given, it will create a file in the working directory with the same name as the program followed by ".log". If more than one path is given, everything beyond the first is ingored.

func ToStdOut

func ToStdOut()

ToStdOut sets default logger to write to os.Stdout

Types

type KV

type KV struct {
	K string
	V interface{}
}

KV write a key value pair as "key=value".

func (KV) LogVal

func (kv KV) LogVal() string

LogVal sets how KV will be displayed in the logs

type Lbl

type Lbl string

Lbl provides a way to add strings that will not be wrapped in quotes

func (Lbl) LogVal

func (l Lbl) LogVal() string

LogVal returns the underlying string

type Log

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

Log writes data to a log. Each entry is one line

func Child

func Child(data ...interface{}) *Log

Child method for the default logger

func File

func File(path ...string) (*Log, error)

File opens a file as a log. If no path is given, it will creat a file in the working directory with the same name as the program followed by ".log". If more than one path is given, everything beyond the first is ingored.

func New

func New(w io.Writer) *Log

New creates a new log from a writer.

func (*Log) Child

func (l *Log) Child(data ...interface{}) *Log

Child creates a new log that uses the same writer. All data passed in will be written on every line written to this log.

func (*Log) Close

func (l *Log) Close() error

Close will close the writer if the underlying type has a Close method. It will only return an error if one is generated while closing the writer. If the writer is not actually a WriterCloser, no error will be returned.

func (*Log) Debug

func (l *Log) Debug(data ...interface{})

Debug will write data to the log only if debug is enabled

func (*Log) Error

func (l *Log) Error(err error) bool

Error takes an error and if it is not nil writes it to the log. It returns a bool indicating if there was an error.

func (*Log) Fatal

func (l *Log) Fatal(data ...interface{})

Fatal writes data to the log with the FATAL flag and call os.Exit(1). Fatal should only be called from a main package.

func (*Log) GetDebug

func (l *Log) GetDebug() bool

GetDebug gets the debug bool

func (*Log) Info

func (l *Log) Info(data ...interface{})

Info writes data to the log with the INFO flag

func (*Log) Mute

func (l *Log) Mute()

Mute a log by setting the writer to nil

func (*Log) NoTrace

func (l *Log) NoTrace()

NoTrace disables SetTrace

func (*Log) Panic

func (l *Log) Panic(err error)

Panic takes an error and if it is not nil, writes it to the log then panics. Panic should only be called from a main package.

func (*Log) SetDebug

func (l *Log) SetDebug(debug bool)

SetDebug sets the debug bool

func (*Log) SetTrace

func (l *Log) SetTrace(start, end, pathDepth int)

SetTrace to include line in log messages. To output just the calling line, invoke log.SetTrace(1,1,1)

func (*Log) To

func (l *Log) To(w io.Writer)

To changes the writer for a log

type Val

type Val interface {
	LogVal() string
}

Val takes priority in Format.

func CallLine

func CallLine(above int) Val

CallLine returns the a single line above steps above in the stack trace

func Line

func Line() Val

Line returns the invoking line

func Trace

func Trace(start, end int) Val

Trace calls TraceDepth using PathDepth for the depth.

func TraceDepth

func TraceDepth(start, end, pathDepth int) Val

TraceDepth returns a formatted slice of the stack trace. The start arg determines how close to the calling line to return and end determines how close to the top of the stack trace to return.

If start is positive, that many lines from the beginning will be removed. If start is negative, that is how many lines will be returned (and end will be the anchor).

If end is negative, that is how far from the top of the stack trace end will be. If end is positive, that is how many lines will be returned (and start will be the anchor).

If start is negative and end is positive, then I don't know what happens!

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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