log

package module
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2019 License: MIT Imports: 2 Imported by: 3

README

Log

GoDoc Go Report Card Build Status

  • It ehnances Golang's logger with levels.
  • It wraps Golang's log package

Usage

Download it

go get -u github.com/libgolang/log

In Code

import "github.com/libgolang/log"


func main() {

	log.SetLevel(log.LevelDebug) // defaults to log.LevelInfo

	someVar := "example"

	log.Debug("message", someVar)
	log.Debugf("message: %s", someVar)

	log.Info("message", someVar)
	log.Infof("message: %s", someVar)

	log.Warn("message", someVar)
	log.Warnf("message: %s", someVar)

	log.Error("message", someVar)
	log.Errorf("message: %s", someVar)

	log.Fatal("message", someVar)
	log.Fatalf("message: %s", someVar)
}

Why

  • Does no require 3rd party libraries

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug calls Golang's log.Print which in turn calls Output to print to the standard logger. It will only call log.Printf if the log level is set Debug or above. Arguments are handled in the manner of fmt.Print.

func Debugf

func Debugf(format string, v ...interface{})

Debugf calls Golang's log.Printf which in turn calls Output to print to the standard logger. It will only call log.Printf if the log level is set Debug or above. Arguments are handled in the manner of fmt.Printf.

func Error

func Error(v ...interface{})

Error calls Golang's log.Print which in turn calls Output to print to the standard logger. It will call log.Printf if the log level is set Error or above. Arguments are handled in the manner of fmt.Print.

func Errorf

func Errorf(format string, v ...interface{})

Errorf calls Golang's log.Printf which in turn calls Output to print to the standard logger. It will call log.Printf if the log level is set Error or above. Arguments are handled in the manner of fmt.Printf.

func Fatal

func Fatal(v ...interface{})

Fatal is equivalent to Print() followed by a call to os.Exit(1).

func Fatalf

func Fatalf(format string, v ...interface{})

Fatalf is equivalent to Printf() followed by a call to os.Exit(1).

func Info

func Info(v ...interface{})

Info calls Golang's log.Print which in turn calls Output to print to the standard logger. It will only call log.Printf if the log level is set Info or above. Arguments are handled in the manner of fmt.Print.

func Infof

func Infof(format string, v ...interface{})

Infof calls Golang's log.Printf which in turn calls Output to print to the standard logger. It will only call log.Printf if the log level is set Info or above. Arguments are handled in the manner of fmt.Printf.

func SetLevel

func SetLevel(level Level)

SetLevel is used to set the logging level. This library only support setting logging level globally. The possible arguments to this function are: LevelFatal, LevelError, LevelWarn, LevelInfo, LevelDebug and LevelTrace.

func Trace

func Trace(v ...interface{})

Trace calls Golang's log.Print which in turn calls Output to print to the standard logger. It will only call log.Printf if the log level is set Trace or above. Arguments are handled in the manner of fmt.Print.

func Tracef

func Tracef(format string, v ...interface{})

Tracef calls Golang's log.Printf which in turn calls Output to print to the standard logger. It will only call log.Printf if the log level is set Trace or above. Arguments are handled in the manner of fmt.Printf.

func Warn

func Warn(v ...interface{})

Warn calls Golang's log.Print which in turn calls Output to print to the standard logger. It will call log.Printf if the log level is set Warn or above. Arguments are handled in the manner of fmt.Print.

func Warnf

func Warnf(format string, v ...interface{})

Warnf calls Golang's log.Printf which in turn calls Output to print to the standard logger. It will call log.Printf if the log level is set Warn or above. Arguments are handled in the manner of fmt.Printf.

Types

type Level

type Level int

Level Log level to use in `SetLevel()` function

const (
	// LevelFatal to be used with `SetLevel(LevelFatal)`, to set log level to only Fatal calls
	LevelFatal Level = iota

	// LevelError to be used with `SetLevel(LevelError)`, to set log level to Error and Fatal calls
	LevelError Level = iota

	// LevelWarn to be used with `SetLevel(LevelWarn)`, to set log level to Error, Fatal and Warn calls
	LevelWarn Level = iota

	// LevelInfo to be used with `SetLevel(LevelInfo)`, to set log level to Error, Fatal, Warn and Info cals
	LevelInfo Level = iota

	// LevelDebug to be used with `SetLevel(LevelDebug)`, to set log level to Error, Fatal, Warn, Info and Debug calls.
	LevelDebug Level = iota

	// LevelTrace to be used with `SetLevel(LevelTrace)`, it enables all log levels.
	LevelTrace Level = iota
)

func ParseLevel

func ParseLevel(strLevel string) Level

ParseLevel takes as string and return the corresponding level. The strLevel argument is case insensitive. The strLevel argument just needs to begin with one of the logging level names. Logging level names are TRACE, DEBUG, INFO, WARN, ERROR and FATAL

e.g.: ParseLevel("debug") // LevelDebug e.g.: ParseLevel("DEBUG") // LevelDebug e.g.: ParseLevel("debugging") // LevelDebug e.g.: ParseLevel("warn") // LevelWarn e.g.: ParseLevel("warni") // LevelWarn e.g.: ParseLevel("warnin") // LevelWarn e.g.: ParseLevel("warning") // LevelWarn e.g.: ParseLevel("WARNING") // LevelWarn

func (Level) String

func (l Level) String() string

Jump to

Keyboard shortcuts

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