diag

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2015 License: BSD-2-Clause Imports: 6 Imported by: 0

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

View Source
var DefaultDiag = New(1024 * 1024)

Functions

func Contents

func Contents() []string

func Log

func Log(values ...interface{})
Example
package main

import (
	"github.com/heroku/hsup/diag"
)

func main() {
	diag.Log("世界")
	diag.Log("ascii")
}
Output:

func Logf

func Logf(s string, values ...interface{})
Example
package main

import (
	"github.com/heroku/hsup/diag"
)

func main() {
	diag.Logf("%v %v", "世界", "ascii")
}
Output:

Types

type Diag

type Diag struct {
	// contains filtered or unexported fields
}

func New

func New(retentionSz int) *Diag

New creates a Diag value, holding retentionSz bytes.

func (*Diag) Contents

func (dg *Diag) Contents() []string

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

func (dg *Diag) Logf(f string, rest ...interface{})

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>]

func (*Diag) Write

func (dg *Diag) Write(p []byte) (n int, err error)

Write implements the Writer interface.

Jump to

Keyboard shortcuts

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