logger

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: Apache-2.0 Imports: 7 Imported by: 7

README

go-logger

Build Status

This repository contains a small golang logger libary.

You can download the source via go.

go get github.com/volker-raschek/go-logger

Usage

package main

import (
  "git.cryptic.systems/volker.raschek/go-logger"
)

func main() {
  myLogger := logger.NewLogger(logger.LogLevelDebug)
  myLogger.Debug("Debug output")
  myLogger.Info("Info output")
  myLogger.Warn("Warn output")
  myLogger.Error("Error output")
  myLogger.Fatal("Fatal output")
}

Produce the following output:

$ go run main.go
2019/09/24 15:25:34 DEBUG: Debug output
2019/09/24 15:25:34 INFO: Info output
2019/09/24 15:25:34 WARN: Warn output
2019/09/24 15:25:34 ERROR: Error output
2019/09/24 15:25:34 FATAL: Fatal output
exit status 1

If the function myLogger.Fatal() is called, the program is terminated with exit code 1.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnkownLogLevel = errors.New("Unkown loglevel")

ErrUnkownLogLevel will be returned, if the loglevel can not be parsed and is unkown

Functions

This section is empty.

Types

type LogLevel

type LogLevel int

LogLevel describes which level of logs will be written on the writers

const (
	// LogLevelDebug instruct the logger to write debug, info, warn, error and
	// fatal logs into the defined writers
	LogLevelDebug LogLevel = iota + 1

	// LogLevelInfo instruct the logger to write info, warn, error and fatal logs
	// into the defined writers
	LogLevelInfo

	// LogLevelWarn instruct the logger to write warn, error and fatal logs into
	// the defined writers
	LogLevelWarn

	// LogLevelError instruct the logger to write error and fatal logs into the
	// defined writers
	LogLevelError

	// LogLevelFatal instruct the logger to write only fatal logs into the
	// defined writer
	LogLevelFatal
)

func ParseLogLevel

func ParseLogLevel(logLevel string) (LogLevel, error)

ParseLogLevel parse the matching LogLevel from a string variable and returns it as LogLevel constante. - 1, debug, DEBUG => LogLevelDebug - 2, info, INFO => LogLevelInfo - 3, warn, WARN => LogLevelWARN - 4, error, ERROR => LogLevelError - 5, fatal, FATAL => LogLevelFatal

type Logger

type Logger interface {
	Debug(string, ...interface{})
	Info(string, ...interface{})
	Warn(string, ...interface{})
	Error(string, ...interface{})
	Fatal(string, ...interface{})
}

Logger interface to define a logger

func NewCustomLogger

func NewCustomLogger(loglevel LogLevel, out io.Writer, err io.Writer) Logger

NewCustomLogger returns a new logger which writes his logs on writer out. Error and fatal logs will be written on writer err.

func NewLogger

func NewLogger(logLevel LogLevel) Logger

NewLogger returns a new logger which writes his logs on stdout. Error and fatal logs will be written on stderr.

func NewSilentLogger

func NewSilentLogger() Logger

NewSilentLogger returns a new logger which discard all his logs

Jump to

Keyboard shortcuts

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