gripslog

package module
v0.0.0-...-613f999 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

===================================================================
``gripslog`` -- Interface Library for cdr/slog and deciduosity/grip
===================================================================

gripslog is a shim layer between Grip and Slog, allowing libraries written
with one logger to exist within applications that use the other, and also use
the underlying fundamentals (Senders and Sinks) within either higher level
interfaces.

The translation between message.Composers and SinkEntries, is not lossless:
SinkEntry objects contain stack data, which is neither populated or saved in
the conversion in either direction; similarly, the structure of many
message.Composers is difficult to preserve exactly in all cases.

Documentation

Overview

Package gripslog provides an interface shim between the "grip" logging package and the "slog" package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertLevel

func ConvertLevel(l slog.Level) level.Priority

ConvertLevel produces converts a slog.Level into the analogous grip priority.

func ConvertMessage

func ConvertMessage(msg message.Composer) (string, slog.Map)

ConvertMessage turns a grip message object into the kind of message+structured format that slog expects.

func ConvertPriority

func ConvertPriority(p level.Priority) slog.Level

ConvertPriority converts a grip message's priority to a slog level. Invalid priorities become "info".

func ConvertSinkEntry

func ConvertSinkEntry(ent slog.SinkEntry) message.Composer

ConvertSinkEntry turns a slog.SinkEntry into a message.Composer. The conversion is best-effort, and omits stack tracing data. Additionally the ordered nature of slog.SinkEntry is not preserved.

func ConvertToSinkEntry

func ConvertToSinkEntry(msg message.Composer) slog.SinkEntry

ConvertToSinkEntry provides a convenience wrapper around ConvertMessage to produce lower-level slog.SinkEntry payloads. This function does not populate stack info or other data.

func MakeSinkEntry

func MakeSinkEntry(p level.Priority, msg interface{}) slog.SinkEntry

MakeSinkEntry takes an arbitrary value, and coerces it to a slog.SinkEntry using the message.ConvertToComposer function that grip loggers use.

This operation will always override the priority of the resulting message, even when its already set to some other value

func MakeSinkEntryWithLevel

func MakeSinkEntryWithLevel(p level.Priority, msg interface{}) slog.SinkEntry

MakeSinkEntryWithLevel takes an arbitrary value, and coerces it to a slog.SinkEntry using the message.ConvertToComposer function that grip loggers use.

This operation will use the existing value of the message's priority if set, and override it only if needed.

func NewSenderSink

func NewSenderSink(s send.Sender) slog.Sink

NewSenderSink wraps a send.Sender in a form that is usable as a slog.Sink.

func NewSinkJournal

func NewSinkJournal(sink slog.Sink) grip.Journaler

NewSinkJournal produces an independent grip.Journal instance that wraps a slog.Sink.

func NewSinkSender

func NewSinkSender(name string, sink slog.Sink) send.Sender

NewSinkSenderWithContext produces a send.Sender with the same semantics, as NewSinkSenderWithContext but does not require a context.

func NewSinkSenderWithContext

func NewSinkSenderWithContext(ctx context.Context, name string, sink slog.Sink) send.Sender

NewSinkSenderWithContext produces a send.Sender that wraps the anaogous slog object, a slog.Sink.

Calls to SetName on this send.Sender instance will not impact the name of the slog.Logger or its hierarchy, and the level thresholds are tracked independently. Additionally, the sender's MessageFormater or ErrorHandler are not used.

The context is used when sending messages with slog, and is stored otherwise.

Types

This section is empty.

Jump to

Keyboard shortcuts

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