Documentation ¶
Overview ¶
`Tracey` is a simple library which allows for much easier function enter / exit logging
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var RE_detectFN = regexp.MustCompile(`\$FN`)
View Source
var RE_stripFnPreamble = regexp.MustCompile(`^.*\.(.*)$`)
Define a global regex for extracting function names
Functions ¶
func New ¶
Main entry-point for the tracey lib. Calling New with nil will result in the default options being used.
Example (ChangeIndentLevel) ¶
G, O := New(&Options{SpacesPerIndent: 1}) second := func() { defer G(O("SECOND")) } first := func() { defer G(O("FIRST")) second() } first()
Output: [ 0]ENTER: FIRST [ 1] ENTER: SECOND [ 1] EXIT: SECOND [ 0]EXIT: FIRST
Example (CustomMessage) ¶
G, O := New(&Options{EnterMessage: "en - ", ExitMessage: "ex - "}) second := func() { defer G(O("SECOND", time.Now())) } first := func() { defer G(O("FIRST")) second() } first()
Output: [ 0]en - FIRST [ 1] en - SECOND [ 1] ex - SECOND [ 0]ex - FIRST
Example (NoOptions) ¶
Examples
G, O := New(nil) second := func() { defer G(O("SECOND")) } first := func() { defer G(O("FIRST")) second() } first()
Output: [ 0]ENTER: FIRST [ 1] ENTER: SECOND [ 1] EXIT: SECOND [ 0]EXIT: FIRST
Types ¶
type Options ¶
type Options struct { // Setting "DisableTracing" to "true" will cause tracey to return // no-op'd functions for both exit() and enter(). The default value // for this is "false" which enables tracing. DisableTracing bool // Setting the "CustomLogger" to nil will cause tracey to log to // os.Stdout. Otherwise, this is a pointer to an object as returned // from `log.New(...)`. CustomLogger Logger // Setting "DisableDepthValue" to "true" will cause tracey to not // prepend the printed function's depth to enter() and exit() messages. // The default value is "false", which logs the depth value. DisableDepthValue bool // Setting "DisableNesting" to "true" will cause tracey to not indent // any messages from nested functions. The default value is "false" // which enables nesting by prepending "SpacesPerIndent" number of // spaces per level nested. DisableNesting bool SpacesPerIndent int `default:"2"` // Setting "DisplayParentsCaller" to "true" will cause tracey to display // full caller tree for a function DisplayParentsCaller bool // Setting "EnterMessage" or "ExitMessage" will override the default // value of "Enter: " and "EXIT: " respectively. EnterMessage string `default:"ENTER: "` ExitMessage string `default:"EXIT: "` ElapsedMessage string `default:", took: "` // contains filtered or unexported fields }
These options represent the various settings which tracey exposes. A pointer to this structure is expected to be passed into the `tracey.New(...)` function below.
Click to show internal directories.
Click to hide internal directories.