kuttilog

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: MIT Imports: 2 Imported by: 7

README

kuttilog

A simple levelled logging system, used throughout the kutti project.

Go Report Card PkgGoDev GitHub release (latest by date)

Documentation

Overview

Package kuttilog implements a simple levelled logging system. The SetLevel function sets the current level. The Print, Printf and Println functions all take a level parameter, and only log if it is less than or equal to the current level.

The package provides a Logger interface, so that the actual output can vary between implementations. The SetLogger method can be called with an appropriate implementation. There is a default implementation, which uses a standard output logger created using the Go standard log package.

Levels begin at 0, and can go up to a implementation-specific maximum. The default logger provides five levels: Quiet(0), Minimal(1), Info(2), Verbose(3) and Debug(4). The default level is Info(2).

There is also a special level: Error(-1), deliberately kept below the minimum level. All implementations must ensure that logs at this level have to mandatorily produce output.

Index

Constants

View Source
const (
	Error   = -1
	Quiet   = 0
	Minimal = 1
	Info    = 2
	Verbose = 3
	Debug   = 4
)

Default Log levels

Variables

This section is empty.

Functions

func LogLevel added in v0.2.0

func LogLevel() int

LogLevel returns the current log level.

func MaxLevel

func MaxLevel() int

MaxLevel returns the highest level permitted by the current logger.

func Print

func Print(level int, v ...interface{})

Print prints to the log, if the level is <= current log level. Arguments are handled in the manner of fmt.Print.

func Printf

func Printf(level int, format string, v ...interface{})

Printf prints to the log, if the level is <= current log level. Arguments are handled in the manner of fmt.Printf.

func Println

func Println(level int, v ...interface{})

Println prints to the log, if the level is <= current log level. Arguments are handled in the manner of fmt.Println.

func ResetLogger

func ResetLogger()

ResetLogger resets to the default logger.

func SetLogLevel added in v0.2.0

func SetLogLevel(newlevel int)

SetLogLevel sets the current log level. If level is below 0 or greater than MaxLevel, it is not changed.

func SetLogger

func SetLogger(l Logger)

SetLogger sets the current logger.

func V

func V(level int) bool

V returns true if the specified level is between -1 and the current log level, false otherwise.

Types

type Logger

type Logger interface {
	// MaxLevel returns the maximum level permitted by this logger.
	MaxLevel() int
	// LevelPrefix returns rhe logger-supplied prefix string for a
	// level. It may return an empty string.
	LevelPrefix(level int) string
	// Print prints to the log.
	// Arguments are handled in the manner of fmt.Print.
	Print(v ...interface{})
	// Printf prints to the log.
	// Arguments are handled in the manner of fmt.Printf.
	Printf(format string, v ...interface{})
	// Println prints to the log.
	// Arguments are handled in the manner of fmt.Println.
	Println(v ...interface{})
}

Logger contains methods for implementation-specific logging. Exact destination, formatting etc. is implementation-specific. Kuttilog will call each print method only if needed. It will also append a level prefix string as the first item output. Implementations can provide their own prefix strings via the LevelPrefix method.

Jump to

Keyboard shortcuts

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