logger

package module
v1.1.0 Latest Latest
Warning

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

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

README

go-logger

Go module providing simple logging support.

Take a look at main.go for an example.

Documentation

Overview

logger provides basic logging support for your application. Supported log destinations are the console and a log file

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseFile

func CloseFile()

CloseFile closes the underlaying file to which the logger messages are written.

func Debug

func Debug(message string, parameters ...any)

func Error

func Error(message string, parameters ...any)

func Fatal

func Fatal(message string, parameters ...any)

func Info

func Info(message string, parameters ...any)

func SetGlobalLogger

func SetGlobalLogger(l *Logger)

SetGlobalLogger updates the global default logger with a custom one. You can create one via the Logger struct.

func Trace

func Trace(message string, parameters ...any)

func Warning

func Warning(message string, parameters ...any)

Types

type Level

type Level uint8

Level of the log message

const (
	LevelTrace Level = iota
	LevelDebug
	LevelInfo
	LevelWarning
	LevelError
	LevelFatal
)

func GetLevelByName

func GetLevelByName(levelName string) Level

GetLevelByName tries to convert the given level name to the represented level code. Allowed values are: 'trace', 'debug', 'info', 'warn', 'warning', 'error', 'panic' and 'fatal' If an incorrect level name was given an warning is logged and info will be returned

type Logger

type Logger struct {
	PrintLevel  Level
	LogLevel    Level
	LogFilePath string
	PrintSource bool

	// Colorizes the log messages for the console.
	// Even if you set this to true the user is able to overwrite this behaviour by
	// setting the environment variables "TERMINAL_DISABLE_COLORS" and
	// "TERMINAL_ENABLE_COLORS" (to force coloring for "unsupported" terminals)
	ColoredOutput bool

	// While logging, the file and line number of the
	// invoking (calling) line can be printed out.
	// This defines an offset that is applied to the call stack.
	// If you you are using an own wrapper function, you
	// have to set this value to one
	FuncCallIncrement int
	// contains filtered or unexported fields
}

func GetGlobalLogger

func GetGlobalLogger() *Logger

func NewLogger

func NewLogger(logger *Logger) *Logger

NewLogger creates a new instance of the logger with the given configuration.

func NewLoggerWithFile

func NewLoggerWithFile(logger *Logger, file *Logger) *Logger

NewLoggerWithFile creates a new instance with the given logger configuration. Instead of opening a new file to write the log messages to, the old file reference of the other logger will be used internal. This enables you to writhe to the same file with different log configurations.

func (*Logger) CloseFile

func (l *Logger) CloseFile()

func (Logger) Debug added in v1.0.2

func (l Logger) Debug(message string, parameters ...any)

func (Logger) Error added in v1.0.2

func (l Logger) Error(message string, parameters ...any)

func (Logger) Fatal added in v1.0.2

func (l Logger) Fatal(message string, parameters ...any)

func (Logger) Info added in v1.0.2

func (l Logger) Info(message string, parameters ...any)

func (*Logger) Log

func (l *Logger) Log(level Level, message string, parameters ...any)

Log logs a message with the given level. As additional parameters you can specify replace values for the message. See "fmt.printf()" for more infos.

func (Logger) Trace added in v1.0.2

func (l Logger) Trace(message string, parameters ...any)

func (Logger) Warning added in v1.0.2

func (l Logger) Warning(message string, parameters ...any)

Directories

Path Synopsis
main contains a simple example of using this logger package
main contains a simple example of using this logger package

Jump to

Keyboard shortcuts

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