log

package
v1.1.0-alpha-8 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package log defines a complete logging API and is to be used for all 0-Disk info/error logging purposes.

Broadcast

Broadcast is a function that wraps 0-log specifically for logging errors in JSON format to the 0-Orchestrator.

It takes a MessageStatus, MessageSubject and an interface for additional data that needs to be sent. These values are used to form the Message struct which will be send over to zerolog.Log to be logged.

MessageStatus is a status code that represents the status of the MessageSubject.

MessageSubject represents who the status applies to (storage(ardb), etcd, tlog).

No error is returned as this would be used as a last resort to notify the 0-Orchestrator to intervene.

More information about Broadcast can be found in the 0-Disk docs: https://github.com/zero-os/0-Disk/blob/master/docs/log.md#broadcasting-to-0-orchestrator and more information about 0-log can be found at the 0-log github page: https://github.com/zero-os/0-log

BroadcastStatistics

BroadcastStatistics is a function that wraps 0-log specifically for logging statistical information to the 0-core log monitor.

The parameters are used to form a zerolog.MsgStatistics struct, used to format a statistics message's message.

More in depth information about zerolog.MsgStatistics can be found in the godocs: https://godoc.org/github.com/zero-os/0-log#MsgStatistics and the zerolog docs: https://github.com/zero-os/0-log .

AggregationType and MetricTags are wrappers for the zerolog types with the same names provided to avoid using the 0-log package in other parts of 0-Disk.

An error will be returned in the following cases:

  • The aggregation type is invalid (zerolog.ErrInvalidAggregationType)

usage example without tags:

BroadcastStatistics("vvdisk.iops.write@virt.a", 268.51483871176936, AggregationAverages, nil)
// outputs: 10::vdisk.iops.write@virt.a:268.51483871176936|A

usage example with tags:

tags := MetricTags{"cluster": "a"}
BroadcastStatistics("vvdisk.iops.write@virt.a", 268.51483871176936, AggregationAverages, tags)
// outputs: 10::vdisk.iops.write@virt.a:268.51483871176936|A|cluster=a

Index

Constants

View Source
const (
	// AggregationAverages represents an averaging aggregation type
	// wraps zerolog.AggregationAverages
	AggregationAverages = zerolog.AggregationAverages
	// AggregationDifferentiates represents a differentiating aggregation type
	// wraps zerolog.AggregationDifferentiates
	AggregationDifferentiates = zerolog.AggregationDifferentiates
)
View Source
const (
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel = log.LvlDebug
	// InfoLevel level. General operational entries about what's going on inside the
	// application.
	InfoLevel = log.LvlInfo
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	// Commonly used for hooks to send errors to an error tracking service.
	ErrorLevel = log.LvlError
	// FatalLevel level. Logs and then calls `os.Exit(1)`.
	FatalLevel = log.LvlCrit
)

Variables

This section is empty.

Functions

func Broadcast

func Broadcast(status MessageStatus, subject MessageSubject, data interface{})

Broadcast a message to the stderr in JSON format, such that managing services in an upper layer can react upon it.

func BroadcastStatistics

func BroadcastStatistics(key string, value float64, op AggregationType, tags MetricTags) error

BroadcastStatistics broadcasts statistics data for 0-Core statistics monitor using the 0-Log package

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugf

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

Debugf logs a message at level Debug on the standard logger.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorf

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

Errorf logs a message at level Error on the standard logger.

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger.

func Fatalf

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

Fatalf logs a message at level Fatal on the standard logger.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

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

Infof logs a message at level Info on the standard logger.

func SetHandlers

func SetHandlers(handlers ...Handler)

SetHandlers allows you to set extra handlers on the std logger, besides the default StdErr Logger

func SetLevel

func SetLevel(level Level)

SetLevel defines at which level the std logger should log

Types

type ARDBServerTimeoutBody

type ARDBServerTimeoutBody struct {
	Address  string         `json:"address"`
	Database int            `json:"db"`
	Type     ARDBServerType `json:"type"`
	VdiskID  string         `json:"vdiskID"`
}

ARDBServerTimeoutBody is the data given for a ARDB StatusServerTimeout message.

type ARDBServerType

type ARDBServerType uint8

