logger

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package logger includes the core implemenation of unilog's logging process.

Index

Constants

View Source
const (
	// Version is the Unilog version. Reported in emails and in
	// response to --version on the command line. Can be overriden
	// by the Version field in a Unilog object.
	Version = "1.0.2"
	// DefaultBuffer is the default size (in lines) of the
	// in-process line buffer
	DefaultBuffer = 1 << 12
)

Variables

Stats is Unilog's statsd client.

Functions

func IndependentCount

func IndependentCount(client Client, name string, value int64, tags []string, rate float64) error

IndependentCount is a wrapper for the statsd.Count method. It will emit the normal metric in addition to a metric for each tag in independenttags with all global tags and that tag attached (along with tags passed as an argument to IndependentCount). Metric names will be of the form metricName.tag. Will short-circuit upon encountering an error.

func SetCommitDate added in v1.0.1

func SetCommitDate(date time.Time)

SetCommitDate sets the commitDate contents, so dependents can inject build info

func SetCommitHash added in v1.0.1

func SetCommitHash(hash string)

SetCommitHash sets the commitHash contents, so dependents can inject build info

Types

type Client

type Client interface {
	Count(name string, value int64, tags []string, rate float64) error
}

Client is the interface for our metrics client for use in independent metric emission Currently, only IndependentCount is implemented

type Filter

type Filter interface {
	FilterLine(line string) string
	FilterJSON(line *json.LogLine)
}

Filter takes in a log line and applies a transformation prior to logging them. Since Unilog can operate on JSON or on string content, there are two methods that a filter must implement (so unilog can cut down on time spent parsing the log line).

type Unilog

type Unilog struct {
	// Sentry DSN for reporting Unilog errors
	// If this is unset, unilog will not report errors to Sentry
	SentryDSN string
	// StatsdAddress for sending metrics
	// If this is unset, it wlil default to "127.0.0.1:8200" -> TODO: is this what we want?
	StatsdAddress string
	// The email address from which unilog will send mail on
	// errors
	MailTo string
	// The email address to which unilog will email breakages. If
	// either MailTo or MailFrom is unset, unilog will not
	// generate email.
	MailFrom string

	// A series of filters which will be applied to each log line
	// in order
	Filters []Filter

	// The version that unilog will report on the command-line and
	// in error emails. Defaults to the toplevel Version constant.
	Version string
	// The number of log lines to buffer in-memory, in case
	// unilog's disk writer falls behind. Note that when talking
	// to unilog over a pipe, the kernel also maintains an
	// in-kernel pipe buffer, sized 64kb on Linux.
	BufferLines int
	// Whether unilog expects log line input as JSON or as plain
	// text.
	JSON bool

	Name    string
	Verbose bool
	Debug   bool
	// contains filtered or unexported fields
}

Unilog represents a unilog process. unilog is intended to be used as a standalone application, but is exported as a package to allow users to perform compile-time configuration to simplify deployment.

func (*Unilog) Main

func (u *Unilog) Main()

Main sets up the Unilog instance and then calls Run.

Jump to

Keyboard shortcuts

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