logger

package module
v0.0.0-...-c7c465f Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: BSD-3-Clause Imports: 12 Imported by: 3

README

go-logger

Build Status GoDoc

A simple go logger for easy logging and debugging of your programs

Example

Example program demonstrates how to use the logger.

Example Output

package main

import (
	"github.com/gjvnq/go-logger"
	"os"
)

func main () {
	// Get the instance for logger class, "test" is the module name, 1 is used to 
	// state if we want coloring 
	// Third option is optional and is instance of type io.Writer, defaults to os.Stderr
	log, err := logger.New("test", 1, os.Stdout)
	if err != nil {
		panic(err) // Check for error
	}

	// Critically log critical
	log.Critical("This is Critical!")
	log.CriticalF("%+v", err)
	// Debug
	log.Debug("This is Debug!")
	log.DebugF("Here are some numbers: %d %d %f", 10, -3, 3.14)
	// Give the Warning
	log.Warning("This is Warning!")
	log.WarningF("This is Warning!")
	// Show the error
	log.Error("This is Error!")
	log.ErrorF("This is Error!")
	// Notice
	log.Notice("This is Notice!")
	log.NoticeF("%s %s", "This", "is Notice!")
	// Show the info
	log.Info("This is Info!")
	log.InfoF("This is %s!", "Info")

	log.StackAsError("Message before printing stack");
}

Install

go get github.com/apsdehal/go-logger

Use go get -u to update the package.

Tests

Run go test logger to run test on logger and go bench for benchmarks

Thanks

Thanks goes to all go-loggers out there in github world

License

The [BSD 3-Clause license][bsd], the same as the [Go language][golang]. [bsd]: http://opensource.org/licenses/BSD-3-Clause [golang]: http://golang.org/LICENSE

Documentation

Overview

Package name declaration

Index

Constants

View Source
const (
	Black = (iota + 30)
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)

Color numbers for stdout

Variables

This section is empty.

Functions

func InterfacesToString

func InterfacesToString(raw_slice ...interface{}) string

func Stack

func Stack() string

Returns a string with the execution stack for this goroutine

Types

type Info

type Info struct {
	Id       uint64
	GID      uint64
	Time     string
	Module   string
	Level    string
	Line     int
	Filename string
	Message  string
	// contains filtered or unexported fields
}

Info class, Contains all the info on what has to logged, time is the current time, Module is the specific module For which we are logging, level is the state, importance and type of message logged, Message contains the string to be logged, format is the format of string to be passed to sprintf

func (*Info) Output

func (r *Info) Output() string

Returns a proper string to be outputted for a particular info

type Logger

type Logger struct {
	Module string
	Levels map[string]bool
	// contains filtered or unexported fields
}

Logger class that is an interface to user to log messages, Module is the module for which we are testing worker is variable of Worker class that is used in bottom layers to log the message

func New

func New(args ...interface{}) (*Logger, error)

Returns a new instance of logger class, module is the specific module for which we are logging , color defines whether the output is to be colored or not, out is instance of type io.Writer defaults to os.Stderr

func (*Logger) Critical

func (l *Logger) Critical(messages ...interface{})

Critical logs a message at a Critical Level

func (*Logger) CriticalF

func (l *Logger) CriticalF(format string, a ...interface{})

CriticalF logs a message at Critical level using the same syntax and options as fmt.Printf

func (*Logger) CriticalNF

func (l *Logger) CriticalNF(n int, format string, a ...interface{})

CriticalNF is just like CriticalF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) Debug

func (l *Logger) Debug(messages ...interface{})

Debug logs a message at Debug level

func (*Logger) DebugF

func (l *Logger) DebugF(format string, a ...interface{})

DebugF logs a message at Debug level using the same syntax and options as fmt.Printf

func (*Logger) DebugNF

func (l *Logger) DebugNF(n int, format string, a ...interface{})

DebugNF is just like DebugF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) Error

func (l *Logger) Error(messages ...interface{})

Error logs a message at Error level

func (*Logger) ErrorF

func (l *Logger) ErrorF(format string, a ...interface{})

ErrorF logs a message at Error level using the same syntax and options as fmt.Printf

func (*Logger) ErrorNF

func (l *Logger) ErrorNF(n int, format string, a ...interface{})

ErrorNF is just like ErrorF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) Fatal

func (l *Logger) Fatal(messages ...interface{})

Fatal is just like func l.Critical logger except that it is followed by exit to program

func (*Logger) FatalF

func (l *Logger) FatalF(format string, a ...interface{})

FatalF is just like func l.CriticalF logger except that it is followed by exit to program

func (*Logger) FatalNF

func (l *Logger) FatalNF(n int, format string, a ...interface{})

FatalNF is just like FatalF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) Info

func (l *Logger) Info(messages ...interface{})

Info logs a message at Info level

func (*Logger) InfoF

func (l *Logger) InfoF(format string, a ...interface{})

InfoF logs a message at Info level using the same syntax and options as fmt.Printf

func (*Logger) InfoNF

func (l *Logger) InfoNF(n int, format string, a ...interface{})

InfoNF is just like InfoF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) Log

func (l *Logger) Log(lvl string, message interface{})

The log commnand is the function available to user to log message, lvl specifies the degree of the messagethe user wants to log, message is the info user wants to log

func (*Logger) Notice

func (l *Logger) Notice(messages ...interface{})

Notice logs a message at Notice level

func (*Logger) NoticeF

func (l *Logger) NoticeF(format string, a ...interface{})

NoticeF logs a message at Notice level using the same syntax and options as fmt.Printf

func (*Logger) NoticeNF

func (l *Logger) NoticeNF(n int, format string, a ...interface{})

NoticeNF is just like NoticeF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) Panic

func (l *Logger) Panic(messages ...interface{})

Panic is just like func l.Critical except that it is followed by a call to panic

func (*Logger) PanicF

func (l *Logger) PanicF(format string, a ...interface{})

PanicF is just like func l.CriticalF except that it is followed by a call to panic

func (*Logger) PanicNF

func (l *Logger) PanicNF(n int, format string, a ...interface{})

PanicNF is just like PanicF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

func (*Logger) StackAsCritical

func (l *Logger) StackAsCritical(messages interface{})

Prints this goroutine's execution stack as critical with an optional message at the begining

func (*Logger) StackAsDebug

func (l *Logger) StackAsDebug(messages interface{})

Prints this goroutine's execution stack as debug with an optional message at the begining

func (*Logger) StackAsError

func (l *Logger) StackAsError(messages interface{})

Prints this goroutine's execution stack as an error with an optional message at the begining

func (*Logger) Warning

func (l *Logger) Warning(messages ...interface{})

Warning logs a message at Warning level

func (*Logger) WarningF

func (l *Logger) WarningF(format string, a ...interface{})

WarningF logs a message at Warning level using the same syntax and options as fmt.Printf

func (*Logger) WarningNF

func (l *Logger) WarningNF(n int, format string, a ...interface{})

WarningNF is just like WarningF, but the n parameter indicates how many stack levels to go back when printing file name and line number info

type Worker

type Worker struct {
	Minion *log.Logger
	Color  int
	Lock   *sync.Mutex
}

Worker class, Worker is a log object used to log messages and Color specifies if colored output is to be produced

func NewWorker

func NewWorker(prefix string, flag int, color int, out io.Writer) *Worker

Returns an instance of worker class, prefix is the string attached to every log, flag determine the log params, color parameters verifies whether we need colored outputs or not

func (*Worker) Log

func (w *Worker) Log(level string, calldepth int, info *Info) error

Function of Worker class to log a string based on level

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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