loggingFormatter

package
v0.0.46 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

This package is used provide a standardized format for loggers using the sirupsen/logrus package.

Index

Constants

View Source
const (
	JSONLogFormat         = "{\"id\":\"%id%\",\"timestamp\":\"%time%\",\"level\":\"%lvl%\",\"context\":\"%context%\",\"message\":\"%msg%\"}\n"
	JSONLogMessageNoQuote = "{\"id\":\"%id%\",\"timestamp\":\"%time%\",\"level\":\"%lvl%\",\"context\":\"%context%\",\"message\":%msg%}\n"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Formatter

type Formatter struct {
	TimestampFormat string // Format string for timestamp
	LogFormat       string // Format string for log output
}

Formatter implements logrus.Formatter interface.

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Use: loggingFormatter.Formatter{} (Struct) |DESCRIPTION| Format building log message as standard text |ARGS|

type JSONFormatter

type JSONFormatter struct {
	TimestampFormat string // Format string for timestamp
	Prefix          string // Prefix to write at the beginning of each line
	Timezone        string // Timezone to use for timestamps
	LogFormat       string // Format string for log output
	CorrelationID   string // Correlation ID to include in logs
	MessageNoQuote  bool   // If true, don't put the message field in quotes
	// contains filtered or unexported fields
}

JSONFormatter formats logs into parsable json

func NewJSONFormatter added in v0.0.23

func NewJSONFormatter(timestampFormat string, correlationID string, prefix string, timezone string, messageNoQuote bool) *JSONFormatter

NewJSONFormatter creates a new JSONFormatter

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(entry *logrus.Entry) ([]byte, error)

Use: loggingFormatter.JSONFormatter{} (Struct) |DESCRIPTION| Format renders a single log entry as JSON |ARGS| Prefix (string), Timezone (string), MessageNoQuote (bool)

type LogEntry added in v0.0.23

type LogEntry struct {
	ID            string        `json:"id"`
	Time          string        `json:"time"`
	Level         string        `json:"level"`
	CorrelationID string        `json:"correlation,omitempty"`
	Context       string        `json:"context"`
	Message       string        `json:"message"`
	Data          logrus.Fields `json:"data,omitempty"`
}

LogEntry is the log entry structure for JSONFormatter

Jump to

Keyboard shortcuts

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