formatters

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package formatters provides functions to format log messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapitalizedLevel

func CapitalizedLevel(level slog.Level) string

CapitalizedLevel returns a capitalized string representation of the log level

See https://github.com/cihub/seelog/blob/f561c5e57575bb1e0a2167028b7339b3a8d16fb4/format.go#L318

func Date

func Date(logFormatRFC3339 bool) func(time.Time) string

Date returns a function that formats a time.Time to a string.

func ExtraJSONContext

func ExtraJSONContext(record AttrHolder) string

ExtraJSONContext creates a JSON string of the record's attributes.

func ExtraTextContext

func ExtraTextContext(record AttrHolder) string

ExtraTextContext creates a text string of the record's attributes.

func ExtractShortPathFromFullPath

func ExtractShortPathFromFullPath(fullPath string) string

ExtractShortPathFromFullPath extracts the short path from a full path.

It is exported to be used from pkg/util/log/setup, and can be unexported once seelog is removed.

func Frame

func Frame(r slog.Record) runtime.Frame

Frame returns the runtime.Frame of the caller of the log message.

func GetLogDateFormat

func GetLogDateFormat(logFormatRFC3339 bool) string

GetLogDateFormat returns the date format to use for the log.

It is exported to be used from pkg/util/log/setup, and can be unexported once seelog is removed.

func LevelToString

func LevelToString(level slog.Level) string

LevelToString converts a slog.Level to a string

func Quote

func Quote(message string) string

Quote quotes a message.

func ShortFilePath

func ShortFilePath(frame runtime.Frame) string

ShortFilePath returns the short path of the file that the log message was emitted from.

func ShortFunction

func ShortFunction(frame runtime.Frame) string

ShortFunction returns the short function name of the function that the log message was emitted from.

See https://github.com/cihub/seelog/blob/f561c5e57575bb1e0a2167028b7339b3a8d16fb4/format.go#L400

func ShortLevel

func ShortLevel(level slog.Level) string

ShortLevel converts a slog.Level to a short string

See https://github.com/cihub/seelog/blob/f561c5e57575bb1e0a2167028b7339b3a8d16fb4/format.go#L328

func ShortestLevel

func ShortestLevel(level slog.Level) string

ShortestLevel returns a single character representation of the log level

https://github.com/cihub/seelog/blob/f561c5e57575bb1e0a2167028b7339b3a8d16fb4/format.go#L338

func ToSlogAttrs

func ToSlogAttrs(context interface{}) []slog.Attr

ToSlogAttrs converts an opaque context to a list of slog.Attr

The context is expected to be a slice of interface{}, containing an even number of elements, with keys being strings.

We can lift the restrictions and/or change the API later, but for now we want the exact same behavior as previously.

This is exported to allow using it with seelog and slog, once we stop using seelog this can be moved to the slog package.

func UppercaseLevel

func UppercaseLevel(level slog.Level) string

UppercaseLevel returns an uppercase string representation of the log level

See https://github.com/cihub/seelog/blob/f561c5e57575bb1e0a2167028b7339b3a8d16fb4/format.go#L365

Types

type AttrHolder

type AttrHolder interface {
	Attrs(func(a slog.Attr) bool)
	NumAttrs() int
}

AttrHolder provides attributes

This is an abstraction to allow using it with both seelog and slog

Jump to

Keyboard shortcuts

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