dlog

package module
v0.0.0-...-97d876b Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2017 License: Apache-2.0 Imports: 3 Imported by: 10

README

dlog GoDoc Go Report Card

Simple build-time controlled debug log

How to use

Unbuffered
package main

import "github.com/kirillDanshin/dlog"

func main() {
	a := []int{2, 4, 8, 16, 32, 64, 128, 256, 512}
	b := "some string"
	
	dlog.D(a)		// D'ump `a`
	dlog.P(b)		// P'rint `b`
	dlog.F("%s format", b)	// F'ormatted print
	dlog.Ln(b)		// print'Ln `b`
}
Buffered
package main

import "github.com/kirillDanshin/dlog"

func main() {
	log := dlog.NewBuffered()
	defer log.Release()
	
	log.D(a)		// D'ump `a`
	log.P(b)		// P'rint `b`
	log.F("%s format", b)	// F'ormatted print
	log.Ln(b)		// print'Ln `b`

	dlog.Ln(log) // or fmt.Println("log") etc.
}

Release

To disable logging in release build just run

	go build

Debug

To enable logging in debug build run

	go build -tags "debug"

Documentation

Overview

Package dlog is a build-time enabled or disabled logger. Godoc shows disabled state because it built in by default.

Index

Constants

View Source
const (
	// CallerUnknown returned when caller isn't determined
	CallerUnknown = "UNKNOWN"

	// StateEnabled is to check if dlog.State enabled
	StateEnabled = "enabled"
	// StateDisabled is to check if dlog.State disabled
	StateDisabled = "disabled"
)
View Source
const State = "disabled"

State handles dlog state. Can be "disabled" or "enabled".

Variables

This section is empty.

Functions

func D

func D(v ...interface{})

D dumps a value

func F

func F(f string, v ...interface{})

F is a build-time disabled printf

func Ln

func Ln(v ...interface{})

Ln is a build-time disabled println

func P

func P(v ...interface{})

P is a build-time disabled print

Types

type Buffered

type Buffered struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Buffered thread-safe dlog

func NewBuffered

func NewBuffered() *Buffered

NewBuffered dlog

func (*Buffered) D

func (b *Buffered) D(v ...interface{})

D dumps a value

func (*Buffered) F

func (b *Buffered) F(f string, v ...interface{})

F is a build-time enabled printf

func (*Buffered) Ln

func (b *Buffered) Ln(v ...interface{})

Ln is a build-time enabled println

func (*Buffered) P

func (b *Buffered) P(v ...interface{})

P is a build-time enabled print

func (*Buffered) Release

func (b *Buffered) Release()

Release the buffer for dlog

func (*Buffered) String

func (b *Buffered) String() string

type Caller

type Caller struct {
	File     string
	Line     int
	FuncName string
}

Caller info

func GetCaller

func GetCaller(_ ...int) (*Caller, bool)

GetCaller is a build-time disabled caller determining. Returns caller's file, line and func name

func (*Caller) String

func (c *Caller) String() string

type WithCaller

type WithCaller struct{}

WithCaller is a dlog with caller info prefix

func (*WithCaller) D

func (*WithCaller) D(v ...interface{})

D dumps a value

func (*WithCaller) F

func (*WithCaller) F(f string, v ...interface{})

F is a build-time enabled printf

func (*WithCaller) Ln

func (*WithCaller) Ln(v ...interface{})

Ln is a build-time enabled println

func (*WithCaller) P

func (*WithCaller) P(v ...interface{})

P is a build-time enabled print

Jump to

Keyboard shortcuts

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