logger

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: UPL-1.0 Imports: 4 Imported by: 0

Documentation

Overview

Package logger provides logging functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogLevel

type LogLevel int

LogLevel defines a set of logging levels that used to control logging output.

The logging levels are ordered. The available levels in ascending order are:

Fine
Trace
Debug
Info
Warn
Error

Enabling logging at a given level also enables logging at all higher levels. For example, if desired logging level for the logger is set to Debug, the messages at Debug level, as well as Info, Warn and Error levels are all logged.

In addition there is a level Off that can be used to turn off logging.

const (
	// Fine represents a level used to log the most detailed output.
	Fine LogLevel = 10

	// Trace represents a level used to log tracing messages.
	Trace LogLevel = 15

	// Debug represents a level used to log debug messages.
	Debug LogLevel = 20

	// Info represents a level used to log informative messages.
	Info LogLevel = 30

	// Warn represents a level used to log warning messages.
	Warn LogLevel = 40

	// Error represents a level used to log error messages.
	Error LogLevel = 50

	// Off turns off logging.
	Off LogLevel = 99
)

func (LogLevel) String

func (level LogLevel) String() string

String returns a string representation for the log level.

This implements the fmt.Stringer interface.

type Logger

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

Logger represents a logging object that is a wrapper for log.Logger, adding capabilities to control the desired level of messges to log and whether the log entry time is displayed in local time zone or UTC.

var DefaultLogger *Logger = New(os.Stderr, Warn, false)

DefaultLogger represents a default logger that writes warning and higher priority events to stderr.

func New

func New(out io.Writer, level LogLevel, useLocalTime bool) *Logger

New creates a logger that writes messages of the specified logging level to the specified io.Writer. If useLocalTime is set to false, the log entry displays UTC time.

If specified level is set to Off or a not available value, returns nil that represents logging is disabled.

func (*Logger) Close

func (l *Logger) Close() error

Close closes the logger and releases associated resources.

func (*Logger) Debug

func (l *Logger) Debug(messageFormat string, messageArgs ...interface{})

Debug writes the specified message at Debug level to the logger if logger's logging level is less than or equal to Debug.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) Error

func (l *Logger) Error(messageFormat string, messageArgs ...interface{})

Error writes the specified message at Error level to the logger if logger's logging level is less than or equal to Error.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) Fine

func (l *Logger) Fine(messageFormat string, messageArgs ...interface{})

Fine writes the specified message at Fine level to the logger if logger's logging level is less than or equal to Fine.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) Info

func (l *Logger) Info(messageFormat string, messageArgs ...interface{})

Info writes the specified message at Info level to the logger if logger's logging level is less than or equal to Info.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) Log

func (l *Logger) Log(level LogLevel, messageFormat string, messageArgs ...interface{})

Log writes the specified message to logger if logger's logging level is less than or equal to the specified level.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) LogWithFn

func (l *Logger) LogWithFn(level LogLevel, fn func() string)

LogWithFn calls the function fn if the logger's logging level is less than or equal to specified level, writes the message returned from fn to the logger.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) Trace

func (l *Logger) Trace(messageFormat string, messageArgs ...interface{})

Trace writes the specified message at Trace level to the logger if logger's logging level is less than or equal to Trace.

The arguments for the logging message are handled in the manner of fmt.Printf.

func (*Logger) Warn

func (l *Logger) Warn(messageFormat string, messageArgs ...interface{})

Warn writes the specified message at Warn level to the logger if logger's logging level is less than or equal to Warn.

The arguments for the logging message are handled in the manner of fmt.Printf.

Jump to

Keyboard shortcuts

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