simplelog

package module
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2023 License: GPL-2.0 Imports: 4 Imported by: 1

README

simplelog!

Installation

Easily install github.com/Nigel2392/simplelog with the following command:

go get github.com/Nigel2392/simplelog

Usage

Simple import the package, and initiate the logger with the following code:

import "github.com/Nigel2392/simplelog"
var logger = simplelog.NewLogger(loglevel)
// Set on error std
logger.SetStd(os.File)
logger.SetStdErr(os.File) // For errors, optional

Log levels

The logger uses the following log levels: It gets the integer value of the log level, and logs everything above that level.

error   = 4 = "error" 
warning = 3 = "warning" 
info    = 2 = "info" 
debug   = 1 = "debug" 
test    = 0 = "test" 

Logger interface

The logger interface is as follows:

type Logger interface {
	// Set the standard output
	SetStd(std *os.File)
	// Set the standard output for errors
	SetStdErr(std *os.File)
	// Write a message
	Write(t string, message ...any)
	// Write an error message
	Error(msg ...any)
	// Write a warning message
	Warning(msg ...any)
	// Write an info message
	Info(msg ...any)
	// Write a debug message
	Debug(msg ...any)
	// Write a test message
	Test(msg ...any)
}

Documentation

Index

Constants

View Source
const (
	Reset        string = "\033[0m"
	Red          string = "\033[31m"
	Green        string = "\033[32m"
	Yellow       string = "\033[33m"
	Blue         string = "\033[34m"
	Purple       string = "\033[35m"
	Cyan         string = "\033[36m"
	White        string = "\033[37m"
	BrightRed    string = "\033[31;1m"
	BrightGreen  string = "\033[32;1m"
	BrightYellow string = "\033[33;1m"
	BrightBlue   string = "\033[34;1m"
	BrightPurple string = "\033[35;1m"
	BrightCyan   string = "\033[36;1m"
)

ANSI color codes

View Source
const (
	LogErr   = "error"
	LogWarn  = "warning"
	LogInfo  = "info"
	LogDebug = "debug"
	LogTest  = "test"
)

Variables

View Source
var (

	// LogTest
	ColorLevelTest = Purple

	// LogDebug
	ColorLevelDebug = Green

	// LogInfo
	ColorLevelInfo = Blue

	// LogWarn
	ColorLevelWarning = Yellow

	// LogErr
	ColorLevelError = Red

	// No level, default switch case opt.
	ColorNoLevel = Green
)

Preset colors for use in the logger's Colorize function

Functions

func Colorize

func Colorize(level int, msg string) string

Colorize a message based on the loglevel

func NewLogger

func NewLogger(level string) *logger

func WrapTime

func WrapTime(t string, msg string) string

Wrap a message with time

Types

type Logger

type Logger interface {
	// Set the standard output
	SetStd(std *os.File)
	// Set the standard output for errors
	SetStdErr(std *os.File)
	// Write a message
	Write(t string, message string, args ...any)
	// Write an error message
	Error(msg any, args ...any)
	// Write a warning message
	Warning(msg string, args ...any)
	// Write an info message
	Info(msg string, args ...any)
	// Write a debug message
	Debug(msg string, args ...any)
	// Write a test message
	Test(msg string, args ...any)
}

Standard logger interface. Every logger should implement this interface. To be used by the framework.

Jump to

Keyboard shortcuts

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