Documentation
¶
Overview ¶
Package zerolog is a package that prints messages in a format the 0-Core log monitor can read and use for logging (errors), statistics, selfhealing and other features.
Usage:
zerolog.Log(zerolog.LevelStdout, "Hello world")
Output:
1::Hello world
Message ¶
Accepted message types may very on provided log level:
String message (e.g.: LevelStdout, LevelStderr) takes strings, string aliases, types that implement fmt.Stringer, types that implement encoding.TextMarshaler.
Statistics message (e.g: LevelStatistics) takes a MsgStatistics to have fields and validation for data required by the 0-Core statistics monitor https://github.com/zero-os/0-core/blob/master/docs/monitoring/stats.md
The MsgStatistics Operation field takes an AggregationType which defines the data aggregation strategy for the 0-core.
The MsgStatistics Tags field takes a MetricTags type which is a map with a string as key and an interface as value. When logging this map is formatted to a flat string, if the value is a string it will simply be added to the formatted string, if not it will check the value implements the fmt.Stringer or encoding.TextMarshaler interfaces, as a last resort the value will be turned into a string using fmt.Sprint.
JSON messages (e.g.: LevelJSON) takes any type that can be marshalled to JSON.
Additional info ¶
package docs: https://github.com/zero-os/0-log/blob/master/README.md
Information about the 0-Core monitoring: https://github.com/zero-os/0-core/blob/master/docs/monitoring/logging.md
Index ¶
Constants ¶
const ( // AggregationAverages represents an averaging aggregation type AggregationAverages = AggregationType("A") // AggregationDifferentiates represents a differentiating aggregation type AggregationDifferentiates = AggregationType("D") )
Variables ¶
var ( // ErrLevelNotValid defines an error where the loggin level is not supported/valid ErrLevelNotValid = errors.New("logging level not valid") // ErrNilMessage represents an error where the supplied message was nil ErrNilMessage = errors.New("message was nil") // ErrInvalidMessage represents an error where the supplied message was invalid ErrInvalidMessage = errors.New("message was invalid") // ErrNilStatisticsKey represents an error where the supplied // statistics message has no key specified ErrNilStatisticsKey = errors.New("statistics key was missing") // ErrInvalidAggregationType represents an error where the supplied // statistics message has an invalid aggregation type specified ErrInvalidAggregationType = errors.New("invalid aggregation type") )
Functions ¶
Types ¶
type AggregationType ¶
type AggregationType string
AggregationType represents an statistics aggregation type
func (AggregationType) Validate ¶
func (at AggregationType) Validate() error
Validate validates the AggregationType
type MetricTags ¶
type MetricTags map[string]interface{}
MetricTags represents statistics metric tags
func (MetricTags) String ¶
func (mt MetricTags) String() string
String converts the MetricTags into a flat string for logging
type MsgStatistics ¶
type MsgStatistics struct { Key string Value float64 Operation AggregationType Tags MetricTags }
MsgStatistics represents the data needed for a statistics message
func (*MsgStatistics) Validate ¶
func (msg *MsgStatistics) Validate() error
Validate validates the MsgStatistics according to spec: https://github.com/zero-os/0-core/blob/master/docs/monitoring/stats.md