jog

package module
v0.0.0-...-863fdf1 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2016 License: MIT Imports: 6 Imported by: 3

README

========================================== jog -- Structured logging library for Go

Jog is a simple, minimal, logging library for Go. It's meant for backend services that generate a lot of logs, where ease of processing is more important than human eyeball friendliness.

  • the right way is the easy way; event types are differentiated for you
  • log rotation, compression, and such belong outside the process
  • don't repeat identical values in every log message, e.g. hostname (these can be added at indexing time)
  • can be (realtime) postprocessed for more readable messages

Usage:

log := jog.New(nil)

type cowbell struct {
    More bool
}
log.Event(cowbell{More: true})

type sound struct {
    Description string
}
log.Event(sound{Description: "dynamite"})
log.Event(sound{Description: "loud"})
log.Event(sound{Description: "distracting"})

Define a new type for every type of event you emit. Don't reuse the same name within the package (Go helps you with this! They're already identifiers!).

For more, see the API documentation at http://godoc.org/github.com/tv42/jog and the example code in https://github.com/tv42/jog/blob/master/example/hello.go

Documentation

Overview

Jog is a structured logging library outputting JSON messages one per line.

Each logged event will have the following fields:

  • Time: ISO 8601 format
  • Type: type of the Go variable representing the event
  • Data: details of the event

The format for the type is "IMPORTPATH#TYPE", for example "github.com/tv42/jog#unencodable".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Destination to which log events will be written.
	Out io.Writer
}

type Logger

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

A Logger represents a logger that takes Go variables as events and writes them to an io.Writer as JSON. Each logging operation makes a single call to the Writer's Write method and contains one complete log event. For high throughput logging, you may want to use a bufio.Writer. A Logger can be used simultaneously from multiple goroutines, Write calls happen one at a time.

func New

func New(conf *Config) *Logger

New creates a new Logger. Configuration is optional.

func (*Logger) Event

func (l *Logger) Event(data interface{})

Record an event on this Logger. Data may be any value that can be JSON encoded.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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