clog

package module
v0.0.0-...-6446106 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2018 License: MIT Imports: 5 Imported by: 6

README

clog

Simple conditional logging for go.

See the documentation.

Installation

$ go get github.com/32bitkid/clog

Examples

clog is silent by default...

log := NewLog("package")
log.Println("This is a log")
fmt.Println("<end>")
$ go run test.go
<end>

...but can easily be configured to show all registered loggers...

log := NewLog("package")

log.Println("This is a log")
fmt.Println("<end>")
$ DEBUG=* go run test.go
package: This is a log!
<end>

...or only show logs from a specific namespace...

 foolog := NewLog("foo")
 barlog := NewLog("bar")
 foolog.Println("This is a log")
 barlog.Println("This is a log")
 fmt.Println("<end>")
$ DEBUG=foo go run test.go
foo: This is a log
<end>

...and even match namespaces with wildcards.

barlog := NewLog("foo:bar")
bazlog := NewLog("foo:baz")
quxlog := NewLog("qux")

barlog.Println("This is a log")
bazlog.Println("This is a log")
quxlog.Println("This is a log")

fmt.Println("<end>")
$ DEBUG=foo:* go run test.go
foo:bar This is a log
foo:baz This is a log
<end>

Documentation

Overview

Simple conditional logging for go.

Leverages the environment variable "DEBUG" to conditionally output statements.

clog is silent by default...

Code:

log := NewLog("package")
log.Println("This is a log")
fmt.Println("<end>")

Output:

$ go run test.go
<end>

...but can easily be configured to show all registered loggers...

Code:

log := NewLog("package")

log.Println("This is a log")
fmt.Println("<end>")

Output:

$ DEBUG=* go run test.go
package: This is a log!
<end>

...or only show logs from a specific namespace...

Code:

foolog := NewLog("foo")
barlog := NewLog("bar")
foolog.Println("This is a log")
barlog.Println("This is a log")
fmt.Println("<end>")

Output:

$ DEBUG=foo go run test.go
foo: This is a log
<end>

...and even match namespaces with wildcards.

Code:

barlog := NewLog("foo:bar")
bazlog := NewLog("foo:baz")
quxlog := NewLog("qux")

barlog.Println("This is a log")
bazlog.Println("This is a log")
quxlog.Println("This is a log")

fmt.Println("<end>")

Output:

$ DEBUG=foo:* go run test.go
foo:bar This is a log
foo:baz This is a log
<end>

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
}

Logger interface collects the basic methods for logging.

func NewLog

func NewLog(ns string) Logger

NewLog creates a conditional logger that writes to os.Stderr

func NewLogWriter

func NewLogWriter(ns string, w io.Writer) Logger

NewLogWriter creates a logger that will write to the given io.Writer

Jump to

Keyboard shortcuts

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