Skip to content

Commit

Permalink
main: add logcompressor flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jharveyb committed Aug 26, 2024
1 parent 2b53ed1 commit ad5ecdc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
defaultLogLevel = "info"
defaultLogDirname = "logs"
defaultLogFilename = "btcd.log"
defaultLogCompressor = "gzip"
defaultMaxPeers = 125
defaultBanDuration = time.Hour * 24
defaultBanThreshold = 100
Expand Down Expand Up @@ -125,6 +126,7 @@ type config struct {
FreeTxRelayLimit float64 `long:"limitfreerelay" description:"Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute"`
Listeners []string `long:"listen" description:"Add an interface/port to listen for connections (default all interfaces port: 8333, testnet: 18333)"`
LogDir string `long:"logdir" description:"Directory to log output."`
LogCompressor string `long:"logcompressor" description:"Compression algorithm to use when rotating logs. Valid algorithms are: gzip and zstd."`
MaxOrphanTxs int `long:"maxorphantx" description:"Max number of orphan transactions to keep in memory"`
MaxPeers int `long:"maxpeers" description:"Max number of inbound and outbound peers"`
MiningAddrs []string `long:"miningaddr" description:"Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option is set"`
Expand Down Expand Up @@ -428,6 +430,7 @@ func loadConfig() (*config, []string, error) {
RPCMaxConcurrentReqs: defaultMaxRPCConcurrentReqs,
DataDir: defaultDataDir,
LogDir: defaultLogDir,
LogCompressor: defaultLogCompressor,
DbType: defaultDbType,
RPCKey: defaultRPCKeyFile,
RPCCert: defaultRPCCertFile,
Expand Down Expand Up @@ -661,6 +664,15 @@ func loadConfig() (*config, []string, error) {
os.Exit(0)
}

// Validate that the selected log compression algorithm is supported.
if _, ok := logCompressors[cfg.LogCompressor]; !ok {
str := "%s: The specified log compressor [%v] is invalid"
err := fmt.Errorf(str, funcName, cfg.LogCompressor)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}

// Initialize log rotation. After log rotation has been initialized, the
// logger variables may be used.
initLogRotator(filepath.Join(cfg.LogDir, defaultLogFilename))
Expand Down
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ Application Options:
(default all interfaces port: 8333, testnet:
18333, signet: 38333)
--logdir= Directory to log output
--logcompressor= Compression algorithm to use when rotating logs.
(default: gzip)
--maxorphantx= Max number of orphan transactions to keep in
memory (default: 100)
--maxpeers= Max number of inbound and outbound peers
Expand Down
7 changes: 7 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ var subsystemLoggers = map[string]btclog.Logger{
"TXMP": txmpLog,
}

// logCompressors maps the identifier for each supported compression algorithm
// to the extension used for the compressed log files.
var logCompressors = map[string]string{
"gzip": "gz",
"zstd": "zst",
}

// initLogRotator initializes the logging rotater to write logs to logFile and
// create roll files in the same directory. It must be called before the
// package-global log rotater variables are used.
Expand Down

0 comments on commit ad5ecdc

Please sign in to comment.