Documentation
¶
Index ¶
- Constants
- func AddLoggingSectionToCommand(cmd cmds.Command) (cmds.Command, error)
- func AddLoggingSectionToRootCommand(rootCmd *cobra.Command, appName string) error
- func InitEarlyLoggingFromArgs(args []string, appName string) error
- func InitLoggerFromCobra(cmd *cobra.Command) error
- func InitLoggerFromSettings(settings *LoggingSettings) error
- func InitLoggerFromViper() error
- func InitLoggerWithConfig(config *LogConfig) error
- func InitViper(appName string, rootCmd *cobra.Command) errordeprecated
- func InitViperInstanceWithAppName(appName string, configFile string) (*viper.Viper, error)deprecated
- func InitViperWithAppName(appName string, configFile string) errordeprecated
- func NewLoggingSection() (schema.Section, error)
- func SetupLoggingFromValues(parsedValues *values.Values) error
- type LogConfig
- type LoggingSettings
- type LogstashWriter
Constants ¶
const LoggingSectionSlug = "logging"
Variables ¶
This section is empty.
Functions ¶
func AddLoggingSectionToCommand ¶ added in v1.0.0
AddLoggingSectionToCommand adds the logging section to a Glazed command
func AddLoggingSectionToRootCommand ¶ added in v1.0.0
func InitEarlyLoggingFromArgs ¶ added in v0.7.5
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
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 InitLoggerFromViper ¶
func InitLoggerFromViper() error
InitLoggerFromViper initializes the logger using settings from Viper Deprecated: Initialize logging from resolved values using SetupLoggingFromValues instead.
func InitLoggerWithConfig ¶
func InitViperWithAppName
deprecated
func NewLoggingSection ¶ added in v1.0.0
NewLoggingSection creates a new section for logging configuration
func SetupLoggingFromValues ¶ added in v1.0.0
SetupLoggingFromValues configures global logger from command-line fields
Types ¶
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"`
LogstashEnabled bool `glazed:"logstash-enabled"`
LogstashHost string `glazed:"logstash-host"`
LogstashPort int `glazed:"logstash-port"`
LogstashProtocol string `glazed:"logstash-protocol"`
LogstashAppName string `glazed:"logstash-app-name"`
LogstashEnvironment string `glazed:"logstash-environment"`
}
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
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