log

package
v0.0.0-...-cdd6f12 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2019 License: GPL-3.0, GPL-3.0 Imports: 4 Imported by: 0

README

gitlab.com/coygo/log

An alternative Go logger.

Package log wraps Go's log package and provides a simple level-able and color-able logging package. It has 5 levels of logging in order from highest to lowest as listed below.

Error > Warning > Info > Debug > Trace

Package log is licensed in GPLv3.

Example

package main

import "gitlab.com/coygo/log"

func main() {
	log.SetFlags(log.LstdFlags | log.Ltrace)

	log.Trace("A trace level logging event in color magenta.")
	log.Debugf("A debug level one. %s", "It works like fmt.Printf(), but colored in blue.")
	log.Infoln("A info level one works like fmt.Println(), but colored in green.")
	log.Warning("A yellow one.")
	log.Error("A error level event should be in red.")
	log.Print("No color logging event. It is a log.Print() from Go official log package in fact.")
	log.Fatal("A Go official's log.Fatal() indeed. In fact, the program will stop here.")
	log.Panic("This line will never reached.")
}

Install

go get -u gitlab.com/coygo/log

Documentation

Overview

Package log wraps Go's log package and provide a simple level-able and color-able logging package. It has 5 levels of logging in order from highest to lowest as listed below. The default is Info.

Error > Warning > Info > Debug > Trace

Package log is licensed in GPLv3.

Index

Constants

View Source
const (
	Ldate         = 1 << iota // the date in the local time zone: 2009/01/23
	Ltime                     // the time in the local time zone: 01:23:23
	Lmicroseconds             // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                 // full file name and line number: /a/b/c/d.go:23
	Lshortfile                // final file name element and line number: d.go:23. overrides Llongfile
	LUTC                      // if Ldate or Ltime is set, use UTC rather than the local time zone
	Ltrace                    // Ltrace indicates logging trace level event
	Ldebug                    // Ldebug indicates logging debug level event
	Linfo                     // Linfo indicates logging info level event
	Lwarning                  // Lwarning indicates logging warning level event
	Lerror                    // Lerror indicates logging error level event

	LstdFlags = Ldate | Ltime | Linfo // initial values for the standard logger
)

These flags define which text to prefix to each log entry generated by the Logger. Bits are or'ed together to control what's printed. There is no control over the order they appear (the order listed here) or the format they present (as described in the comments). The prefix is followed by a colon only when Llongfile or Lshortfile is specified. For example, flags Ldate | Ltime (or LstdFlags) produce,

2009/01/23 01:23:23 message

while flags Ldate | Ltime | Lmicroseconds | Llongfile produce,

2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message

Variables

View Source
var Fatal = log.Fatal // func Fatal(v ...interface{})

Fatal is an alias to Go's log.Fatal, which prints logging event to the standard logger followed by a call to os.Exit(1). Arguments are handled in the manner of fmt.Print.

NOTE: No color output.

View Source
var Fatalf = log.Fatalf // func Fatalf(format string, v ...interface{})

Fatalf is an alias to Go's log.Fatalf, which prints logging event to the standard logger followed by a call to os.Exit(1). Arguments are handled in the manner of fmt.Printf.

NOTE: No color output.

View Source
var Fatalln = log.Fatalln // func Fatalln(v ...interface{})

Fatalln is an alias to Go's log.Fatalln, which prints logging event to the standard logger followed by a call to os.Exit(1). Arguments are handled in the manner of fmt.Println.

NOTE: No color output.

View Source
var Panic = log.Panic // func Panic(v ...interface{})

Panic is an alias to Go's log.Panic, which prints logging event to the standard logger followed by a call to panic(). Arguments are handled in the manner of fmt.Print.

NOTE: No color output.

View Source
var Panicf = log.Panicf // func Panicf(format string, v ...interface{})

Panicf is an alias to Go's log.Panicf, which prints logging event to the standard logger followed by a call to panic(). Arguments are handled in the manner of fmt.Printf.

NOTE: No color output.

View Source
var Panicln = log.Panicln // func Panicln(v ...interface{})

Panicln is an alias to Go's log.Panicln, which prints logging event to the standard logger followed by a call to panic(). Arguments are handled in the manner of fmt.Println.

NOTE: No color output.

View Source
var Print = log.Print // func Print(v ...interface{})

Print is an alias to Go's log.Print, which prints logging event to the standard logger. Arguments are handled in the manner of fmt.Print.

NOTE: No color output.

View Source
var Printf = log.Printf // func Printf(format string, v ...interface{})

Printf is an alias to Go's log.Printf, which prints logging event to the standard logger. Arguments are handled in the manner of fmt.Printf.

NOTE: No color output.

View Source
var Println = log.Println // func Println(v ...interface{})

Println is an alias to Go's log.Println, which prints logging event to the standard logger. Arguments are handled in the manner of fmt.Println.

NOTE: No color output.

Functions

func Debug

func Debug(v ...interface{})

Debug writes debug level logging event to the standard logger. Arguments are handled in the manner of fmt.Print.

func Debugf

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

Debugf writes debug level logging event to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Debugln

func Debugln(v ...interface{})

Debugln writes debug level logging event to the standard logger. Arguments are handled in the manner of fmt.Println.

func Error

func Error(v ...interface{})

Error writes error level logging event to the standard logger. Arguments are handled in the manner of fmt.Print.

func Errorf

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

Errorf writes error level logging event to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Errorln

func Errorln(v ...interface{})

Errorln writes error level logging event to the standard logger. Arguments are handled in the manner of fmt.Println.

func Info

func Info(v ...interface{})

Info writes info level logging event to the standard logger. Arguments are handled in the manner of fmt.Print.

func Infof

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

Infof writes info level logging event to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Infoln

func Infoln(v ...interface{})

Infoln writes info level logging event to the standard logger. Arguments are handled in the manner of fmt.Println.

func SetFlags

func SetFlags(flag int)

SetFlags sets the output flags for the standard logger.

func Trace

func Trace(v ...interface{})

Trace writes trace level logging event to the standard logger. Arguments are handled in the manner of fmt.Print.

func Tracef

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

Tracef writes trace level logging event to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Traceln

func Traceln(v ...interface{})

Traceln writes trace level logging event to the standard logger. Arguments are handled in the manner of fmt.Println.

func Warning

func Warning(v ...interface{})

Warning writes warning level logging event to the standard logger. Arguments are handled in the manner of fmt.Print.

func Warningf

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

Warningf writes warning level logging event to the standard logger. Arguments are handled in the manner of fmt.Printf.

func Warningln

func Warningln(v ...interface{})

Warningln writes warning level logging event to the standard logger. Arguments are handled in the manner of fmt.Println.

Types

This section is empty.

Jump to

Keyboard shortcuts

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