logging

package
v1.2.7 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 16 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 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"`
	LogLevel    string `glazed:"log-level"`
	LogFormat   string `glazed:"log-format"`
	LogFile     string `glazed:"log-file"`
	LogToStdout bool   `glazed:"log-to-stdout"`
}

LoggingSettings holds the logging configuration fields

func GetLoggingSettings added in v0.6.2

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

GetLoggingSettings extracts logging configuration for custom validation or setup

Jump to

Keyboard shortcuts

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