yaglogger

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 5 Imported by: 8

README

yaglogger (Yet another Go Logger)

GoDoc Go Report Card Coverage Status

yaglogger is a simple logger for Go. It allows to log in color to screen and to a file.

Installation

 go get -u github.com/jlentink/yaglogger

Default logger

package main

import (
	"github.com/jlentink/yaglogger"
)

func main() {
    logger := yaglogger.NewLogger()
    logger.Info("Hello world")
}

Custom logger

Or adjust where needed by initializing a new logger with the following options. Referer NewLogger for more information.

package main

import (
	"github.com/jlentink/yaglogger"
)
func main() {
        yalogger.Logger {
            Level:       0,
            OutErr:      nil,
            OutNormal:   nil,
            Output:      yalogger.LevelOutput{},
            ShowLevel:   false,
            ShowDate:    false,
            Color:       false,
            LogToScreen: false,
            LogFilePath: "",
            LogFile:     nil,
        }
	}

Documentation

Index

Constants

View Source
const (
	LevelFatal level = iota
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
	LevelTrace
	LevelAll
)

All log levels

Variables

This section is empty.

Functions

func Debug added in v0.0.2

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

Debug logs a message with level debug

func Error added in v0.0.2

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

Error logs a message with level error

func Fatal added in v0.0.2

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

Fatal logs a message with level fatal

func Info added in v0.0.2

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

Info logs a message with level info

func SetLevel added in v0.0.2

func SetLevel(level level)

SetLevel sets the log level

func Trace added in v0.0.2

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

Trace logs a message with level trace

func Warn added in v0.0.2

func Warn(message string, a ...any)

Warn logs a message with level warn

Types

type LevelOutput

type LevelOutput struct {
	Fatal io.Writer
	Error io.Writer
	Warn  io.Writer
	Info  io.Writer
	Debug io.Writer
	Trace io.Writer
}

LevelOutput defines the output stream for screen

type Logger

type Logger struct {
	Level       level
	Output      LevelOutput
	ShowLevel   bool
	ShowDate    bool
	Color       bool
	LogToScreen bool
	LogFilePath string
	LogFile     *os.File
}

Logger Struture

func New added in v0.0.2

func New() *Logger

New creates a new logger

func (*Logger) Debug

func (l *Logger) Debug(message string, a ...any)

Debug logs a message with level debug

func (*Logger) Error

func (l *Logger) Error(message string, a ...any)

Error logs a message with level error

func (*Logger) Fatal

func (l *Logger) Fatal(message string, a ...any)

Fatal logs a message with level fatal

func (*Logger) Info

func (l *Logger) Info(message string, a ...any)

Info logs a message with level info

func (*Logger) IsLogLevelEnabled

func (l *Logger) IsLogLevelEnabled(level level) bool

IsLogLevelEnabled returns true if the given level is enabled

func (*Logger) LevelColor

func (l *Logger) LevelColor(level level, message any) aurora.Value

LevelColor returns the color of the given level

func (*Logger) LevelName

func (l *Logger) LevelName(level level) string

LevelName returns the name of the given level

func (*Logger) LevelOutput

func (l *Logger) LevelOutput(level level) io.Writer

LevelOutput returns the output stream for the given level

func (*Logger) Log

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

Log is the generic logging function

func (*Logger) SetLevel

func (l *Logger) SetLevel(level level)

SetLevel sets the log level

func (*Logger) Trace

func (l *Logger) Trace(message string, a ...any)

Trace logs a message with level trace

func (*Logger) Warn

func (l *Logger) Warn(message string, a ...any)

Warn logs a message with level warn

Jump to

Keyboard shortcuts

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