jsonlog

package
v0.0.0-...-ddc59df Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2022 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

Define a Level type to represent the severity level for a log entry.

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

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

func (Level) String

func (l Level) String() string

Return a human-friendly string for the severity level.

type Logger

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

Define a custom Logger type. This holds the output destination that the log entries will be written to, the minimum severity level that log entries will be written for, plus a mutex for coordinating the writes.

func New

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

Return 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)

func (*Logger) PrintFatal

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

func (*Logger) PrintInfo

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

Declare some helper methods for writing log entries at the different levels. Notice that these all accept a map as the second parameter which can contain any arbitrary 'properties' that you want to appear in the log entry.

func (*Logger) Write

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

We also implement a Write() method on our Logger type so that it satisfies the io.Writer interface. This 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