clog

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2019 License: GPL-3.0 Imports: 5 Imported by: 1

README

clog

pipeline status coverage report Contributor Covenant

Implementation of custom logging.

Install

go get -u lab.madbox.synology.me/gophers/clog

Examples

// Use Prefln for messages with a static prefix
clog.Prefln("warn", "This is the message")
// Example output: 2006/01/02 15:04:05 [warn] This is the message

// When passing a format string, use Preff
clog.Preff("warn", "This is the %s\n", "message")
// Example output: 2006/01/02 15:04:05 [warn] This is the message

// The output of the Traceln/Tracef and Verbln/Verbf functions is discarded if
// verbosity is disabled.
// To enable verbose output, if it is not enabled yet, do:
if !clog.GetVerbosity() {
  clog.EnableVerbosity()
}

// Additionally these functions don't take a prefix, since the name of the
// calling function is used.
// This is a more complex example using both Traceln and Tracef:
func test1() {
  clog.Traceln("This is Traceln output.")
}

func test2() {
  clog.Tracef("This is %s output.\n", "Tracef")
}

func main() {
  clog.EnableVerbosity()
  test1()
  test2()
}
// Example output:
// 2006/01/02 15:04:05 [main.test1] This is Traceln output.
// 2006/01/02 15:04:05 [main.test2] This is Tracef output.

Contributing

When contributing to this project, please note our Code of Conduct.

License

The GNU General Public License v3.0 (GPLv3) - see LICENSE for more details

Documentation

Overview

Package clog implements custom logging.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deff added in v0.3.0

func Deff(format string, a ...interface{})

Deff is a fmt.Printf() using the default prefix.

func Defln added in v0.3.0

func Defln(a ...interface{})

Defln is a fmt.Println() using the default prefix.

func DisableVerbosity

func DisableVerbosity()

DisableVerbosity disables verbose output.

func EnableVerbosity

func EnableVerbosity()

EnableVerbosity enables verbose output.

func GetVerbosity

func GetVerbosity() bool

GetVerbosity returns true if verbose output is enabled.

func Preff

func Preff(prefix string, format string, a ...interface{})

Preff is a fmt.Printf() using the default prefix plus given prefix.

func Prefln

func Prefln(prefix string, a ...interface{})

Prefln is a fmt.Println() using the default prefix plus given prefix.

func SetPrefix added in v0.4.0

func SetPrefix(f func() string)

SetPrefix takes a string returning function to override the default prefix.

func Tracef

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

Tracef is a verbose Printf() using the default prefix plus the calling function's name as prefix.

func Traceln

func Traceln(a ...interface{})

Traceln is a verbose Println() using the default prefix plus the calling function's name as prefix.

func VerbDeff added in v0.5.0

func VerbDeff(format string, a ...interface{})

VerbDeff is a verbose fmt.Printf() using the default prefix.

func VerbDefln added in v0.5.0

func VerbDefln(a ...interface{})

VerbDefln is a verbose fmt.Println() using the default prefix.

func Verbf added in v0.2.0

func Verbf(format string, a ...interface{})

Verbf is a verbose Printf().

Example
Verbf("%s %s", "Discarded", "Verbf output\n")
EnableVerbosity()
Verbf("%s %s", "Verbf", "output\n")
DisableVerbosity()
Output:

Verbf output

func Verbln added in v0.2.0

func Verbln(a ...interface{})

Verbln is a verbose Println().

Example
Verbln("Discarded Verbln output")
EnableVerbosity()
Verbln("Verbln output")
DisableVerbosity()
Output:

Verbln output

Types

This section is empty.

Jump to

Keyboard shortcuts

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