logger

package module
v0.0.0-...-9ce0206 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2018 License: MIT Imports: 9 Imported by: 1

README

go-log

Build Status Godoc license goreportcard

Golang Logging Library

This Golang library provides an easy interface for logging to console and files. The library provides support for multiple log levels.

Supported Log levels

The following log levels are supported when logging.

  • TRACE
  • DEBUG
  • INFO
  • WARNING
  • ERROR
  • FATAL

Logging to fatal will terminate the program.

Usage

To create a new logger specify a log file and a log level. Specifying an empty string "" for the log file will return a console only logger.

log := logger.NewLogger("/tmp/mylogfile.log", logger.INFO)

This will create an INFO level logger that will log to the path /tmp/mylogfile.log.

To log to info:

log.Info("My log message")

To log to error:

log.Error("My error message")

You can even use formatting

myString := "World"
myInt := 47
log.Debug("Hello, %s: %d", myString, myInt)

Yields Hello, World: 47

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

type Log interface {
	Close() error
	Console(string, ...interface{})
	ConsoleInfo(string, ...interface{})
	Trace(string, ...interface{})
	Debug(string, ...interface{})
	Info(string, ...interface{})
	Warning(string, ...interface{})
	Error(string, ...interface{})
	Fatal(string, ...interface{})
}

Log is an interface describing the required functions for a logger.

func NewLogger

func NewLogger(filename string, level LogLevel) (Log, error)

NewLogger returns a pointer to a new Logger containing basic configuration.

func NewMockLogger

func NewMockLogger() Log

NewMockLogger returns a new dummy logger.

type LogLevel

type LogLevel int

LogLevel contains the range of logging levels to show

const (
	TRACE LogLevel = iota
	DEBUG
	INFO
	WARNING //4
	ERROR
	FATAL
)

Defines standard log levels

type Logger

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

Logger is a log handler for various levels of logging.

func (*Logger) Close

func (logger *Logger) Close() error

Close cleans up any file handles and necessary shutdown functions.

func (*Logger) Console

func (logger *Logger) Console(message string, a ...interface{})

Console logs a message directly to the console if quiet is not set.

func (*Logger) ConsoleInfo

func (logger *Logger) ConsoleInfo(message string, a ...interface{})

ConsoleInfo is a helper function that logs to both the console and Info log.

func (*Logger) Debug

func (logger *Logger) Debug(message string, a ...interface{})

Debug writes a DEBUG level log message to the log file.

func (*Logger) Error

func (logger *Logger) Error(message string, a ...interface{})

Error writes an ERROR level log message to the log file.

func (*Logger) Fatal

func (logger *Logger) Fatal(message string, a ...interface{})

Fatal writes a FATAL level log message to the log file.

func (*Logger) Info

func (logger *Logger) Info(message string, a ...interface{})

Info writes an INFO level log message to the log file.

func (*Logger) Trace

func (logger *Logger) Trace(message string, a ...interface{})

Trace writes a TRACE level log message to the log file.

func (*Logger) Warning

func (logger *Logger) Warning(message string, a ...interface{})

Warning writes a WARNING level log message to the log file.

type MockLogger

type MockLogger struct{}

MockLogger is a dummy logger that performs no-ops.

func (*MockLogger) Close

func (logger *MockLogger) Close() error

Close performs no-op.

func (*MockLogger) Console

func (logger *MockLogger) Console(string, ...interface{})

Console performs no-op.

func (*MockLogger) ConsoleInfo

func (logger *MockLogger) ConsoleInfo(string, ...interface{})

ConsoleInfo performs no-op.

func (*MockLogger) Debug

func (logger *MockLogger) Debug(string, ...interface{})

Debug performs no-op.

func (*MockLogger) Error

func (logger *MockLogger) Error(string, ...interface{})

Error performs no-op.

func (*MockLogger) Fatal

func (logger *MockLogger) Fatal(string, ...interface{})

Fatal performs no-op.

func (*MockLogger) Info

func (logger *MockLogger) Info(string, ...interface{})

Info performs no-op.

func (*MockLogger) Trace

func (logger *MockLogger) Trace(string, ...interface{})

Trace performs no-op.

func (*MockLogger) Warning

func (logger *MockLogger) Warning(string, ...interface{})

Warning performs no-op.

Jump to

Keyboard shortcuts

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