jsonlog

package
v1.0.40 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package jsonlog implements json format logging.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownLogLevel = errors.New("unknown log level")
)

Functions

This section is empty.

Types

type Level

type Level int8

Level represents the severity level for a log entry.

const (
	LevelDebug   Level = iota // 0
	LevelInfo                 // 1
	LevelError                // 2
	LevelFatal                // 3
	LevelOff     = 99
	LevelInvalid = -1
)

func LogLevel

func LogLevel(level string) (Level, error)

LogLevel matches the level string to a Level type.

func (Level) String

func (l Level) String() string

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

type Logger

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

Logger is custom logger type. It 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

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

func (*Logger) PrintDebug

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

PrintDebug is a helper method to write DEBUG level log entries.

func (*Logger) PrintError

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

PrintError is a helper method to write ERROR level log entries.

func (*Logger) PrintFatal

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

PrintFatal is a helper method to write FATAL level log entries.

func (*Logger) PrintInfo

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

PrintInfo is a helper method to write INFO level log entries.

func (*Logger) Write

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

Write writes a log entry at the ERROR level with no additional properties. It is implemented to satisfy the io.Writer interface.

Jump to

Keyboard shortcuts

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