logging

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLogDirectory ...
	DefaultLogDirectory = fmt.Sprintf("~/.%s/logs", constants.AppName)
)

Functions

This section is empty.

Types

type Color

type Color string

Color ...

const (
	Black       Color = "\033[0;30m"
	DarkGray    Color = "\033[1;30m"
	Red         Color = "\033[0;31m"
	LightRed    Color = "\033[1;31m"
	Green       Color = "\033[0;32m"
	LightGreen  Color = "\033[1;32m"
	Orange      Color = "\033[0;33m"
	Yellow      Color = "\033[1;33m"
	Blue        Color = "\033[0;34m"
	LightBlue   Color = "\033[1;34m"
	Purple      Color = "\033[0;35m"
	LightPurple Color = "\033[1;35m"
	Cyan        Color = "\033[0;36m"
	LightCyan   Color = "\033[1;36m"
	LightGray   Color = "\033[0;37m"
	White       Color = "\033[1;37m"

	Reset   Color = "\033[0;0m"
	Bold    Color = "\033[;1m"
	Reverse Color = "\033[;7m"
)

Colors

func (Color) Wrap

func (lc Color) Wrap(text string) string

Wrap ...

type Config

type Config struct {
	RotationInterval                                                                                time.Duration
	FileSize, RotationSize, FlushSize                                                               int
	DisableLogging, DisableDisplaying, DisableContextualDisplaying, DisableFlushOnWrite, Assertions bool
	LogLevel, DisplayLevel                                                                          Level
	DisplayHighlight                                                                                Highlight
	Directory, MsgPrefix                                                                            string
}

Config ...

func DefaultConfig

func DefaultConfig() (Config, error)

DefaultConfig ...

type Factory

type Factory interface {
	Make() (Logger, error)
	MakeChain(chainID string, subdir string) (Logger, error)
	MakeSubdir(subdir string) (Logger, error)
	Close()
}

Factory ...

func NewFactory

func NewFactory(config Config) Factory

NewFactory ...

type Highlight

type Highlight int

Highlight mode to apply to displayed logs

const (
	Plain Highlight = iota
	Colors
)

Highlighting modes available

func ToHighlight

func ToHighlight(h string, fd uintptr) (Highlight, error)

ToHighlight chooses a highlighting mode

type Level

type Level int

Level ...

const (
	Off Level = iota
	Fatal
	Error
	Warn
	Info
	Debug
	Verbo
)

Enum ...

func ToLevel

func ToLevel(l string) (Level, error)

ToLevel ...

func (Level) Color

func (l Level) Color() Color

Color ...

func (Level) String

func (l Level) String() string

type Log

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

Log ...

func New

func New(config Config) (*Log, error)

New ...

func NewTestLog

func NewTestLog(config Config) (*Log, error)

NewTestLog ...

func (*Log) AssertDeferredNoError

func (l *Log) AssertDeferredNoError(f func() error)

AssertDeferredNoError ...

func (*Log) AssertDeferredTrue

func (l *Log) AssertDeferredTrue(f func() bool, format string, args ...interface{})

AssertDeferredTrue ...

func (*Log) AssertNoError

func (l *Log) AssertNoError(err error)

AssertNoError ...

func (*Log) AssertTrue

func (l *Log) AssertTrue(b bool, format string, args ...interface{})

AssertTrue ...

func (*Log) Debug

func (l *Log) Debug(format string, args ...interface{})

Debug ...

func (*Log) Error

func (l *Log) Error(format string, args ...interface{})

Error ...

func (*Log) Fatal

func (l *Log) Fatal(format string, args ...interface{})

Fatal ...

func (*Log) Info

func (l *Log) Info(format string, args ...interface{})

Info ...

func (*Log) RecoverAndExit

func (l *Log) RecoverAndExit(f, exit func())

RecoverAndExit ...

func (*Log) RecoverAndPanic

func (l *Log) RecoverAndPanic(f func())

RecoverAndPanic ...

func (*Log) SetContextualDisplayingEnabled

func (l *Log) SetContextualDisplayingEnabled(enabled bool)

SetContextualDisplayingEnabled ...

func (*Log) SetDisplayLevel

func (l *Log) SetDisplayLevel(lvl Level)

SetDisplayLevel ...

func (*Log) SetDisplayingEnabled

func (l *Log) SetDisplayingEnabled(enabled bool)

SetDisplayingEnabled ...

func (*Log) SetLogLevel

func (l *Log) SetLogLevel(lvl Level)

SetLogLevel ...

func (*Log) SetLoggingEnabled

func (l *Log) SetLoggingEnabled(enabled bool)

SetLoggingEnabled ...

func (*Log) SetPrefix

func (l *Log) SetPrefix(prefix string)

SetPrefix ...

func (*Log) Stop

func (l *Log) Stop()

Stop ...

func (*Log) StopOnPanic

func (l *Log) StopOnPanic()

StopOnPanic ...

func (*Log) Verbo

func (l *Log) Verbo(format string, args ...interface{})

Verbo ...

func (*Log) Warn

func (l *Log) Warn(format string, args ...interface{})

Warn ...

func (*Log) Write

func (l *Log) Write(p []byte) (int, error)

type Logger

