Categorygithub.com/RichardKnop/logging
modulepackage
0.0.0-20190827224416-1a693bdd4fae
Repository: https://github.com/richardknop/logging.git
Documentation: pkg.go.dev

# README

Logging

A simple leveled logging library with coloured output.

Travis Status for RichardKnop/logging godoc for RichardKnop/logging


Log levels:

  • INFO (blue)
  • WARNING (pink)
  • ERROR (red)
  • FATAL (red)

Formatters:

  • DefaultFormatter
  • ColouredFormatter

Example usage. Create a new package log in your app such that:

package log

import (
	"github.com/RichardKnop/logging"
)

var (
	logger = logging.New(nil, nil, new(logging.ColouredFormatter))

	// INFO ...
	INFO = logger[logging.INFO]
	// WARNING ...
	WARNING = logger[logging.WARNING]
	// ERROR ...
	ERROR = logger[logging.ERROR]
	// FATAL ...
	FATAL = logger[logging.FATAL]
)

Then from your app you could do:

package main

import (
	"github.com/yourusername/yourapp/log"
)

func main() {
	log.INFO.Print("log message")
}

# Functions

New returns instance of Logger.

# Constants

DEBUG level.
ERROR level.
FATAL level.
INFO level.
WARNING level.

# Structs

ColouredFormatter colours log messages with ASCI escape codes and adds filename and line number before the log message See https://en.wikipedia.org/wiki/ANSI_escape_code.
DefaultFormatter adds filename and line number before the log message.
Wrapper ...

# Interfaces

Formatter interface.
LoggerInterface will accept stdlib logger and a custom logger.

# Type aliases

Logger ...