logging

package
v0.0.0-...-e955a5d Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SuccessResult = Result{Success, nil}

SuccessResult is a default success result

Functions

func Debug

func Debug(format string, v ...interface{})

Debug formats with fmt.Sprintf and prints the result to the configured writer

func DebugRequest

func DebugRequest(req *http.Request, res *http.Response)

DebugRequest will dump the given request and response and prints the result to the configured writer

func Init

func Init(errorOutput io.Writer, debugOutput io.Writer)

Init initialises the error and debug output loggers

func LoggerToFile

func LoggerToFile(filename string, locateWithExec bool, maxSize, maxBackups, maxAge int, compressBackups bool) (
	output io.WriteCloser, cause error)

LoggerToFile creates qn output file destination for logging which can then be passed to an Init call. filename is the file to write logs to locateWithExec prepends the executable directory to the filename when true maxSize is the maximum size in megabytes of the log file before it gets rotated maxAge is the maximum number of days to retain old log files maxBackups is the maximum number of old log files to retain compressBackups determines if the rotated log files should be compressed using gzip

Types

type Error

type Error struct {
	Message string
	Cause   error
	Stack   []byte
}

Error is used to provide information about a program error and facilitate debugging

func NewError

func NewError(message string, cause error) *Error

NewError creates a new Error struct with the given parameters

func (Error) String

func (e Error) String() string

String implements the Stringer interface so that has a "native" format

type Result

type Result struct {
	Code  ResultCode
	Error *Error
}

Result couples a result code with an error, which should only be nil when the code is SUCCESS.

func NewResult

func NewResult(code ResultCode, error *Error) Result

NewResult creates a new Result struct with the given parameters

func ResultFromCause

func ResultFromCause(cause error) Result

ResultFromCause creates a Result based on the given parameters

func ResultFromCode

func ResultFromCode(code ResultCode, message string) Result

ResultFromCode creates a Result based on the given parameters

func ResultFromError

func ResultFromError(message string, cause error) Result

ResultFromError creates a Result based on the given parameters

func ResultFromMessage

func ResultFromMessage(message string) Result

ResultFromMessage creates a Result based on the given parameters

func (Result) Description

func (r Result) Description() string

Description returns just the messages for for error and cause, without the debug information.

func (Result) Failure

func (r Result) Failure() bool

Failure will return true if the result indicates failure

func (Result) Log

func (r Result) Log()

Log will print the result. For errors this will include the stacktrace if available.

func (Result) String

func (r Result) String() string

String implementation for a Result struct

func (Result) Success

func (r Result) Success() bool

Success will return true if the result indicates success

type ResultCode

type ResultCode int

ResultCode is a predefined code to describe the result of a function call.

const (
	// Success result
	Success ResultCode = 100
	// ErrorGeneric result
	ErrorGeneric ResultCode = 200
	// BadRequest result
	ErrorBadRequest ResultCode = 400
	// TokenInactive result
	ErrorTokenInactive ResultCode = 455
)

Jump to

Keyboard shortcuts

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