log

package
v0.0.0-...-598a1f7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2023 License: AGPL-3.0, MIT Imports: 5 Imported by: 0

Documentation

Overview

Package log provides logging interfaces for use in handlers and loggers for stdout, files, and time series databases

Index

Constants

View Source
const (
	// FileFlags serts the flags for OpenFile on the log file
	FileFlags = os.O_WRONLY | os.O_APPEND | os.O_CREATE

	// FilePermissions serts the perms for OpenFile on the log file
	FilePermissions = 0640
)
View Source
const (
	// PrefixDate constant for date prefixes
	PrefixDate = "2006-01-02 "
	// PrefixTime  constants for time prefix
	PrefixTime = "15:04:05 "
	// PrefixDateTime  constants for date + time prefix
	PrefixDateTime = "2006-01-02:15:04:05 "
)

Date prefix constants

View Source
const (
	ColorNone  = "\033[0m" // Use this to clear output
	ColorRed   = "\033[31m"
	ColorGreen = "\033[32m"
	ColorAmber = "\033[33m"
	ColorCyan  = "\033[1;36m"
)

Color constants used for writing in colored output

View Source
const KeyNameTime = "stats_key_name_time"

KeyNameTime specifies a key used to define the time value for a given key the Value should be a time.Time value

View Source
const SeriesName = "stats_series_name"

SeriesName specifies the key used to define which bucket/table to send values to thius is used by adapters to extract the table name from values supplied.

View Source
const TagPrefix = "stats_key_tag_"

TagPrefix for a key name allows adding a tag instead of a field to influx

Variables

This section is empty.

Functions

func Add

func Add(l PrintLogger)

Add adds the given logger to the list of outputs, it should be called before logging commences

func AddTag

func AddTag(values map[string]interface{}, key string, value string) map[string]interface{}

AddTag adds a tag field to this

func AddValuesLog

func AddValuesLog(l ValuesLogger)

AddValuesLog adds the given logger to the list of ValuesLoggers, it should be called before logging commences

func Printf

func Printf(format string, args ...interface{})

Printf prints to the printLogs

func Timef

func Timef(start time.Time, format string, args ...interface{})

Timef prints the time elapsed since start plus any message to the PrintLog to log time taken by a function, call at start with defer log.Timef(start,...).

func Values

func Values(values map[string]interface{})

Values values to the valueLogs which typically emit stats to a time series database.

func ValuesBatch

func ValuesBatch(values []map[string]interface{})

ValuesBatch sends an array of values to the valueLogs which typically emit stats to a time series database.

Types

type Default

type Default struct {

	// PrefixTimeFormat is used to prefix any log lines emitted with a time.
	PrefixTimeFormat string

	// Writer is the output of this logger.
	Writer io.Writer
}

Default defines a default logger to stdout

func NewStdErr

func NewStdErr() (*Default, error)

NewStdErr returns a new PrintLogger which outputs to stderr

func (*Default) Printf

func (d *Default) Printf(format string, args ...interface{})

Printf prints the format to writer using args and a time prefix

func (*Default) WriteString

func (d *Default) WriteString(s string)

WriteString writes the string to the Writer.

type File

type File struct {
	Default // File embeds default
	Path    string
}

File logs to a local file as well as stdout

func NewFile

func NewFile(path string) (*File, error)

NewFile creates a new file logger for the given path.

type PrintLogger

type PrintLogger interface {
	Printf(format string, args ...interface{})
}

PrintLogger defines an interface for logging to a text log.

type StatsLog

type StatsLog struct {
}

StatsLog conforms to the ValuesLogger interface It simply outputs the values to stdout, rather than logging to a specific service see the adapters folder for ValueLoggers which connect to time series databases.

func (*StatsLog) Values

func (l *StatsLog) Values(values map[string]interface{})

Values prints to the ValuesLog which typically emits stats to a time series database. This example logger prints values to stdout instead.

type ValuesLogger

type ValuesLogger interface {
	Values(values map[string]interface{})
	ValuesBatch(values []map[string]interface{})
}

ValuesLogger defines an interface for logging to a stats service.

Directories

Path Synopsis
adapters
influx
Package influx sends values to an influxdb database
Package influx sends values to an influxdb database

Jump to

Keyboard shortcuts

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