Documentation ¶
Overview ¶
Package diag implements a fixed-size ring buffer to store diagnostic text in.
Similar to the "log" package, there exists a default, global Diag value. Also by default "diag" will receive a copy of output sent by the default "log" logger.
Diag priorities safety and convenience.
"Convenience" is defined as being at least as easy as "log" to use, as to maximize the amount of instrumentation in general by minimizing its burden on the programmer.
"Safety" is defined as:
- Being safe to call anywhere in a program.
- Being fast enough to call almost anywhere in a program.
- Data is synchronized.
- Storage is fixed-size.
- The implementation has no known bugs to spoil the instrumented program.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultDiag = New(1024 * 1024)
Functions ¶
Types ¶
type Diag ¶
type Diag struct {
// contains filtered or unexported fields
}
func (*Diag) Contents ¶
Contents copies and returns elements in the ring buffer. Each call to Log/Logf/Write is represented as an element of the returned slice.
func (*Diag) Log ¶
func (dg *Diag) Log(values ...interface{})
Log writes to the ring buffer. Arguments are handled in the manner of fmt.Print.
Example ¶
package main import ( "fmt" "github.com/heroku/hsup/diag" ) func main() { dg := diag.New(1024) dg.Log("the answer", 42, nil) fmt.Println(dg.Contents()) dg.Log("what is six times nine") fmt.Println(dg.Contents()) }
Output: [the answer 42 <nil>] [the answer 42 <nil> what is six times nine]
func (*Diag) Logf ¶
Logf writes to the ring buffer. Arguments are handled in the manner of fmt.Printf.
Example ¶
package main import ( "fmt" "github.com/heroku/hsup/diag" ) func main() { dg := diag.New(1024) dg.Logf("%v %T", "the type of nil is", nil) fmt.Println(dg.Contents()) }
Output: [the type of nil is <nil>]