yaglogger

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 10 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

Direct usage

package main

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

func main() {
	log.Debug("Debug")
}

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

This section is empty.

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(v ...any)

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf added in v0.0.4

func Fatalf(format string, v ...any)

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Fatalln added in v0.0.6

func Fatalln(v ...any)

Fatalln is equivalent to Println() followed by a call to os.Exit(1).

func Flags added in v0.0.6

func Flags() int

Flags returns the output flags for the standard logger. and is unsupported in this package.

func Info added in v0.0.2

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

Info logs a message with level info

func Output added in v0.0.6

func Output(calldepth int, s string) error

func Panic added in v0.0.4

func Panic(v ...any)

func Panicf added in v0.0.4

func Panicf(format string, v ...any)

func Panicln added in v0.0.6

func Panicln(v ...any)

func Prefix added in v0.0.6

func Prefix() string

func Print added in v0.0.6

func Print(v ...any)

func Printf added in v0.0.6

func Printf(format string, v ...any)

func Println added in v0.0.6

func Println(v ...any)

func SetFlags added in v0.0.6

func SetFlags(flag int)

func SetLevel added in v0.0.2

func SetLevel(level LogLevel)

SetLevel sets the log level

func SetLevelByString added in v0.0.6

func SetLevelByString(level string)

func SetLogger added in v0.0.6

func SetLogger(logger *Logger)

func SetOutput added in v0.0.6

func SetOutput(w io.Writer)

func SetPrefix added in v0.0.6

func SetPrefix(prefix string)

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

func Writer added in v0.0.6

func Writer() io.Writer

Types

type Format added in v0.0.6

type Format struct {
	ShowDate   bool
	DateLayout string
	Color      bool
	ShowLevel  bool
	EndOfLine  string
	Prefix     string
}

type LevelOutput

type LevelOutput struct {
	Fatal    *os.File
	Error    *os.File
	Warn     *os.File
	Info     *os.File
	Debug    *os.File
	Trace    *os.File
	Msg      *os.File
	DebugMsg *os.File
}

LevelOutput defines the output stream for screen

type LogLevel added in v0.0.7

type LogLevel uint

Level type

const (
	LevelNone LogLevel = iota
	LevelFatal
	LevelError
	LevelWarn
	LevelInfo
	LevelDebug
	LevelTrace
	LevelAll
)

All log levels

func (LogLevel) String added in v0.0.7

func (l LogLevel) String() string

type Logger

type Logger struct {
	Level       LogLevel
	Output      LevelOutput
	Format      Format
	LogToScreen bool
	LogFilePath string
	LogFile     io.Writer

	ForceNewLine    bool
	ShowLogLocation bool
	// contains filtered or unexported fields
}

Logger Structure

func GetInstance added in v0.0.6

func GetInstance() *Logger

func New added in v0.0.2

func New() *Logger

New creates a new logger

func (*Logger) CenteredLevelName added in v0.0.7

func (l *Logger) CenteredLevelName(level LogLevel) string

CenteredLevelName returns the name of the given level

func (*Logger) Debug

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

Debug logs a message with level debug

func (*Logger) EnableColors added in v0.0.6

func (l *Logger) EnableColors(c bool)

EnableColors enables/disables colors

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(v ...any)

Fatal logs a message with level fatal

func (*Logger) Fatalf added in v0.0.6

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

Fatalf logs a message with level fatal

func (*Logger) Fatalln added in v0.0.6

func (l *Logger) Fatalln(v ...any)

func (*Logger) Fprint added in v0.0.6

func (l *Logger) Fprint(w io.Writer, a ...any) (n int, err error)

func (*Logger) Fprintf added in v0.0.6

func (l *Logger) Fprintf(w io.Writer, format string, a ...any) (n int, err error)

func (*Logger) GetColours added in v0.0.6

func (l *Logger) GetColours() *aurora.Aurora

GetColours returns the aurora instance

func (*Logger) GetFileWithLine added in v0.0.7

func (l *Logger) GetFileWithLine() string

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 LogLevel) bool

IsLogLevelEnabled returns true if the given level is enabled

func (*Logger) LevelColor

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

LevelColor returns the color of the given level

func (*Logger) LevelOutput

func (l *Logger) LevelOutput(level LogLevel) *os.File

LevelOutput returns the output stream for the given level

func (*Logger) Log

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

Log is the generic logging function

func (*Logger) Panic added in v0.0.4

func (l *Logger) Panic(v ...any)

Panic logs a message with level fatal

func (*Logger) Panicf added in v0.0.6

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

Panic logs a message with level fatal

func (*Logger) Print added in v0.0.6

func (l *Logger) Print(v ...any)

Print prints message

func (*Logger) PrintDebug added in v0.0.6

func (l *Logger) PrintDebug(format any) (n int, err error)

PrintDebug prints message with debug level

func (*Logger) PrintDebugf added in v0.0.6

func (l *Logger) PrintDebugf(format string, a ...any) (n int, err error)

PrintDebugf prints message with debug level and formatting

func (*Logger) Printf added in v0.0.6

func (l *Logger) Printf(format string, a ...any)

Printf prints message with formatting

func (*Logger) SetDebug added in v0.0.6

func (l *Logger) SetDebug(d bool) *Logger

SetDebug sets the log level to debug

func (*Logger) SetLevel

func (l *Logger) SetLevel(level LogLevel) *Logger

SetLevel sets the log level

func (*Logger) SetLevelByString added in v0.0.6

func (l *Logger) SetLevelByString(level string) LogLevel

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

Directories

Path Synopsis
examples
log-to-screen command

Jump to

Keyboard shortcuts

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