ARDBServerType defines the type of ARDB Server, for any broadcast purposes.

const (
	ARDBPrimaryServer ARDBServerType = iota
	ARDBSlaveServer
	ARDBTemplateServer
)

ARDBServerType enum values

func (ARDBServerType) MarshalText

func (st ARDBServerType) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.MarshalText. Returns this message subject in string format.

func (ARDBServerType) String

func (st ARDBServerType) String() string

String implements Stringer.String

type AggregationType

type AggregationType = zerolog.AggregationType

AggregationType represents an statistics aggregation type wraps zerolog.AggregationType

type Handler

type Handler = log.Handler

Handler interface defines where and how log records are written. Handlers are composable, providing you great flexibility in combining them to achieve the logging structure that suits your applications.

func FileHandler

func FileHandler(path string) (Handler, error)

FileHandler returns a handler which writes log records to the give file using the given format. If the path already exists, FileHandler will append to the given file. If it does not, FileHandler will create the file with mode 0644.

func StderrHandler

func StderrHandler() Handler

StderrHandler is the default handler for all logs, unless handlers are given

func SyslogHandler

func SyslogHandler(tag string) (Handler, error)

SyslogHandler opens a connection to the system syslog daemon by calling syslog.New and writes all records to it.

type InvalidConfigBody

type InvalidConfigBody struct {
	Endpoints []string `json:"endpoints"`
	Key       string   `json:"key"`
	// given if the config is only invalid
	// because it is used for a specific vdiskID
	// which has extra requirements the configs does not fullfill.
	VdiskID string `json:"vdiskID,omitempty"`
}

InvalidConfigBody is the data given for a StatusInvalidConfig message.

type Level

type Level = log.Lvl

Level type

func GetLevel

func GetLevel() Level

GetLevel returns the level used by the std logger

type Logger

type Logger interface {
	// verbose messages targeted at the developer
	Debug(args ...interface{})
	Debugf(format string, args ...interface{})
	// info messages targeted at the user and developer
	Info(args ...interface{})
	Infof(format string, args ...interface{})
	// error messages targeted at the user, sysadmin and developer,
	// but mostly at the sysadmin
	Error(args ...interface{})
	Errorf(format string, args ...interface{})
	// a fatal message targeted at the user and developer
	// the program will exit as this message
	// this level shouldn't be used by libraries
	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
}

Logger defines a pragmatic Logger interface.

func New

func New(module string, level Level, handlers ...Handler) Logger

New logger, creates a new logger

func NopLogger

func NopLogger() Logger

NopLogger creates a Logger which discards all logs, and doesn't ever exit the process when a fatal error occurs.

type Message

type Message struct {
	Status  MessageStatus  `json:"status"`
	Subject MessageSubject `json:"subject"`
	Data    interface{}    `json:"data"`
}

Message defines the structure of all broadcast messages using the 0-log stderr logger.

type MessageStatus

type MessageStatus uint

MessageStatus represents the status code that comes with a broadcast message

const (
	StatusUnknownError     MessageStatus = 400
	StatusClusterTimeout   MessageStatus = 401
	StatusInvalidConfig    MessageStatus = 403
	StatusServerTimeout    MessageStatus = 421
	StatusServerDisconnect MessageStatus = 422
	StatusServerTempError  MessageStatus = 423
)

status codes

type MessageSubject

type MessageSubject uint8

MessageSubject represents the subject of the message, which together with the status code should tell you how to interpret a message

const (
	// SubjectStorage identifies the messages has to do with (ardb) storage
	SubjectStorage MessageSubject = iota
	// SubjectETCD identifies the messages has to do with etcd
	SubjectETCD
	// SubjectTlog identifies the messages has to do with tlog
	SubjectTlog
	// SubjectZeroStor identifies the messages has to do with zerostor
	SubjectZeroStor
)

func (MessageSubject) MarshalText

func (s MessageSubject) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.MarshalText. Returns this message subject in string format.

func (MessageSubject) String

func (s MessageSubject) String() string

String implements Stringer.String

type MetricTags

type MetricTags = zerolog.MetricTags

MetricTags represents statistics metric tags wraps zerolog.MetricTags

type Record

type Record = log.Record

Record is what a Logger asks its handler to write

Jump to

Keyboard shortcuts

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