logger

package module
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2024 License: MIT, MIT Imports: 7 Imported by: 0

README

logger

Description

A simple logger facility for golang. This logger supports logging to stdout, stderr and the local system's logging facility (e.g. syslog).

Usage

package main

import "github.com/sam-caldwell/logger"

func main(){
    var log Logger
    const (
        logTarget logger.LogTarget = logger.Syslog
		verbosity logger.Verbosity = logger.Quiet //as opposed to logger.Debug
		logLevel  logger.Levels = logger.Info
    )
    log.Setup(logTarget, verbosity, logLevel)
	log.Debug("Debug message")
	log.Informational("Informational message") 
	log.Notice("Notice message")
	log.Warning("Warning message")
	log.Error("Error message")
	log.Alert("Alert error message")
	log.Critical("Critical error message.")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetListOfLevels added in v1.0.1

func GetListOfLevels() (result []string)

GetListOfLevels - return a []string list of log levels

Types

type Levels

type Levels uint8

Levels - A numeric indicator of the logging level

The assigned values follows https://datatracker.ietf.org/doc/html/rfc5424
const (
	// Critical - system (application) is unusable
	Critical Levels = 0
	// Alert - action must be taken immediately
	Alert Levels = 1
	// Error - error conditions exist
	Error Levels = 2
	// Warning - warning conditions exist
	Warning Levels = 3
	// Notice - normal but significant conditions
	Notice Levels = 4
	// Info - informational messages
	Info Levels = 5
	// Informational - longer form of Info
	Informational Levels = Info
	// Debug - Debugging information
	Debug Levels = 6
)

func (*Levels) FromString added in v1.0.2

func (level *Levels) FromString(levelString string) error

FromString - Given a string input, convert and store the matching log level or return an error

func (*Levels) ToString

func (level *Levels) ToString() string

func (*Levels) ToSysLogPriority

func (level *Levels) ToSysLogPriority() syslog.Priority

ToSysLogPriority - Convert our log levels to the syslog priorities.

The internal levels follow the syslog RFC pretty closely. But these levels may add non-RFC values in the future. This method converts our log levels to an RFC5424 user level priority value. See https://datatracker.ietf.org/doc/html/rfc5424

type Logger

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

Logger - A simple Logger facility

func (*Logger) Alert

func (log *Logger) Alert(msg string)

Alert - write a message string to the logger.

func (*Logger) Alertf

func (log *Logger) Alertf(formatString string, msg ...any)

Alertf - write a formatted string to the logger.

func (*Logger) Critical

func (log *Logger) Critical(msg string)

Critical - write a message string to the logger.

func (*Logger) Criticalf

func (log *Logger) Criticalf(formatString string, msg ...any)

Criticalf - write a formatted string to the logger.

func (*Logger) Debug

func (log *Logger) Debug(msg string)

Debug - write a message string to the logger.

func (*Logger) Debugf

func (log *Logger) Debugf(formatString string, msg ...any)

Debugf - write a formatted string to the logger.

func (*Logger) Error

func (log *Logger) Error(msg string)

Error - write a message string to the logger.

func (*Logger) Errorf

func (log *Logger) Errorf(formatString string, msg ...any)

Errorf - write a formatted string to the logger.

func (*Logger) Fatal

func (log *Logger) Fatal(msg string, exitCode int)

Fatal - write a message string to the logger. Then terminate.

func (*Logger) Fatalf

func (log *Logger) Fatalf(exitCode int, formatString string, msg ...any)

Fatalf - write a formatted string to the logger. Then terminate.

func (*Logger) Info

func (log *Logger) Info(msg string)

Info - write a message string to the logger.

func (*Logger) Infof

func (log *Logger) Infof(formatString string, msg ...any)

Infof - write a formatted string to the logger.

func (*Logger) Notice

func (log *Logger) Notice(msg string)

Notice - write a message string to the logger.

func (*Logger) Noticef

func (log *Logger) Noticef(formatString string, msg ...any)

Noticef - write a formatted string to the logger.

func (*Logger) SetLevel

func (log *Logger) SetLevel(level Levels) error

SetLevel - Set the current level of a logger object

func (*Logger) SetTarget

func (log *Logger) SetTarget(stdout, stderr, syslog bool) (err error)

SetTarget - Set the current target of a logger object.

This method will set the first (left-most) true target type. Thus, if all three are true, stdout will take precedence. But also if none are true, stdout will be the default.

func (*Logger) Setup

func (log *Logger) Setup(useStdout, useStderr, useSyslog bool, level Levels) error

Setup - Set up the logger object configuration.

func (*Logger) UseBuffer

func (log *Logger) UseBuffer(w io.Writer)

UseBuffer - Configure logger to write to io.Writer

func (*Logger) UseStderr

func (log *Logger) UseStderr()

UseStderr - Configure logger for stderr

func (*Logger) UseStdout

func (log *Logger) UseStdout()

UseStdout - configure logger for stdout

func (*Logger) UseSyslog

func (log *Logger) UseSyslog()

UseSyslog - Configure logger for syslog

func (*Logger) Warn

func (log *Logger) Warn(msg string)

Warn - write a message string to the logger.

func (*Logger) Warnf

func (log *Logger) Warnf(formatString string, msg ...any)

Warnf - write a formatted string to the logger.

type Target

type Target io.Writer

Target - an arbitrary io.Writer object

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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