logjuice

package
v1.34.3 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 9 Imported by: 3

Documentation

Overview

Description: This package provides utility functions for logging.

Index

Constants

View Source
const (
	GoogleMessageKey   googleLogKey = "message"
	GoogleSeverityKey  googleLogKey = "severity"
	GoogleTimestampKey googleLogKey = "timestamp"
	GoogleComponentKey googleLogKey = "component"
	GoogleTraceKey     googleLogKey = "trace"
)

Variables

This section is empty.

Functions

func GetComponent

func GetComponent() string

GetComponent returns details about the caller function, including the function name and line number.

This information is used to populate the component field of a log entry when concise caller information is sufficient.

If the caller's details cannot be retrieved, it returns a string indicating that the caller information could not be obtained.

func GetComponentCustom added in v1.15.12

func GetComponentCustom(skip int, includeFuncPath, includeFile, includeFilePath, includeLine bool) string

GetComponentCustom returns details about the caller function, including the function name, file, and line number.

This information is used to populate the component field of a log entry.

If the caller's details cannot be retrieved, it returns a string indicating that the caller information could not be obtained.

func GetComponentWithFile

func GetComponentWithFile() string

GetComponentWithFile returns details about the caller function, including the function name, file name, and line number.

This information is used to populate the component field of a log entry when detailed caller information is required.

If the caller's details cannot be retrieved, it returns a string indicating that the caller information could not be obtained.

func GetTrace added in v1.15.8

func GetTrace(ctx context.Context, traceKey interface{}) string

GetTrace returns the trace value from the context.

This function is used to retrieve the trace value from the context, which is used to correlate log entries.

Types

type GoogleLogEntry added in v1.15.12

type GoogleLogEntry struct {
	Message   string `json:"message"`
	Trace     string `json:"logging.googleapis.com/trace,omitempty"`
	Component string `json:"component,omitempty"`
}

GoogleLogEntry represents a log entry for Google's logging service.

It includes a message, trace, and component information.

type LogLevel added in v1.15.12

type LogLevel int

LogLevel represents the level of a log entry.

const (
	Debug LogLevel = iota
	Info
	Warn
	Error
)

type Logger added in v1.15.12

type Logger struct {
	// contains filtered or unexported fields
}

func (*Logger) Debug added in v1.15.12

func (l *Logger) Debug(entry GoogleLogEntry)

Error logs an error message with the specified component and trace.

func (*Logger) Error added in v1.15.12

func (l *Logger) Error(entry GoogleLogEntry)

Error logs an error message with the specified component and trace.

func (*Logger) Info added in v1.15.12

func (l *Logger) Info(entry GoogleLogEntry)

Info logs an info message with the specified component and trace.

func (*Logger) JSONLog added in v1.15.12

func (l *Logger) JSONLog(ctx context.Context, level LogLevel, data interface{}, emoji string, messages ...string)

JSONLog logs a structured message with the specified level, emoji & messages, in a structured way following Google Cloud's logging guidelines.

The data parameter is expected to be a struct or map that can be marshaled into JSON.

Message field will be populated with the indent JSON string of the data.

If the data is nil, the message field will be populated with a message indicating that the data is nil.

If the data cannot be indented into a JSON string, the message field will be populated with a message indicating that the data could not be indented.

Trace is retrieved from the context using the logger's trace key.

func (*Logger) Log added in v1.15.12

func (l *Logger) Log(ctx context.Context, level LogLevel, message, component string)

Log logs a message with the specified level & component.

Trace is retrieved from the context using the logger's trace key.

func (*Logger) SLog added in v1.15.12

func (l *Logger) SLog(ctx context.Context, level LogLevel, emoji string, messages ...string)

SLog logs a structured message with the specified level, emoji & messages, in a structured way following Google Cloud's logging guidelines.

Trace is retrieved from the context using the logger's trace key.

func (*Logger) Warn added in v1.15.12

func (l *Logger) Warn(entry GoogleLogEntry)

Warn logs a warning message with the specified component and trace.

type LoggerPort added in v1.15.12

type LoggerPort interface {
	Info(entry GoogleLogEntry)
	Error(entry GoogleLogEntry)
	Debug(entry GoogleLogEntry)
	Warn(entry GoogleLogEntry)
	Log(ctx context.Context, level LogLevel, message, component string)
	SLog(ctx context.Context, level LogLevel, emoji string, messages ...string)
	JSONLog(ctx context.Context, level LogLevel, data interface{}, emoji string, message ...string)
}

func NewLogger added in v1.15.12

func NewLogger(out io.Writer, level slog.Level, traceKey interface{}) LoggerPort

NewLogger creates a new logger with the specified output and log level.

Jump to

Keyboard shortcuts

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