Skip to content

Commit

Permalink
Change logging scheme (#359)
Browse files Browse the repository at this point in the history
* add new debug flag to lit

remove -vvv, -vvvv, -vvvvv in favour of shorter arguments

* reinstate -vvv ; add litinit.go changes from other PR
  • Loading branch information
Varunram authored and adiabat committed Sep 19, 2018
1 parent 4229360 commit ef18f29
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
9 changes: 4 additions & 5 deletions lit.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ type litConfig struct { // define a struct for usage with go-flags
Tower bool `long:"tower" description:"Watchtower: Run a watching node"`
Hard bool `short:"t" long:"hard" description:"Flag to set networks."`

// logging, bool because that's how the tool works
LogLevel []bool `short:"v" long:"verbose" description:"Set verbosity level from 0 to 5 (most to least)"`
// logging and debug parameters
LogLevel []bool `short:"v" description:"Set verbosity level to verbose (-v), very verbose (-vv) or very very verbose (-vvv)"`

// rpc server config
Rpcport uint16 `short:"p" long:"rpcport" description:"Set RPC port to connect to"`
Expand All @@ -72,7 +72,7 @@ var (
defaultAutoListenPort = ":2448"
defaultAutoReconnectInterval = int64(60)
defaultUpnPFlag = false
defaultLogLevel = 3 // reasons
defaultLogLevel = 0
defaultAutoReconnectOnlyConnectedCoins = false
defaultUnauthRPC = false
)
Expand Down Expand Up @@ -214,7 +214,6 @@ func main() {
AutoListenPort: defaultAutoListenPort,
AutoReconnectInterval: defaultAutoReconnectInterval,
AutoReconnectOnlyConnectedCoins: defaultAutoReconnectOnlyConnectedCoins,
LogLevel: []bool{}, // reasons
UnauthRPC: defaultUnauthRPC,
}

Expand All @@ -224,7 +223,7 @@ func main() {
conf.ChainProxyURL = conf.ProxyURL
}

// SIGQUIT hander for debugging
// SIGQUIT handler for debugging
go func() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGQUIT)
Expand Down
16 changes: 10 additions & 6 deletions litinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ func litSetup(conf *litConfig) *[32]byte {
// Load config from file and parse
parser := newConfigParser(conf, flags.Default)

// set default log level here
logging.SetLogLevel(defaultLogLevel)
// create home directory
_, err = os.Stat(conf.LitHomeDir)
if err != nil {
Expand Down Expand Up @@ -118,13 +120,15 @@ func litSetup(conf *litConfig) *[32]byte {
// TODO ... what's this do?
defer logFile.Close()

// special handling for this one.
ll := len(conf.LogLevel)
if ll > 0 {
logging.SetLogLevel(len(conf.LogLevel))
} else {
logging.SetLogLevel(defaultLogLevel)
logLevel := -1
if len(conf.LogLevel) == 1 { // -v
logLevel = 1
} else if len(conf.LogLevel) == 2 { // -vv
logLevel = 2
} else if len(conf.LogLevel) >= 3 {
logLevel = 3
}
logging.SetLogLevel(logLevel)

// Allow node with no linked wallets, for testing.
// TODO Should update tests and disallow nodes without wallets later.
Expand Down
11 changes: 5 additions & 6 deletions logging/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (
type LogLevel int

const (
LogLevelPanicOrFatal LogLevel = 0
LogLevelError LogLevel = 1
LogLevelWarning LogLevel = 2
LogLevelInfo LogLevel = 3
LogLevelDebug LogLevel = 4
LogLevelError LogLevel = 0
LogLevelWarning LogLevel = 1
LogLevelInfo LogLevel = 2
LogLevelDebug LogLevel = 3
)

var logLevel = LogLevelPanicOrFatal
var logLevel = LogLevelError

func SetLogLevel(newLevel int) {
logLevel = LogLevel(newLevel)
Expand Down

0 comments on commit ef18f29

Please sign in to comment.