golog

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2023 License: MIT Imports: 5 Imported by: 11

README

GoLog

Package golog or "GoLog" serves as a wrapper around the default log package to implement logging levels:

  • Critical
  • Error
  • Warning
  • Notice
  • Info
  • Debug

Where a configured level of Error would only print messages of type Error and Critical, while a level of Debug would print all log messages.

The package defines a type MyLogger, with methods for formatting output, same as the log package, and it also has a predefined 'standard' logger with associated logging functions that can be used without creating a custom logger. This standard logger has a predefined loglevel of Notice which means that any logs created by Info or Debug functions will be discarded. However, note that the standard logger's settings including loglevel can be updated with the Set functions same as the custom loggers.

The idea with this library is to use the standard logger when a shared logger is desired in the whole project across all packages where the main function configures the settings that should apply to everyone. If custom log settings is desired per package, create custom logger objects with the function New(...)

Documentation

Overview

The package defines a type MyLogger, with methods for formatting output, same as the log package, and it also has a predefined 'standard' logger with associated logging functions that can be used without creating a custom logger. This standard logger has a predefined loglevel of Notice which means that any logs created by Info or Debug functions will be discarded.

Index

Constants

View Source
const (
	LevelNone = iota
	LevelCritical
	LevelError
	LevelWarning
	LevelNotice
	LevelInfo
	LevelDebug
)

These flags define the available log levels that can be configured. A level of LevelWarning means that only messages of level including and above will be displayed (Warning, Error, Critical). So to display log messages of level Debug, the log level must be set to LevelDebug.

View Source
const (
	Ldate = 1 << iota
	Ltime
	Lmicroseconds
	Llongfile
	Lshortfile
	LUTC
	Lmsgprefix
	LstdFlags = Ldate | Ltime
)

These flags define which test to prefix each log entry generated by the logger and are copied from the default log package.

Variables

View Source
var (
	DefaultOutput    = os.Stdout
	DefaultErrOutput = os.Stderr
	NoOutput         = io.Discard
)

These flags define helper values for logging output

Functions

func Critical

func Critical(v ...interface{})

func Criticalf

func Criticalf(format string, v ...interface{})

func Criticalln

func Criticalln(v ...interface{})

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Debugln

func Debugln(v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Errorln

func Errorln(v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func Infoln

func Infoln(v ...interface{})

func Notice

func Notice(v ...interface{})

func Noticef

func Noticef(format string, v ...interface{})

func Noticeln

func Noticeln(v ...interface{})

func Set added in v0.2.0

func Set(name, displayname string, level, flags int, output io.Writer, errOutput io.Writer)

Setup a new logger for a given reference. Intended usage is to specify a custom logger for a packet.

func SetErrOutput added in v0.3.2

func SetErrOutput(w io.Writer)

func SetFlags

func SetFlags(flag int)

func SetLogLevel

func SetLogLevel(level int)

func SetOutput

func SetOutput(w io.Writer)

func Warning

func Warning(v ...interface{})

func Warningf

func Warningf(format string, v ...interface{})

func Warningln

func Warningln(v ...interface{})

Types

type MyLogger

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

A MyLogger represents an active logging object that serves as a wrapper around the Logger from the log package. Each logging operation will check against the defined loglevel to see if the message should be logged before passing it on to the underlying log packets Logger.

func Get added in v0.2.0

func Get(name string) *MyLogger

Get a custom logger if it exists, otherwise return default logger.

func New

func New(name string, level, flags int, output io.Writer, errOutput io.Writer) *MyLogger

New creates a new MyLogger. The level variable sets the loglevel which should be used to filter what is logged. The flags variable is passed directly to the underlying log package to set Logger flags. The output variable sets the destination to which log data will be written.

func (*MyLogger) Critical

func (ml *MyLogger) Critical(v ...interface{})

func (*MyLogger) Criticalf

func (ml *MyLogger) Criticalf(format string, v ...interface{})

func (*MyLogger) Criticalln

func (ml *MyLogger) Criticalln(v ...interface{})

func (*MyLogger) Debug

func (ml *MyLogger) Debug(v ...interface{})

func (*MyLogger) Debugf

func (ml *MyLogger) Debugf(format string, v ...interface{})

func (*MyLogger) Debugln

func (ml *MyLogger) Debugln(v ...interface{})

func (*MyLogger) Error

func (ml *MyLogger) Error(v ...interface{})

func (*MyLogger) Errorf

func (ml *MyLogger) Errorf(format string, v ...interface{})

func (*MyLogger) Errorln

func (ml *MyLogger) Errorln(v ...interface{})

func (*MyLogger) Info

func (ml *MyLogger) Info(v ...interface{})

func (*MyLogger) Infof

func (ml *MyLogger) Infof(format string, v ...interface{})

func (*MyLogger) Infoln

func (ml *MyLogger) Infoln(v ...interface{})

func (*MyLogger) Notice

func (ml *MyLogger) Notice(v ...interface{})

func (*MyLogger) Noticef

func (ml *MyLogger) Noticef(format string, v ...interface{})

func (*MyLogger) Noticeln

func (ml *MyLogger) Noticeln(v ...interface{})

func (*MyLogger) SetDisplayName added in v0.3.0

func (ml *MyLogger) SetDisplayName(name string)

func (*MyLogger) SetErrOutput added in v0.3.2

func (ml *MyLogger) SetErrOutput(w io.Writer)

func (*MyLogger) SetFlags

func (ml *MyLogger) SetFlags(flag int)

func (*MyLogger) SetLogLevel

func (ml *MyLogger) SetLogLevel(level int)

func (*MyLogger) SetOutput

func (ml *MyLogger) SetOutput(w io.Writer)

func (*MyLogger) Warning

func (ml *MyLogger) Warning(v ...interface{})

func (*MyLogger) Warningf

func (ml *MyLogger) Warningf(format string, v ...interface{})

func (*MyLogger) Warningln

func (ml *MyLogger) Warningln(v ...interface{})

Jump to

Keyboard shortcuts

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