logger

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level int8

Level represents the severity level of a log entry.

const (
	LevelInfo  Level = iota // Has the value of 0.
	LevelError              // Has the value of 1.
	LevelFatal              // Has the value of 2.
	LevelOff                // Has the value of 3.
)

Initialize constants which represent a specific severity level using the "iota" keyword as a shortcut to assign successive integer values to the constants.

func (Level) String

func (l Level) String() string

String returns a human-friendly string for the severity level.

type Logger

type Logger struct {
	Verbose bool `json:"verbose"`
	// contains filtered or unexported fields
}

Logger is the custom logger. It holds the output destination that the log entries will be written to, the minimum severity level that log entries will be written for, and a mutex for coordination the writes.

func NewLogger

func NewLogger(out io.Writer, minLevel Level) *Logger

NewLogger returns a new Logger instance which writes log entries at or above a minimum severity level to a specific output destination.

func (*Logger) PrintError

func (l *Logger) PrintError(err error, properties map[string]string)

PrintError is a helper that writes Info level log entries.

func (*Logger) PrintFatal

func (l *Logger) PrintFatal(err error, properties map[string]string)

PrintFatal is a helper that writes Info level log entries. It also terminates the application.

func (*Logger) PrintInfo

func (l *Logger) PrintInfo(message string, properties map[string]string)

PrintInfo is a helper that writes Info level log entries.

func (*Logger) TryLog

func (l *Logger) TryLog(message string, properties map[string]string, level Level)

TryPrintInfo is a helper that will PrintInfo depending on verbose flag

func (*Logger) Write

func (l *Logger) Write(message []byte) (n int, err error)

Write satisfies the io.Writer interface. It writes a log entry at the ERROR level with no additional properties

Jump to

Keyboard shortcuts

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