zlog

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 7 Imported by: 0

README

zlog

Go Reference

A small, thread-safe logging package for Go, with cool features.

Getting started

$ go get github.com/eze-kiel/zlog

Usage

Here is a simple example about the main features of the package:

package main

import (
	"fmt"
	"log"

	"github.com/eze-kiel/zlog"
)

func main() {
	l := zlog.NewLogger() // create logger
	l.Debug("message at debug level")
	l.Info("blah at info level")

    // change log level to warn
	if err := l.ParseLevel("warn"); err != nil {
		log.Fatal(err)
	}

	l.Info("you cannot see me!")
	l.Warn("but you can see me!!")
	l.Error("oops, an error !")

    // disable the colors
	l.UseColors(false)
	l.Fatal("this one is going to be fatal... :(")
}

Documentation

You can get the whole documentation here:

https://pkg.go.dev/github.com/eze-kiel/zlog

License

MIT

Documentation

Index

Constants

View Source
const (
	DebugLvl = iota
	InfoLvl
	WarnLvl
	ErrorLvl
	FatalLvl
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

NewLogger creates a new logger object with default values set

func (*Logger) Debug

func (l *Logger) Debug(message string)

Debug logs a message at the debug level

func (*Logger) Error

func (l *Logger) Error(message string)

Error logs a message at the error level

func (*Logger) Fatal

func (l *Logger) Fatal(message string)

Fatal logs a message at the fatal level

func (*Logger) GetDebugPrefix

func (l *Logger) GetDebugPrefix() string

GetDebugPrefix returns the debug prefix string

func (*Logger) GetErrorPrefix

func (l *Logger) GetErrorPrefix() string

GetErrorPrefix returns the error prefix string

func (*Logger) GetFatalPrefix

func (l *Logger) GetFatalPrefix() string

GetFatalPrefix returns the fatal prefix string

func (*Logger) GetInfoPrefix

func (l *Logger) GetInfoPrefix() string

GetInfoPrefix returns the info prefix string

func (Logger) GetLogLevel

func (l Logger) GetLogLevel() int

GetLogLevel returns the logger's current log level

func (*Logger) GetWarnPrefix

func (l *Logger) GetWarnPrefix() string

GetWarnPrefix returns the warn prefix string

func (*Logger) Info

func (l *Logger) Info(message string)

Info logs a message at the info level

func (*Logger) ParseLevel

func (l *Logger) ParseLevel(level string) error

ParseLevel reads from a string an tries to set the logger's level according to the value provided. It returns an error if it can not parse the level

func (*Logger) SetDebugPrefix

func (l *Logger) SetDebugPrefix(prefix string)

SetDebugPrefix sets the debug prefix string to prefix

func (*Logger) SetErrorPrefix

func (l *Logger) SetErrorPrefix(prefix string)

SetErrorPrefix sets the error prefix string to prefix

func (*Logger) SetFatalPrefix

func (l *Logger) SetFatalPrefix(prefix string)

SetFatalPrefix sets the fatal prefix string to prefix

func (*Logger) SetInfoPrefix

func (l *Logger) SetInfoPrefix(prefix string)

SetInfoPrefix sets the info prefix string to prefix

func (*Logger) SetOutputFileDescriptor

func (l *Logger) SetOutputFileDescriptor(output io.Writer)

SetOutputFileDescriptor allows the user to choose the fd that will be used to log

func (*Logger) SetPrefixBorders

func (l *Logger) SetPrefixBorders(first, last string)

SetPrefixBorders allows to set the level prefix borders

func (*Logger) SetTimeBorders added in v0.0.2

func (l *Logger) SetTimeBorders(first, last string)

SetTimeBorders allows an user to set the time prefix borders

func (*Logger) SetTimeFormat added in v0.0.2

func (l *Logger) SetTimeFormat(format string)

SetTimeFormat allows an user to change default time format

func (*Logger) SetWarnPrefix

func (l *Logger) SetWarnPrefix(prefix string)

SetWarnPrefix sets the warn prefix string to prefix

func (*Logger) UseColors

func (l *Logger) UseColors(value bool)

UseColors allows the user to create colored logs

func (*Logger) Warn

func (l *Logger) Warn(message string)

Warn logs a message at the warn level

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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