build

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

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 (
	// PreRelease is defined as a variable so it can be overridden during the
	// build process with:
	// '-ldflags "-X github.com/decred/dcrlnd/build.PreRelease=foo"'
	// if needed.  It MUST only contain characters from semanticAlphabet per
	// the semantic versioning spec.
	PreRelease = "pre"

	// BuildMetadata is defined as a variable so it can be overridden during the
	// build process with:
	// '-ldflags "-X github.com/decred/dcrlnd/build.BuildMetadata=foo"'
	// if needed.  It MUST only contain characters from semanticBuildAlphabet
	// per the semantic versioning spec.
	BuildMetadata = ""

	// Commit is defined as a variable so it can be overriden during the
	// build process with:
	// '-ldflags "-X github.com/decred/dcrlnd/build.Commit=foo"'
	// if needed. It is NOT included in the version string returned by this
	// module and MUST only contain characters from semanticBuildAlphabet.
	Commit = ""
)
View Source
var LogLevel = "info"

LogLevel specifies a default log level of info.

View Source
var Stdout io.Writer = os.Stdout

Stdout is the writer used to actually output data of the app. By default, this is the stdout file.

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 MajorMinorPatch added in v0.3.0

func MajorMinorPatch() (uint, uint, uint)

MajorMinorPatch returns the compiled-in respective semver version elements.

func NewSubLogger

func NewSubLogger(subsystem string,
	genSubLogger func(string) slog.Logger) slog.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 added in v0.3.0

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 SourceCommit added in v0.2.0

func SourceCommit() string

SourceCommit returns the normalized version of the Commit variable according to the rules of semantic versioning guidelines.

func Version

func Version() string

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

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 LeveledSubLogger added in v0.3.0

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 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 LogWriter

type LogWriter struct {
	// RotatorPipe is the write-end pipe for writing to the log rotator.  It
	// is written to by the Write method of the LogWriter type. This only
	// needs to be set if neither the stdlog or nolog builds are set.
	RotatorPipe *io.PipeWriter
}

LogWriter is a stub type whose behavior can be changed using the build flags "stdlog" and "nolog". The default behavior is to write to both stdout and the RotatorPipe. Passing "stdlog" will cause it only to write to stdout, and "nolog" implements Write as a no-op.

func (*LogWriter) Write

func (w *LogWriter) Write(b []byte) (int, error)

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

type PrefixLog added in v0.3.0

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

PrefixLog is a pass-through logger that adds a prefix to every logged line.

func NewPrefixLog added in v0.3.0

func NewPrefixLog(prefix string, log slog.Logger) *PrefixLog

NewPrefixLog instantiates a new prefixed logger.

func (*PrefixLog) Critical added in v0.3.0

func (p *PrefixLog) Critical(v ...interface{})

Critical formats message using the default formats for its operands and writes to log with LevelCritical.

func (*PrefixLog) Criticalf added in v0.3.0

func (p *PrefixLog) Criticalf(format string, params ...interface{})

Criticalf formats message according to format specifier and writes to log with LevelCritical.

func (*PrefixLog) Debug added in v0.3.0

func (p *PrefixLog) Debug(v ...interface{})

Debug formats message using the default formats for its operands and writes to log with LevelDebug.

func (*PrefixLog) Debugf added in v0.3.0

func (p *PrefixLog) Debugf(format string, params ...interface{})

Debugf formats message according to format specifier and writes to log with LevelDebug.

func (*PrefixLog) Error added in v0.3.0

func (p *PrefixLog) Error(v ...interface{})

Error formats message using the default formats for its operands and writes to log with LevelError.

func (*PrefixLog) Errorf added in v0.3.0

func (p *PrefixLog) Errorf(format string, params ...interface{})

Errorf formats message according to format specifier and writes to to log with LevelError.

func (*PrefixLog) Info added in v0.3.0

func (p *PrefixLog) Info(v ...interface{})

Info formats message using the default formats for its operands and writes to log with LevelInfo.

func (*PrefixLog) Infof added in v0.3.0

func (p *PrefixLog) Infof(format string, params ...interface{})

Infof formats message according to format specifier and writes to log with LevelInfo.

func (*PrefixLog) Level added in v0.3.0

func (p *PrefixLog) Level() slog.Level

Level returns the current logging level.

func (*PrefixLog) SetLevel added in v0.3.0

func (p *PrefixLog) SetLevel(level slog.Level)

SetLevel changes the logging level to the passed level.

func (*PrefixLog) Trace added in v0.3.0

func (p *PrefixLog) Trace(v ...interface{})

Trace formats message using the default formats for its operands and writes to log with LevelTrace.

func (*PrefixLog) Tracef added in v0.3.0

func (p *PrefixLog) Tracef(format string, params ...interface{})

Tracef formats message according to format specifier and writes to to log with LevelTrace.

func (*PrefixLog) Warn added in v0.3.0

func (p *PrefixLog) Warn(v ...interface{})

Warn formats message using the default formats for its operands and writes to log with LevelWarn.

func (*PrefixLog) Warnf added in v0.3.0

func (p *PrefixLog) Warnf(format string, params ...interface{})

Warnf formats message according to format specifier and writes to to log with LevelWarn.

type RotatingLogWriter added in v0.3.0

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

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

func NewRotatingLogWriter added in v0.3.0

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 added in v0.3.0

func (r *RotatingLogWriter) Close() error

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

func (*RotatingLogWriter) GenSubLogger added in v0.3.0

func (r *RotatingLogWriter) GenSubLogger(tag string, shutdown func()) slog.Logger

GenSubLogger creates a new sublogger. A shutdown callback function is provided to be able to shutdown in case of a critical error.

func (*RotatingLogWriter) InitLogRotator added in v0.3.0

func (r *RotatingLogWriter) InitLogRotator(logFile string, maxLogFileSize int,
	maxLogFiles int) 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) RegisterSubLogger added in v0.3.0

func (r *RotatingLogWriter) RegisterSubLogger(subsystem string,
	logger slog.Logger)

RegisterSubLogger registers a new subsystem logger.

func (*RotatingLogWriter) SetLogLevel added in v0.3.0

func (r *RotatingLogWriter) 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 (*RotatingLogWriter) SetLogLevels added in v0.3.0

func (r *RotatingLogWriter) 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 (*RotatingLogWriter) SubLoggers added in v0.3.0

func (r *RotatingLogWriter) SubLoggers() SubLoggers

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

NOTE: This is part of the LeveledSubLogger interface.

func (*RotatingLogWriter) SupportedSubsystems added in v0.3.0

func (r *RotatingLogWriter) 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 ShutdownLogger added in v0.3.0

type ShutdownLogger struct {
	slog.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 added in v0.3.0

func NewShutdownLogger(logger slog.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 added in v0.3.0

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 slog.Logger interface.

func (*ShutdownLogger) Criticalf added in v0.3.0

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 slog.Logger interface.

type SubLoggers added in v0.3.0

type SubLoggers map[string]slog.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