kuttilog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2020 License: MIT Imports: 1 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 also a default implementation, which uses the Go standard log package. Levels begin at 0, and can go up to a implemetation-specific maximum.

Index

Constants

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

Default Log levels

Variables

This section is empty.

Functions

func Loglevel

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. There will always be a space printed before the first argument, after the label prefix if any.

func ResetLogger

func ResetLogger()

ResetLogger resets to the default logger.

func SetLogger

func SetLogger(l Logger)

SetLogger sets the current logger.

func Setloglevel

func Setloglevel(newlevel int)

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

func V

func V(level int) bool

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

Types

type Logger

type Logger interface {
	MaxLevel() int                // The maximum level permitted by this logger
	LevelPrefix(level int) string // The logger-supplied prefix string for a level.
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Logger contains methods for implemetation-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.

Jump to

Keyboard shortcuts

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