log

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2023 License: MIT Imports: 4 Imported by: 4

README

log

Package log provides a uniform method of logging.

how to use this?

just import this module into your Go project by adding the following line to your imports:

"git.stinnesbeck.com/go/log"

You can use this package in your code as follows:

log.Print(LOGLEVEL, "This is your message of type LOGLEVEL")
log.PrintInfo("This is your info message")
log.PrintWarning("This is your warning message")
log.PrintError("This is your error message")
log.PrintDebug("This is your debug message")

Log levels

The following log levels are supported:

LogLevel Name
0 ERROR
1 WARNING
2 INFO
3 DEBUG

The package will honor a globally set environment variable LOGLEVEL. The package will only print levels that are less or equal than the one provided (e.g. WARNING will only print ERROR and WARNING). If no environment variable is set or it can't be parsed into the names above, ERROR will be selected as the default.

Example usage

You can see an example output by cloning this repo and executing:

go test

Documentation

Overview

Package log provides a uniform method of logging for all go projects at plusserver

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Print

func Print(printLevel LogLevel, message ...any)

Print writes the given text to the console and formats it properly. If no level is not provided or is unknown it will treat it as "INFO".

Use the constants provided by this package for the available levels.

func PrintDebug

func PrintDebug(message ...any)

PrintDebug is a Wrapper for Print(DEBUG, message)

func PrintError

func PrintError(message ...any)

PrintError is a Wrapper for Print(ERROR, message)

func PrintInfo

func PrintInfo(message ...any)

PrintInfo is a Wrapper for Print(INFO, message)

func PrintWarning

func PrintWarning(message ...any)

PrintWarning is a Wrapper for Print(WARNING, message)

Types

type LogLevel

type LogLevel int

LogLevel is our custom type that represents the different log levels

const (
	ERROR LogLevel = iota
	WARNING
	INFO
	DEBUG
)

Log levels that can be assigned to the WriteLog function

func (LogLevel) String

func (l LogLevel) String() string

This implements the String representation for our custom type logLevel

Jump to

Keyboard shortcuts

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