trace

package module
Version: v0.0.0-...-8e968dc Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

Go Trace Utility

Build Status Coverage Status GoDoc Open Source Helpers

Install

$ go get github.com/dizitart/trace

Usage

package main

import (
	"fmt"
	"github.com/dizitart/trace"
	"time"
)

func main() {
	fmt.Println("Hello World")

	// Set up tracing
	trace.ENABLE_TRACE = true
	trace.SetOut(trace.OUT_ALL)
	trace.TRACE_FILE_PATH = "/temp/trace.log"
	trace.SetMessageFormat(trace.PRINT_FILE | trace.PRINT_LINE | trace.PRINT_PROC)

	someString := "Hello World"
	// assert
	trace.Assert(someString == "hello world")
	// formatted assertion
	trace.Assertf(someString == "hello world", "Assertion Failed! at %v", time.Now())

	// write
	trace.Write(someString)
	// formatted write
	trace.Writef("Tracing at %v for value %s", time.Now(), someString)
}

Documentation

https://godoc.org/github.com/dizitart/trace

License

Copyright (c) 2014 Dizitart

Released under the Apache License, Version 2.0

Documentation

Index

Constants

View Source
const (
	// Switches off other information in trace message
	PRINT_NONE MessageFormat = 0
	// Switch to print time
	PRINT_TIME MessageFormat = 1
	// Switch to print function name
	PRINT_PROC MessageFormat = 2
	// Switch to print source file name
	PRINT_FILE MessageFormat = 4
	// Switch yo print current line number
	PRINT_LINE MessageFormat = 8
	// Switches on all formatting
	PRINT_ALL MessageFormat = PRINT_TIME | PRINT_PROC | PRINT_FILE | PRINT_LINE

	// Switches off printing
	OUT_NONE OutputChannel = 0
	// Switch to print to Stdout
	OUT_STD OutputChannel = 1
	// Switch to print to File
	OUT_FILE OutputChannel = 2
	// Switches on both File & Stdout printing
	OUT_ALL OutputChannel = OUT_STD | OUT_FILE
)

Variables

View Source
var (
	// Flag to enable or disable the Tracing
	ENABLE_TRACE bool = false
	// Trace log file path
	TRACE_FILE_PATH string
)

Use these configuration variables to set tracing parameters

Functions

func Assert

func Assert(condition bool)

Checks for a condition; if the condition is false, writes a trace message that shows the call stack.

func Assertf

func Assertf(condition bool, format string, variables ...interface{})

Checks for a condition; if the condition is false, writes a specified message after formatting it according to a format specifier that shows the call stack.

func SetMessageFormat

func SetMessageFormat(messageFormat MessageFormat)

Sets trace message format

func SetOut

func SetOut(out OutputChannel)

Sets output channels (Stdout, File)

func Write

func Write(variable interface{})

Writes information about current source file, line number and input variable

func Writef

func Writef(format string, variables ...interface{})

Writes information about current source file, line number and input variable after formatting it according to a format specifier

Types

type MessageFormat

type MessageFormat byte

type OutputChannel

type OutputChannel byte

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL