tracerx

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

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

Go to latest
Published: Sep 27, 2017 License: MIT Imports: 8 Imported by: 275

README

tracerx

Tracerx is a simple tracing package that logs messages depending on environment variables. It is very much inspired by git's GIT_TRACE mechanism.

GoDoc

Installation

  go get github.com/rubyist/tracerx

Example

tracerx.DefaultKey = "FOO"
tracerx.Printf("send message")

tracerx.PrintfKey("BAR", "do a thing")

t := time.Now()
// Do some stuff
tracerx.PerformanceSince("BAR", "command x", t)

This example will send tracing output based on the environment variables FOO_TRACE and BAR_TRACE.

The values control where the tracing is output as follows:

unset, 0, or "false":   no output
1, 2:                   stderr
absolute path:          output will be written to the file
3 - 10:                 output will be written to that file descriptor

If an associated BAR_TRACE_PERFORMANCE is set to 1 or "true", the PerformanceSince line will output timing information.

Keys can also be disabled. See the GoDoc for full API documentation.

Bugs, Issues, Feedback

Right here on GitHub: https://github.com/rubyist/tracerx

Documentation

Overview

Package tracerx implements a simple tracer function that uses environment variables to control the output. It is a generalized package inspired by git's GIT_TRACE mechanism.

By default, tracerx will look for the TRACERX_TRACE environment variable. The default can by changed by setting the DefaultKey.

The values control where the tracing is output as follows:

unset, 0, or "false":   no output
1, 2:                   stderr
absolute path:          output will be written to the file
3 - 10:                 output will be written to that file descriptor

By default, messages will be prefixed with "trace: ". This prefix can be modified by setting Prefix.

Each key can have an associated performance key, e.g. TRACERX_TRACE_PERFORMANCE. If this key is 1 or "true" performance output will be written to the same output as the tracing output.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultKey = "TRACERX"
	Prefix     = "trace: "
)

Functions

func Disable

func Disable(key string)

Disable will disable tracing for the given key, regardless of the environment variable

func Enable

func Enable(key string)

Enable will enable tracing for the given key, regardless of the environment variable

func PerformanceSince

func PerformanceSince(what string, t time.Time)

PerformanceSince writes out the time since the given time, if tracing for the default key is enabled and the performance key is set

func PerformanceSinceKey

func PerformanceSinceKey(key, what string, t time.Time)

PerformanceSince writes out the time since the given time, if tracing for the given key is enabled and the performance key is set

func Printf

func Printf(format string, args ...interface{})

Printf writes a trace message for the DefaultKey

func PrintfKey

func PrintfKey(key, format string, args ...interface{})

PrintfKey writes a trace message for the given key

Types

This section is empty.

Jump to

Keyboard shortcuts

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