Documentation
¶
Overview ¶
Package logs provides utilities for handling application logs.
Index ¶
Constants ¶
const ( DataKeyTimestamp = dataKeyPrefix + "created_at" DataKeyLevel = dataKeyPrefix + "level" DataKeySrcFunction = dataKeyPrefix + "src_function" DataKeySrcFileLine = dataKeyPrefix + "src_file_line" DataKeyFSys = dataKeyPrefix + "fsys" )
Variables ¶
This section is empty.
Functions ¶
func AsJSON ¶ added in v0.0.1
Returns a single-line-JSON representation of a log. This function will panic if the JSON marshalling of the log returns an error.
func AsPlainText ¶ added in v0.0.1
Returns a single-line textual representation of a log.
func AsPrettyJSON ¶ added in v0.0.1
Returns the JSON representation of a log with line breaks and indentations. This function will panic if the JSON marshalling of the log returns an error.
Types ¶
type DefaultLogger ¶ added in v0.0.1
type DefaultLogger struct { Writers []io.Writer // For ex: stdout and/or file Serializer Serializer // For ex: As JSON BaseOptions []LogOption // For ex: creation timestamp, source code location LogPrefix string // For ex: "HTTP" or "Server Name" LogSuffix string // For ex: ",\n" to seperate JSON logs by commas and line breaks }
func (*DefaultLogger) LoggerFunc ¶ added in v0.0.1
func (dl *DefaultLogger) LoggerFunc() (LoggerFunc, error)
type Log ¶
Log holds logging data, it has a timestamp, a level of severity and a message. It can also include additional data fields.
type LogLevel ¶ added in v0.0.1
type LogLevel int
LogLevel represents the severity of a log. Severity of logs could range anywhere between simple debug info to critical errors.
const ( LevelUnknown LogLevel = iota // Only for temporary use, like context.TODO() LevelDebug // Debug (usually not meant to be kept in production) LevelInfo // Informative data LevelWarn // Warnings LevelError // Internal errors LevelPanic // Panics / fatal errors )
Represents the level of severity of a log.
type LogOption ¶
type LogOption func(*Log)
LogOption modifies a log. LogOptions are typically used to add more data to a log.
func WithData ¶
WithData adds more data to a log. The value should serializable in order to be writable to the logger output.
func WithFSys ¶ added in v0.0.1
WithFS adds info about a file system (name and size of files) to the log.
func WithSrc ¶ added in v0.0.1
func WithSrc() LogOption
WithSrc stores the location where the log was created in the source code.
func WithTimestamp ¶ added in v0.0.1
func WithTimestamp() LogOption
WithTimestamp adds a creation datetime to the log.
type LoggerFunc ¶ added in v0.0.1
type Serializer ¶ added in v0.0.1
Serializer can convert a Log to bytes so that it can be written.