logging

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 15 Imported by: 25

README

Clay Logging Layer

This package provides a Glazed parameter layer for configuring logging in Clay applications.

Documentation

📖 For API reference and detailed usage, see: Logging Layer API Reference

🎓 To learn how to create custom layers, see: Custom Layer Tutorial

Quick Overview

The logging layer provides:

  • Log Level: Control verbosity (debug, info, warn, error, fatal)
  • Log Format: Choose between text and JSON formats
  • Log File: Specify output file (defaults to stderr)
  • Caller Info: Include caller information in logs
  • Logstash Integration: Send logs to centralized servers

Quick Usage

import "github.com/go-go-golems/glazed/pkg/cmds/logging"

// In your command's Run method:
if err := logging.SetupLoggingFromParsedLayers(parsedLayers); err != nil {
    return err
}

log.Info().Msg("Logging is now configured!")

For complete examples and detailed API documentation, see the links above.

Documentation

Index

Constants

View Source
const LoggingLayerSlug = "logging"

Variables

This section is empty.

Functions

func AddLoggingLayerToCommand

func AddLoggingLayerToCommand(cmd cmds.Command) (cmds.Command, error)

AddLoggingLayerToCommand adds the logging layer to a Glazed command

func AddLoggingLayerToRootCommand

func AddLoggingLayerToRootCommand(rootCmd *cobra.Command, appName string) error

func InitLoggerFromSettings

func InitLoggerFromSettings(settings *LoggingSettings) error

InitLoggerFromSettings initializes the logger based on the provided settings

func InitLoggerFromViper

func InitLoggerFromViper() error

InitLoggerFromViper initializes the logger using settings from Viper

func InitLoggerWithConfig

func InitLoggerWithConfig(config *LogConfig) error

func InitViper

func InitViper(appName string, rootCmd *cobra.Command) error

func InitViperInstanceWithAppName

func InitViperInstanceWithAppName(appName string, configFile string) (*viper.Viper, error)

func InitViperWithAppName

func InitViperWithAppName(appName string, configFile string) error

func NewLoggingLayer

func NewLoggingLayer() (layers.ParameterLayer, error)

NewLoggingLayer creates a new parameter layer for logging configuration

func SetupLoggingFromParsedLayers added in v0.6.2

func SetupLoggingFromParsedLayers(parsedLayers *layers.ParsedLayers) error

SetupLoggingFromParsedLayers configures global logger from command-line parameters

Types

type LogConfig

type LogConfig struct {
	WithCaller bool
	Level      string
	LogFormat  string
	LogFile    string
}

type LoggingSettings

type LoggingSettings struct {
	WithCaller          bool   `glazed.parameter:"with-caller"`
	LogLevel            string `glazed.parameter:"log-level"`
	LogFormat           string `glazed.parameter:"log-format"`
	LogFile             string `glazed.parameter:"log-file"`
	LogToStdout         bool   `glazed.parameter:"log-to-stdout"`
	LogstashEnabled     bool   `glazed.parameter:"logstash-enabled"`
	LogstashHost        string `glazed.parameter:"logstash-host"`
	LogstashPort        int    `glazed.parameter:"logstash-port"`
	LogstashProtocol    string `glazed.parameter:"logstash-protocol"`
	LogstashAppName     string `glazed.parameter:"logstash-app-name"`
	LogstashEnvironment string `glazed.parameter:"logstash-environment"`
}

LoggingSettings holds the logging configuration parameters

func GetLoggingSettings added in v0.6.2

func GetLoggingSettings(parsedLayers *layers.ParsedLayers) (*LoggingSettings, error)

GetLoggingSettings extracts logging configuration for custom validation or setup

type LogstashWriter

type LogstashWriter struct {
	Host        string
	Port        int
	Protocol    string // "tcp" or "udp"
	AppName     string
	Environment string
	// contains filtered or unexported fields
}

LogstashWriter implements io.Writer interface for sending logs to Logstash via TCP or UDP

func NewLogstashWriter

func NewLogstashWriter(host string, port int, protocol, appName, environment string) *LogstashWriter

NewLogstashWriter creates a new LogstashWriter for sending logs to Logstash

func SetupLogstashLogger

func SetupLogstashLogger(host string, port int, protocol, appName, environment string) *LogstashWriter

SetupLogstashLogger configures a logger that sends logs to Logstash

func (*LogstashWriter) Close

func (w *LogstashWriter) Close() error

Close closes the connection to Logstash

func (*LogstashWriter) Write

func (w *LogstashWriter) Write(p []byte) (int, error)

Write implements the io.Writer interface

Jump to

Keyboard shortcuts

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