type Logger interface {
	io.Writer // For logging pre-formated messages

	// Log that a fatal error has occurred. The program should likely exit soon
	// after this is called
	Fatal(format string, args ...interface{})
	// Log that an error has occurred. The program should be able to recover
	// from this error
	Error(format string, args ...interface{})
	// Log that an event has occurred that may indicate a future error or
	// vulnerability
	Warn(format string, args ...interface{})
	// Log an event that may be useful for a user to see to measure the progress
	// of the protocol
	Info(format string, args ...interface{})
	// Log an event that may be useful for a programmer to see when debuging the
	// execution of the protocol
	Debug(format string, args ...interface{})
	// Log extremely detailed events that can be useful for inspecting every
	// aspect of the program
	Verbo(format string, args ...interface{})

	// If assertions are enabled, will result in a panic if err is non-nil
	AssertNoError(err error)
	// If assertions are enabled, will result in a panic if b is false
	AssertTrue(b bool, format string, args ...interface{})
	// If assertions are enabled, the function will be called and will result in
	// a panic the returned value is non-nil
	AssertDeferredNoError(f func() error)
	// If assertions are enabled, the function will be called and will result in
	//  a panic the returned value is false
	AssertDeferredTrue(f func() bool, format string, args ...interface{})

	// Recovers a panic, logs the error, and rethrows the panic.
	StopOnPanic()
	// If a function panics, this will log that panic and then re-panic ensuring
	// that the program logs the error before exiting.
	RecoverAndPanic(f func())

	// If a function panics, this will log that panic and then call the exit
	// function, ensuring that the program logs the error, recovers, and
	// executes the desired exit function
	RecoverAndExit(f, exit func())

	SetLogLevel(Level)
	SetDisplayLevel(Level)
	SetPrefix(string)
	SetLoggingEnabled(bool)
	SetDisplayingEnabled(bool)
	SetContextualDisplayingEnabled(bool)

	// Stop this logger and write back all meta-data.
	Stop()
}

Logger defines the interface that is used to keep a record of all events that happen to the program

type NoFactory

type NoFactory struct{}

NoFactory ...

func (NoFactory) Close

func (NoFactory) Close()

Close ...

func (NoFactory) Make

func (NoFactory) Make() (Logger, error)

Make ...

func (NoFactory) MakeChain

func (NoFactory) MakeChain(string, string) (Logger, error)

MakeChain ...

func (NoFactory) MakeSubdir

func (NoFactory) MakeSubdir(string) (Logger, error)

MakeSubdir ...

type NoIOWriter

type NoIOWriter struct{}

NoIOWriter is a mock Writer that does not write to any underlying source

func (*NoIOWriter) Close

func (nw *NoIOWriter) Close() error

Close ...

func (*NoIOWriter) Flush

func (nw *NoIOWriter) Flush() error

Flush ...

func (*NoIOWriter) Initialize

func (nw *NoIOWriter) Initialize(Config) error

Initialize ...

func (*NoIOWriter) Rotate

func (nw *NoIOWriter) Rotate() error

Rotate ...

func (*NoIOWriter) Write

func (nw *NoIOWriter) Write(p []byte) (int, error)

Write ...

func (*NoIOWriter) WriteString

func (nw *NoIOWriter) WriteString(s string) (int, error)

WriteString ...

type NoLog

type NoLog struct{}

NoLog ...

func (NoLog) AssertDeferredNoError

func (NoLog) AssertDeferredNoError(f func() error)

AssertDeferredNoError ...

func (NoLog) AssertDeferredTrue

func (NoLog) AssertDeferredTrue(f func() bool, format string, args ...interface{})

AssertDeferredTrue ...

func (NoLog) AssertNoError

func (NoLog) AssertNoError(error)

AssertNoError ...

func (NoLog) AssertTrue

func (NoLog) AssertTrue(b bool, format string, args ...interface{})

AssertTrue ...

func (NoLog) Debug

func (NoLog) Debug(format string, args ...interface{})

Debug ...

func (NoLog) Error

func (NoLog) Error(format string, args ...interface{})

Error ...

func (NoLog) Fatal

func (NoLog) Fatal(format string, args ...interface{})

Fatal ...

func (NoLog) Info

func (NoLog) Info(format string, args ...interface{})

Info ...

func (NoLog) RecoverAndExit

func (NoLog) RecoverAndExit(f, exit func())

RecoverAndExit ...

func (NoLog) RecoverAndPanic

func (NoLog) RecoverAndPanic(f func())

RecoverAndPanic ...

func (NoLog) SetContextualDisplayingEnabled

func (NoLog) SetContextualDisplayingEnabled(bool)

SetContextualDisplayingEnabled ...

func (NoLog) SetDisplayLevel

func (NoLog) SetDisplayLevel(Level)

SetDisplayLevel ...

func (NoLog) SetDisplayingEnabled

func (NoLog) SetDisplayingEnabled(bool)

SetDisplayingEnabled ...

func (NoLog) SetLogLevel

func (NoLog) SetLogLevel(Level)

SetLogLevel ...

func (NoLog) SetLoggingEnabled

func (NoLog) SetLoggingEnabled(bool)

SetLoggingEnabled ...

func (NoLog) SetPrefix

func (NoLog) SetPrefix(string)

SetPrefix ...

func (NoLog) Stop

func (NoLog) Stop()

Stop ...

func (NoLog) StopOnPanic

func (NoLog) StopOnPanic()

StopOnPanic ...

func (NoLog) Verbo

func (NoLog) Verbo(format string, args ...interface{})

Verbo ...

func (NoLog) Warn

func (NoLog) Warn(format string, args ...interface{})

Warn ...

func (NoLog) Write

func (NoLog) Write([]byte) (int, error)

type RotatingWriter

type RotatingWriter interface {
	Initialize(Config) error
	Flush() error
	Write(b []byte) (int, error)
	WriteString(s string) (int, error)
	Close() error
	Rotate() error
}

RotatingWriter allows for rotating a stream writer

type RoutineID

type RoutineID struct{}

RoutineID can print the current goroutine ID

func (RoutineID) String

func (RoutineID) String() string

type Stacktrace

type Stacktrace struct {
	Global bool
}

Stacktrace can print the current stacktrace

func (Stacktrace) String

func (st Stacktrace) String() string

Jump to

Keyboard shortcuts

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