hblog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 6 Imported by: 0

README

hblog

Hubble log lib

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewConsole

func NewConsole(cfg *ConsoleConfig) (*zap.Logger, error)

NewConsole creates a new logger that writes to the console (stdout)

func NewConsoleDefault

func NewConsoleDefault() (*zap.Logger, error)

NewConsoleDefault creates a new console logger with default configuration

func NewFile

func NewFile(cfg *FileConfig) (*zap.Logger, error)

NewFile creates a new logger that writes to a file with rotation

func NewFileDefault

func NewFileDefault() (*zap.Logger, error)

NewFileDefault creates a new file logger with default configuration

func NewJSONEncoder

func NewJSONEncoder(cfg *Config) zapcore.Encoder

NewJSONEncoder creates a JSON encoder with the given configuration

func NewKafka

func NewKafka(cfg *KafkaConfig) (*zap.Logger, error)

NewKafka creates a new logger that writes to Kafka NOTE: This is a placeholder. Actual implementation would require a Kafka client

func NewMulti

func NewMulti(cfg *MultiConfig) (*zap.Logger, error)

NewMulti creates a new logger that writes to multiple destinations (console and file)

func NewMultiDefault

func NewMultiDefault() (*zap.Logger, error)

NewMultiDefault creates a new multi-destination logger with default configuration

func ParseLogLevel

func ParseLogLevel(levelStr string) zapcore.Level

ParseLogLevel parses a log level string into a zapcore.Level

func StandardOptions

func StandardOptions(cfg *Config) []zap.Option

StandardOptions returns common logger options

Types

type Config

type Config struct {
	// LogLevel is the minimum log level that will be logged
	LogLevel string `toml:"log_level" json:"log_level"`
	// Development puts the logger in development mode, which changes the
	// behavior of DPanicLevel and takes stacktraces more liberally
	Development bool `toml:"development" json:"development"`
}

Config holds common configuration options for all logger types

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration with sensible values

type ConsoleConfig

type ConsoleConfig struct {
	// Common config options
	Config
	// UseColor determines if log levels should be color-coded
	UseColor bool `toml:"use_color" json:"use_color"`
	// UseJSON determines if console output should be in JSON format
	UseJSON bool `toml:"use_json" json:"use_json"`
}

ConsoleConfig holds configuration specific to console-based logging

func DefaultConsoleConfig

func DefaultConsoleConfig() *ConsoleConfig

DefaultConsoleConfig returns a default configuration for console-based logging

type FileConfig

type FileConfig struct {
	// Common config options
	Config
	// Filename is the file to write logs to
	Filename string `toml:"filename" json:"filename"`
	// MaxSize is the maximum size in megabytes of the log file before it gets rotated
	MaxSize int `toml:"max_size" json:"max_size"`
	// MaxBackups is the maximum number of old log files to retain
	MaxBackups int `toml:"max_backups" json:"max_backups"`
	// MaxAge is the maximum number of days to retain old log files
	MaxAge int `toml:"max_age" json:"max_age"`
	// Compress determines if the rotated log files should be compressed
	Compress bool `toml:"compress" json:"compress"`
}

FileConfig holds configuration specific to file-based logging

func DefaultFileConfig

func DefaultFileConfig() *FileConfig

DefaultFileConfig returns a default configuration for file-based logging

type KafkaConfig

type KafkaConfig struct {
	// Common config options
	Config
	// Brokers is a list of Kafka broker addresses
	Brokers []string `toml:"brokers" json:"brokers"`
	// Topic is the Kafka topic to write logs to
	Topic string `toml:"topic" json:"topic"`
	// RequiredAcks specifies the number of acknowledgments required
	RequiredAcks int `toml:"required_acks" json:"required_acks"`
	// Async specifies whether to produce messages asynchronously
	Async bool `toml:"async" json:"async"`
}

KafkaConfig holds configuration for Kafka-based logging

func DefaultKafkaConfig

func DefaultKafkaConfig() *KafkaConfig

DefaultKafkaConfig returns a default configuration for Kafka-based logging

type MultiConfig

type MultiConfig struct {
	// Common config options
	Config
	// ConsoleEnabled determines if console logging is enabled
	ConsoleEnabled bool `toml:"console_enabled" json:"console_enabled"`
	// ConsoleJSON determines if console output should be in JSON format
	ConsoleJSON bool `toml:"console_json" json:"console_json"`
	// ConsoleColor determines if console output should use colors
	ConsoleColor bool `toml:"console_color" json:"console_color"`
	// FileEnabled determines if file logging is enabled
	FileEnabled bool `toml:"file_enabled" json:"file_enabled"`
	// Filename is the file to write logs to
	Filename string `toml:"filename" json:"filename"`
}

MultiConfig holds configuration for a logger that outputs to multiple destinations

func DefaultMultiConfig

func DefaultMultiConfig() *MultiConfig

DefaultMultiConfig returns a default configuration for multi-destination logging

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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