mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-14 18:16:43 +00:00

* [NOD-256] Add error log * [NOD-256] Add error log * [NOD-256] Fix typo and comment * [NOD-256] Remove btclog dir * [NOD-256] Format project * [NOD-256] Add error log files * [NOD-256] Add an option to add a log file to write into to an existing backend logger * [NOD-256] Get rid of redundant logs initialization * [NOD-256] rename initLogRotators to initLog * [NOD-256] Get rid ExampleSignTxOutput and convert ExampleBlockDAG_ProcessBlock to a regular test * [NOD-256] Show error message if os.Exiting from initLog
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/daglabs/btcd/util"
|
|
"path/filepath"
|
|
|
|
"github.com/jessevdk/go-flags"
|
|
)
|
|
|
|
const (
|
|
defaultLogFilename = "miningsimulator.log"
|
|
defaultErrLogFilename = "miningsimulator_err.log"
|
|
)
|
|
|
|
var (
|
|
// Default configuration options
|
|
defaultHomeDir = util.AppDataDir("miningsimulator", false)
|
|
defaultLogFile = filepath.Join(defaultHomeDir, defaultLogFilename)
|
|
defaultErrLogFile = filepath.Join(defaultHomeDir, defaultErrLogFilename)
|
|
)
|
|
|
|
type config struct {
|
|
AddressListPath string `long:"addresslist" description:"Path to a list of nodes' JSON-RPC endpoints" required:"true"`
|
|
CertificatePath string `long:"cert" description:"Path to certificate accepted by JSON-RPC endpoint"`
|
|
DisableTLS bool `long:"notls" description:"Disable TLS"`
|
|
Verbose bool `long:"verbose" short:"v" description:"Enable logging of RPC requests"`
|
|
}
|
|
|
|
func parseConfig() (*config, error) {
|
|
cfg := &config{}
|
|
parser := flags.NewParser(cfg, flags.PrintErrors|flags.HelpFlag)
|
|
_, err := parser.Parse()
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if cfg.CertificatePath == "" && !cfg.DisableTLS {
|
|
return nil, errors.New("--notls has to be disabled if --cert is used")
|
|
}
|
|
|
|
if cfg.CertificatePath != "" && cfg.DisableTLS {
|
|
return nil, errors.New("--cert should be omitted if --notls is used")
|
|
}
|
|
|
|
initLog(defaultLogFile, defaultErrLogFile)
|
|
|
|
return cfg, nil
|
|
}
|