tools

package
v0.0.0-...-13a3114 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckErr

func CheckErr(err error)

CheckErr is a convenience function makes error handling dangerously simple.

func LogDebug

func LogDebug(format string, args ...interface{})

LogDebug works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It uses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Debug'

func LogError

func LogError(format string, args ...interface{})

LogError works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It uses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Error'

func LogFatal

func LogFatal(format string, args ...interface{})

LogFatal works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It uses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set hogher or equal to 'Fatal'

func LogInfo

func LogInfo(format string, args ...interface{})

LogInfo works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It uses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Info'

func LogWarn

func LogWarn(format string, args ...interface{})

LogWarn works just as fmt.Printf, but prints into the Convenience loggers stream, as set with SetConvenienceLogger(). It uses the standard logger (package log) if te Convenience logger is unset. The message is only printed if ActiveLogLevel is set higher or equal to 'Warn'

func Maxf64

func Maxf64(v []float64) float64

Maxf64 returns the maximum of a slice of float64

func Minf64

func Minf64(v []float64) float64

Minf64 returns the minimum of a slice of float64

Types

type CommonConfig

type CommonConfig struct {
	BuildTimeStamp time.Time
	GitVersion     string
	ShowVersion    bool
	ActiveLogLevel LogLevel

	LogFileName      string
	Logger           *Logger
	WorkingDirectory string
	// contains filtered or unexported fields
}

func (*CommonConfig) AddCleanUpFn

func (cfg *CommonConfig) AddCleanUpFn(f func() error)

func (*CommonConfig) CleanUp

func (cfg *CommonConfig) CleanUp()

func (*CommonConfig) Exit

func (cfg *CommonConfig) Exit(code int)

func (*CommonConfig) FatalExit

func (cfg *CommonConfig) FatalExit()

func (*CommonConfig) FlagDefinition

func (cfg *CommonConfig) FlagDefinition()

func (CommonConfig) GetInspectData

func (cfg CommonConfig) GetInspectData() string

GetInspectData offers some additional debugging information

func (*CommonConfig) Initialize

func (cfg *CommonConfig) Initialize(version string, buildtimestamp string) *CommonConfig

func (CommonConfig) String

func (cfg CommonConfig) String() string

type LogLevel

type LogLevel int

LogLevel sets the criticality of a logging output. It is used to filter logging messages depending on their priority. Compare to log4j.

const (
	Off LogLevel = iota
	Fatal
	Error
	Warn
	Debug
	Info
	All
)

The predefined LogLevels that are used by the logging funktions below.

func LogLevelString

func LogLevelString(s string) (LogLevel, error)

LogLevelString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func LogLevelValues

func LogLevelValues() []LogLevel

LogLevelValues returns all values of the enum

func (LogLevel) IsALogLevel

func (i LogLevel) IsALogLevel() bool

IsALogLevel returns "true" if the value is listed in the enum definition. "false" otherwise

func (LogLevel) String

func (i LogLevel) String() string

type Logger

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

A Logger is an onbject the offers several method to write Messages to a stream. Atually it is a wrapper aroung the 'log' package, that enhances the LogLevel functionality.

func NewLogger

func NewLogger(logfilename string, level LogLevel) *Logger

NewLogger creates a new Logger. It take a string file name as output file and a LogLevel to filter the messages that are wanted. The logger will use io.StdOut if the log filename string parameter is "STDERR"

func NewLoggerFromFile

func NewLoggerFromFile(logfile io.Writer, level LogLevel) *Logger

NewLoggerFromFile creates a new Logger. It take a file parameter (io.Writer) output file and a LogLevel to filter the messages that are wanted. The first created logger wil be set to be the convenience logger (see the convenience functions Log...() below). Afterwards created loggers will not overwrie this. The convenience logger can be reset by using the method SetConvenienceLogger.

func (*Logger) Debug

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

Debug works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Debug'

func (*Logger) Error

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

Error works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Error'

func (*Logger) Fatal

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

Fatal works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set hogher or equal to 'Fatal'

func (*Logger) Info

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

Info works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Info'

func (*Logger) SetConvenienceLogger

func (l *Logger) SetConvenienceLogger()

SetConvenienceLogger sets a logger as a singleton object. The LogInfo etc. functions use this singleton to offer logging function without an object context.

func (*Logger) Warn

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

Warn works just as fmt.Printf, but prints into the loggers stream. The message is only printed if ActiveLogLevel is set higher or equal to 'Warn'

Jump to

Keyboard shortcuts

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