logging

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 18 Imported by: 38

README

Clay Logging Section

This package provides a Glazed field section for configuring logging in Clay applications.

Documentation

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

🎓 To learn how to create custom sections, see: Custom Section Tutorial

Quick Overview

The logging section 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

Quick Usage

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

// In your command's Run method:
if err := logging.SetupLoggingFromValues(parsedSections); 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 LoggingSectionSlug = "logging"

Variables

This section is empty.

Functions

func AddLoggingSectionToCommand added in v1.0.0

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

AddLoggingSectionToCommand adds the logging section to a Glazed command

func AddLoggingSectionToRootCommand added in v1.0.0

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

func InitEarlyLoggingFromArgs added in v0.7.5

func InitEarlyLoggingFromArgs(args []string, appName string) error

InitEarlyLoggingFromArgs initializes logging from command-line arguments before cobra commands are registered. This allows logging configuration (like --log-level) to be respected during command discovery/loading.

This function: - Filters args to only logging flags (ignores unknown flags) - Parses flags using a standalone pflag.FlagSet - Initializes the global logger with parsed settings

Defaults match AddLoggingSectionToRootCommand in section.go.

func InitLoggerFromCobra added in v0.7.0

func InitLoggerFromCobra(cmd *cobra.Command) error

InitLoggerFromCobra initializes the logger using flags parsed by Cobra on the given command. Call this in PersistentPreRun(E) to initialize logging after Cobra parsed flags but before command execution. Flags are added by AddLoggingSectionToRootCommand.

func InitLoggerFromSettings

func InitLoggerFromSettings(settings *LoggingSettings) error

InitLoggerFromSettings initializes the logger based on the provided settings.

func InitLoggerWithConfig

func InitLoggerWithConfig(config *LogConfig) error

func NewLoggingSection added in v1.0.0

func NewLoggingSection() (schema.Section, error)

NewLoggingSection creates a new section for logging configuration

func ParseAreaOverrides added in v1.3.0

func ParseAreaOverrides(values []string) (map[string]string, error)

func SetupLoggingFromValues added in v1.0.0

func SetupLoggingFromValues(parsedValues *values.Values) error

SetupLoggingFromValues configures global logger from command-line fields

Types

type LogConfig

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

type LoggingSettings

type LoggingSettings struct {
	WithCaller     bool              `glazed:"with-caller" yaml:"with-caller" json:"with-caller"`
	LogLevel       string            `glazed:"log-level" yaml:"log-level" json:"log-level"`
	LogFormat      string            `glazed:"log-format" yaml:"log-format" json:"log-format"`
	LogFile        string            `glazed:"log-file" yaml:"log-file" json:"log-file"`
	LogToStdout    bool              `glazed:"log-to-stdout" yaml:"log-to-stdout" json:"log-to-stdout"`
	LogConfigFiles []string          `glazed:"log-config" yaml:"log-config" json:"log-config"`
	LogAreas       map[string]string `glazed:"log-area" yaml:"log-area" json:"log-area"`
	Areas          map[string]string `glazed:"areas" yaml:"areas" json:"areas"`
	StrictAreas    bool              `glazed:"strict-log-areas" yaml:"strict-log-areas" json:"strict-log-areas"`
}

LoggingSettings holds the logging configuration fields

func DefaultLoggingSettings added in v1.3.0

func DefaultLoggingSettings() *LoggingSettings

func GetLoggingSettings added in v0.6.2

func GetLoggingSettings(parsedValues *values.Values) (*LoggingSettings, error)

GetLoggingSettings extracts logging configuration for custom validation or setup

func LoadLoggingSettingsFile added in v1.3.0

func LoadLoggingSettingsFile(path string) (*LoggingSettings, error)

func MergeLoggingSettings added in v1.3.0

func MergeLoggingSettings(base *LoggingSettings, direct *LoggingSettings) (*LoggingSettings, error)

MergeLoggingSettings applies deterministic precedence: base, explicit log-config files in order, then direct settings.

Jump to

Keyboard shortcuts

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