console

package
v0.0.0-...-f32f910 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: MIT Imports: 3 Imported by: 0

README

Console

Package console implements simple hierarchical logging functionality.

This is a pretty standard hierarchical console logging module that allows you to use tiered functions to manage what is printed to the command line. For example if the level is set to Info, then Trace and Debug messages will be implemented as no-ops, reducing the amount of information printed.

Setting up the console usually happens in the init() method of a package:

func init() {
    // Initialize our debug logging with our prefix
    console.Init("[myapp] ", log.Lmicroseconds)
    console.SetLevel(console.LevelInfo)
}

Now the logging functions can automatically be used:

console.Trace("routine %s happening", thing)
console.Debug("sending message #%d from %s to %s", msg, send, recv)
console.Info("listening on %s", addr)
console.Status("completed %d out of %d tasks", completed, nTasks)
console.Warn("limit of %d queries reached", nQueries)
console.Warne(err)

The purpose of these functions were to have simple pout and perr methods inside of applications. Another way to use this library is simply to copy and paste this code and lowercase the function names into your app.

Documentation

Overview

Package console implements simple hierarchical logging functionality.

Index

Constants

View Source
const (
	LevelTrace uint8 = iota
	LevelDebug
	LevelInfo
	LevelStatus
	LevelWarn
	LevelSilent
)

Levels for implementing the debug and trace message functionality.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, a ...interface{})

Debug prints to the standard logger if level is debug or greater; arguments are handled in the manner of log.Printf, but a newline is appended.

func Info

func Info(msg string, a ...interface{})

Info prints to the standard logger if level is info or greater; arguments are handled in the manner of log.Printf, but a newline is appended.

func Init

func Init(prefix string, flag int)

Init the console logger with the previx and log options

func LogLevel

func LogLevel() string

LogLevel returns a string representation of the current level.

func SetLogLevel

func SetLogLevel(level uint8)

SetLogLevel modifies the log level for messages at runtime. Ensures that the highest level that can be set is the trace level. This function is often called from outside of the package in an init() function to define how logging is handled in the console.

func Status

func Status(msg string, a ...interface{})

Status prints to the standard logger if level is status or greater; arguments are handled in the manner of log.Printf, but a newline is appended.

func Trace

func Trace(msg string, a ...interface{})

Trace prints to the standard logger if level is trace or greater; arguments are handled in the manner of log.Printf, but a newline is appended.

func Warn

func Warn(msg string, a ...interface{})

Warn prints to the standard logger if level is warn or greater; arguments are handled in the manner of log.Printf, but a newline is appended.

func Warne

func Warne(err error)

Warne is a helper function to simply warn about an error received.

Types

This section is empty.

Jump to

Keyboard shortcuts

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