logger

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package logger implements a custom logger that prefixes log messages with the database name.

Index

Constants

This section is empty.

Variables

View Source
var (
	LogLevels     = []string{"debug", "info", "warning", "error", "fatal"}
	LogFormats    = []string{"human", "logfmt", "json"}
	LogTimestamps = []string{"short", "disable", "full"}
)
View Source
var DefaultConfig = Config{
	Level:     "info",
	Format:    "human",
	Timestamp: "short",
}

DefaultConfig defines the default configuration

View Source
var FlagConfig = Config{}

FlagConfig captures flag values and defaults to zero values

Functions

func Configure

func Configure(c Config)

Configure configures logrus according to Config

func RegisterFlags

func RegisterFlags()

RegisterFlags registers several log flags. The default values are set to their zero value to allow detecting when the flag has been set. This allows the use of a config file for logging and overriding it with these flags.

func RegisterFlagsWith

func RegisterFlagsWith(stringVar StringVarFlagFunc)

RegisterFlagsWith uses a specific function to register the flags with, allowing it to be used with different flag packages, like Cobra.

Types

type Config

type Config struct {
	Level     string `yaml:"level"`     // One of LogLevels
	Format    string `yaml:"format"`    // One of LogFormats
	Timestamp string `yaml:"timestamp"` // One of LogTimestamps
}

Config configures logging

func (Config) Check

func (c Config) Check() error

Check validates a Config instance

func (Config) Merge

func (c Config) Merge(o Config) Config

Merge merges a Config with another Config, returning the new combined Config. This is useful for merging in values set by flags.

type NamespaceFormatter

type NamespaceFormatter struct {
	Parent logrus.Formatter
}

NamespaceFormatter is a logrus formatter that adds the 'db' field to a log prefix for nicer formatted text output.

func (*NamespaceFormatter) Format

func (f *NamespaceFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements logrus.Formatter

type StringVarFlagFunc

type StringVarFlagFunc func(*string, string, string, string)

StringVarFlagFunc has the signature of flag.StringVar

Jump to

Keyboard shortcuts

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