build

package
v0.19.0-beta.rc3 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultMaxLogFiles is the default maximum number of log files to
	// keep.
	DefaultMaxLogFiles = 10

	// DefaultMaxLogFileSize is the default maximum log file size in MB.
	DefaultMaxLogFileSize = 20
)
View Source
const (
	// Gzip is the default compressor.
	Gzip = "gzip"

	// Zstd is a modern compressor that compresses better than Gzip, in less
	// time.
	Zstd = "zstd"
)

Declare the supported log file compressors as exported consts for easier use from other projects.

View Source
const (
	// AppMajor defines the major version of this binary.
	AppMajor uint = 0

	// AppMinor defines the minor version of this binary.
	AppMinor uint = 19

	// AppPatch defines the application patch for this binary.
	AppPatch uint = 00

	// AppPreRelease MUST only contain characters from semanticAlphabet per
	// the semantic versioning spec.
	AppPreRelease = "beta.rc3"
)

These constants define the application version and follow the semantic versioning 2.0.0 spec (http://semver.org/).

View Source
const Deployment = Production

Deployment specifies a production build.

View Source
const LoggingType = LogTypeDefault

LoggingType is a log type that writes to both stdout and the log rotator, if present.

Variables

View Source
var (
	// Commit stores the current commit of this build, which includes the
	// most recent tag, the number of commits since that tag (if non-zero),
	// the commit hash, and a dirty marker. This should be set using the
	// -ldflags during compilation.
	Commit string

	// CommitHash stores the current commit hash of this build.
	CommitHash string

	// RawTags contains the raw set of build tags, separated by commas.
	RawTags string

	// GoVersion stores the go version that the executable was compiled
	// with.
	GoVersion string
)
View Source
var LogLevel = "info"

LogLevel specifies a default log level of info.

Functions

func IsDevBuild

func IsDevBuild() bool

IsDevBuild returns true if this is a development build.

func IsProdBuild

func IsProdBuild() bool

IsProdBuild returns true if this is a production build.

func NewDefaultLogHandlers

func NewDefaultLogHandlers(cfg *LogConfig,
	rotator *RotatingLogWriter) []btclog.Handler

NewDefaultLogHandlers returns the standard console logger and rotating log writer handlers that we generally want to use. It also applies the various config options to the loggers.

func NewSubLogger

func NewSubLogger(subsystem string,
	genSubLogger func(string) btclog.Logger) btclog.Logger

NewSubLogger constructs a new subsystem log from the current LogWriter implementation. This is primarily intended for use with stdlog, as the actual writer is shared amongst all instantiations.

func ParseAndSetDebugLevels

func ParseAndSetDebugLevels(level string, logger LeveledSubLogger) error

ParseAndSetDebugLevels attempts to parse the specified debug level and set the levels accordingly on the given logger. An appropriate error is returned if anything is invalid.

func SupportedLogCompressor

func SupportedLogCompressor(logCompressor string) bool

SupportedLogCompressor returns whether or not logCompressor is a supported compression algorithm for log files.

func Tags

func Tags() []string

Tags returns the list of build tags that were compiled into the executable.

func Version

func Version() string

Version returns the application version as a properly formed string per the semantic versioning 2.0.0 spec (http://semver.org/).

func WithBuildInfo

func WithBuildInfo(ctx context.Context, cfg *LogConfig) (context.Context,
	error)

WithBuildInfo derives a child context with the build information attached as attributes. At the moment, this only includes the current build's commit hash.

Types

type DeploymentType

type DeploymentType byte

DeploymentType is an enum specifying the deployment to compile.

const (
	// Development is a deployment that includes extra testing hooks and
	// logging configurations.
	Development DeploymentType = iota

	// Production is a deployment that strips out testing logic and uses
	// Default logging.
	Production
)

func (DeploymentType) String

func (b DeploymentType) String() string

String returns a human readable name for a build type.

type FileLoggerConfig

type FileLoggerConfig struct {
	*LoggerConfig  `yaml:",inline"`
	Compressor     string `long:"compressor" description:"Compression algorithm to use when rotating logs." choice:"gzip" choice:"zstd"`
	MaxLogFiles    int    `long:"max-files" description:"Maximum logfiles to keep (0 for no rotation)"`
	MaxLogFileSize int    `long:"max-file-size" description:"Maximum logfile size in MB"`
}

FileLoggerConfig extends LoggerConfig with specific log file options.

type LeveledSubLogger

type LeveledSubLogger interface {
	// SubLoggers returns the map of all registered subsystem loggers.
	SubLoggers() SubLoggers

	// SupportedSubsystems returns a slice of strings containing the names
	// of the supported subsystems. Should ideally correspond to the keys
	// of the subsystem logger map and be sorted.
	SupportedSubsystems() []string

	// SetLogLevel assigns an individual subsystem logger a new log level.
	SetLogLevel(subsystemID string, logLevel string)

	// SetLogLevels assigns all subsystem loggers the same new log level.
	SetLogLevels(logLevel string)
}

LeveledSubLogger provides the ability to retrieve the subsystem loggers of a logger and set their log levels individually or all at once.

type LogConfig

type LogConfig struct {
	Console      *consoleLoggerCfg `group:"console" namespace:"console" description:"The logger writing to stdout and stderr."`
	File         *FileLoggerConfig `group:"file" namespace:"file" description:"The logger writing to LND's standard log file."`
	NoCommitHash bool              `` /* 126-byte string literal not displayed */
}

LogConfig holds logging configuration options.

func DefaultLogConfig

func DefaultLogConfig() *LogConfig

DefaultLogConfig returns the default logging config options.

func (*LogConfig) Validate

func (c *LogConfig) Validate() error

Validate validates the LogConfig struct values.

type LogType

type LogType byte

LogType is an indicating the type of logging specified by the build flag.

const (
	// LogTypeNone indicates no logging.
	LogTypeNone LogType = iota

	// LogTypeStdOut all logging is written directly to stdout.
	LogTypeStdOut

	// LogTypeDefault logs to both stdout and a given io.PipeWriter.
	LogTypeDefault
)

func (LogType) String

func (t LogType) String() string

String returns a human readable identifier for the logging type.

type LoggerConfig

type LoggerConfig struct {
	Disable      bool   `long:"disable" description:"Disable this logger."`
	NoTimestamps bool   `long:"no-timestamps" description:"Omit timestamps from log lines."`
	CallSite     string `long:"call-site" description:"Include the call-site of each log line." choice:"off" choice:"short" choice:"long"`
}

LoggerConfig holds options for a particular logger.

func (*LoggerConfig) HandlerOptions

func (cfg *LoggerConfig) HandlerOptions() []btclog.HandlerOption

HandlerOptions returns the set of btclog.HandlerOptions that the state of the config struct translates to.

type RotatingLogWriter

type RotatingLogWriter struct {
	// contains filtered or unexported fields
}

RotatingLogWriter is a wrapper around the LogWriter that supports log file rotation.

func NewRotatingLogWriter

func NewRotatingLogWriter() *RotatingLogWriter

NewRotatingLogWriter creates a new file rotating log writer.

NOTE: `InitLogRotator` must be called to set up log rotation after creating the writer.

func (*RotatingLogWriter) Close

func (r *RotatingLogWriter) Close() error

Close closes the underlying log rotator if it has already been created.

func (*RotatingLogWriter) InitLogRotator

func (r *RotatingLogWriter) InitLogRotator(cfg *FileLoggerConfig,
	logFile string) error

InitLogRotator initializes the log file rotator to write logs to logFile and create roll files in the same directory. It should be called as early on startup and possible and must be closed on shutdown by calling `Close`.

func (*RotatingLogWriter) Write

func (r *RotatingLogWriter) Write(b []byte) (int, error)

Write writes the byte slice to the log rotator, if present.

type ShutdownLogger

type ShutdownLogger struct {
	btclog.Logger
	// contains filtered or unexported fields
}

ShutdownLogger wraps an existing logger with a shutdown function which will be called on Critical/Criticalf to prompt shutdown.

func NewShutdownLogger

func NewShutdownLogger(logger btclog.Logger, shutdown func()) *ShutdownLogger

NewShutdownLogger creates a shutdown logger for the log provided which will use the signal package to request shutdown on critical errors.

func (*ShutdownLogger) Critical

func (s *ShutdownLogger) Critical(v ...interface{})

Critical formats message using the default formats for its operands and writes to log with LevelCritical. It will then call the shutdown logger's shutdown function to prompt safe shutdown.

Note: it is part of the btclog.Logger interface.

func (*ShutdownLogger) CriticalS

func (s *ShutdownLogger) CriticalS(ctx context.Context, msg string, err error,
	attr ...interface{})

CriticalS writes a structured log with the given message and key-value pair attributes with LevelCritical to the log. It will then call the shutdown logger's shutdown function to prompt safe shutdown.

Note: it is part of the btclog.Logger interface.

func (*ShutdownLogger) Criticalf

func (s *ShutdownLogger) Criticalf(format string, params ...interface{})

Criticalf formats message according to format specifier and writes to log with LevelCritical. It will then call the shutdown logger's shutdown function to prompt safe shutdown.

Note: it is part of the btclog.Logger interface.

type SubLogCreator

type SubLogCreator interface {
	// Logger returns a new logger for a particular subsystem.
	Logger(subsystemTag string) btclog.Logger
}

SubLogCreator can be used to create a new logger for a particular subsystem.

type SubLoggerManager

type SubLoggerManager struct {
	// contains filtered or unexported fields
}

SubLoggerManager manages a set of subsystem loggers. Level updates will be applied to all the loggers managed by the manager.

func NewSubLoggerManager

func NewSubLoggerManager(handlers ...btclog.Handler) *SubLoggerManager

NewSubLoggerManager constructs a new SubLoggerManager.

func (*SubLoggerManager) GenSubLogger

func (r *SubLoggerManager) GenSubLogger(subsystem string,
	shutdown func()) btclog.Logger

GenSubLogger creates a new sub-logger and adds it to the set managed by the SubLoggerManager. A shutdown callback function is provided to be able to shut down in case of a critical error.

func (*SubLoggerManager) RegisterSubLogger

func (r *SubLoggerManager) RegisterSubLogger(subsystem string,
	logger btclog.Logger)

RegisterSubLogger registers the given logger under the given subsystem name.

func (*SubLoggerManager) SetLogLevel

func (r *SubLoggerManager) SetLogLevel(subsystemID string, logLevel string)

SetLogLevel sets the logging level for provided subsystem. Invalid subsystems are ignored. Uninitialized subsystems are dynamically created as needed.

NOTE: This is part of the LeveledSubLogger interface.

func (*SubLoggerManager) SetLogLevels

func (r *SubLoggerManager) SetLogLevels(logLevel string)

SetLogLevels sets the log level for all subsystem loggers to the passed level. It also dynamically creates the subsystem loggers as needed, so it can be used to initialize the logging system.

NOTE: This is part of the LeveledSubLogger interface.

func (*SubLoggerManager) SubLoggers

func (r *SubLoggerManager) SubLoggers() SubLoggers

SubLoggers returns all currently registered subsystem loggers for this log writer.

NOTE: This is part of the LeveledSubLogger interface.

func (*SubLoggerManager) SupportedSubsystems

func (r *SubLoggerManager) SupportedSubsystems() []string

SupportedSubsystems returns a sorted string slice of all keys in the subsystems map, corresponding to the names of the subsystems.

NOTE: This is part of the LeveledSubLogger interface.

type SubLoggers

type SubLoggers map[string]btclog.Logger

SubLoggers is a type that holds a map of subsystem loggers keyed by their subsystem name.

Jump to

Keyboard shortcuts

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