golog

package module
v0.0.0-...-4a1f425 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2018 License: BSD-3-Clause Imports: 2 Imported by: 1

README

golog

Go Report Card GoDoc

A wrapper for the go log providing namespaces and standard levels

Overview

The standard go log package provides the core writing methods but does not provide any colouring or level functions. This simply provides those features. You can overwrite the standard log on the package level if you require any different settings.

Installation

With a healthy Go Language installed, simply run go get github.com/landonia/golog

Example

  	package main

	import (
		"flag"
		"github.com/landonia/golog/prettylog"
	)

	func main() {
		log, err := prettylog.New(prettylog.WithNameSpace("mynamespace"))
    		if err != nil {
      			panic(err)
    		}

		// Setup application.....
		log.Info("Application has started successfully..")

		// .. something goes wrong
		log.Error("Whoops")
	}

Out of Box Example

simply run go run $GOPATH/src/github.com/landonia/golog/cmd/example.go

You should see output to the following:

Example output

About

golog was written by Landon Wainwright | GitHub.

Follow me on Twitter @landotube! Although I don't really tweet much tbh.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LevelChangeNotifier

func LevelChangeNotifier(handler LevelNotifierHandler)

LevelChangeNotifier allows a handler to be added to be notified of any global level change

func SetGlobalLevel

func SetGlobalLevel(level Level)

SetGlobalLevel will set the global log level to the specified level If the log level is not recogised it will return a false and default to INFO

Types

type EmptyLogger

type EmptyLogger struct{}

EmptyLogger can be used to fill the interface requirement where a logger has not been provided

func (*EmptyLogger) Debug

func (el *EmptyLogger) Debug(format string, params ...interface{})

Debug implements Logger

func (*EmptyLogger) Error

func (el *EmptyLogger) Error(format string, params ...interface{})

Error implements Logger

func (*EmptyLogger) Fatal

func (el *EmptyLogger) Fatal(format string, params ...interface{})

Fatal implements Logger

func (*EmptyLogger) Info

func (el *EmptyLogger) Info(format string, params ...interface{})

Info implements Logger

func (*EmptyLogger) SetLevel

func (el *EmptyLogger) SetLevel(level Level)

SetLevel implements Logger

func (*EmptyLogger) Trace

func (el *EmptyLogger) Trace(format string, params ...interface{})

Trace implements Logger

func (*EmptyLogger) Warn

func (el *EmptyLogger) Warn(format string, params ...interface{})

Warn implements Logger

type Level

type Level uint8

Level will define a log level

const (

	// No level has been defined
	NONE Level = iota

	// DISABLED will disable the logger logging level
	DISABLED

	// FATAL logging level
	FATAL

	// ERROR logging level
	ERROR

	// WARN logging level
	WARN

	// INFO logging level
	INFO

	// DEBUG logging level
	DEBUG

	// TRACE logging level
	TRACE
)

Define the logging levels

func GlobalLevel

func GlobalLevel() Level

GlobalLevel will return the current level that has been set globally for all loggers

func LevelFromString

func LevelFromString(ll string) Level

LevelFromString will convert the string to a Level If the string cannot be converted, it will return NONE

func (Level) String

func (l Level) String() string

type LevelNotifierHandler

type LevelNotifierHandler func(Level)

LevelNotifierHandler is used to notify any interested golog.Logger impls that the global level has changed

type Logger

type Logger interface {

	// SetLevel will set the logging level for this logger
	SetLevel(level Level)

	// Fatal prints a Fatal level message
	Fatal(format string, params ...interface{})

	// Error prints an Error level message
	Error(format string, params ...interface{})

	// Warn prints a Warn level message
	Warn(format string, params ...interface{})

	// Info prints an Info level message
	Info(format string, params ...interface{})

	// Debug prints a Debug level message
	Debug(format string, params ...interface{})

	// Trace prints a Trace level message
	Trace(format string, params ...interface{})
}

Logger defines a basic set of logging functions For formatting refer to the underlying log implementation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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