mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
Toggle debug mode via env var
remove logging param from global config, allowing logging server and level to be configured inside logging subpackage from CTOP_DEBUG env var
This commit is contained in:
parent
35cc8d095d
commit
8aa932b29f
@ -18,7 +18,6 @@ func Init() {
|
|||||||
GlobalParams = append(GlobalParams, p)
|
GlobalParams = append(GlobalParams, p)
|
||||||
log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
|
log.Infof("loaded config param: %s: %s", quote(p.Key), quote(p.Val))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, s := range switches {
|
for _, s := range switches {
|
||||||
GlobalSwitches = append(GlobalSwitches, s)
|
GlobalSwitches = append(GlobalSwitches, s)
|
||||||
log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)
|
log.Infof("loaded config switch: %s: %t", quote(s.Key), s.Val)
|
||||||
|
@ -17,11 +17,6 @@ var switches = []*Switch{
|
|||||||
Val: true,
|
Val: true,
|
||||||
Label: "Enable Status Header",
|
Label: "Enable Status Header",
|
||||||
},
|
},
|
||||||
&Switch{
|
|
||||||
Key: "loggingEnabled",
|
|
||||||
Val: false,
|
|
||||||
Label: "Enable Logging Server",
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Switch struct {
|
type Switch struct {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package logging
|
package logging
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/op/go-logging"
|
"github.com/op/go-logging"
|
||||||
@ -13,7 +14,7 @@ const (
|
|||||||
var (
|
var (
|
||||||
Log *CTopLogger
|
Log *CTopLogger
|
||||||
exited bool
|
exited bool
|
||||||
level = logging.INFO
|
level = logging.INFO // default level
|
||||||
format = logging.MustStringFormatter(
|
format = logging.MustStringFormatter(
|
||||||
`%{color}%{time:15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
`%{color}%{time:15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
||||||
)
|
)
|
||||||
@ -33,6 +34,11 @@ func Init() *CTopLogger {
|
|||||||
logging.NewMemoryBackend(size),
|
logging.NewMemoryBackend(size),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debugMode() {
|
||||||
|
level = logging.DEBUG
|
||||||
|
StartServer()
|
||||||
|
}
|
||||||
|
|
||||||
backendLvl := logging.AddModuleLevel(Log.backend)
|
backendLvl := logging.AddModuleLevel(Log.backend)
|
||||||
backendLvl.SetLevel(level, "")
|
backendLvl.SetLevel(level, "")
|
||||||
|
|
||||||
@ -71,3 +77,5 @@ func (log *CTopLogger) Exit() {
|
|||||||
exited = true
|
exited = true
|
||||||
StopServer()
|
StopServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
|
||||||
|
15
main.go
15
main.go
@ -25,9 +25,6 @@ var (
|
|||||||
func main() {
|
func main() {
|
||||||
defer panicExit()
|
defer panicExit()
|
||||||
|
|
||||||
// init global config
|
|
||||||
config.Init()
|
|
||||||
|
|
||||||
// parse command line arguments
|
// parse command line arguments
|
||||||
var versionFlag = flag.Bool("v", false, "output version information and exit")
|
var versionFlag = flag.Bool("v", false, "output version information and exit")
|
||||||
var helpFlag = flag.Bool("h", false, "display this help dialog")
|
var helpFlag = flag.Bool("h", false, "display this help dialog")
|
||||||
@ -48,6 +45,12 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init logger
|
||||||
|
log = logging.Init()
|
||||||
|
|
||||||
|
// init global config
|
||||||
|
config.Init()
|
||||||
|
|
||||||
// override default config values with command line flags
|
// override default config values with command line flags
|
||||||
if *filterFlag != "" {
|
if *filterFlag != "" {
|
||||||
config.Update("filterStr", *filterFlag)
|
config.Update("filterStr", *filterFlag)
|
||||||
@ -66,12 +69,6 @@ func main() {
|
|||||||
config.Toggle("sortReversed")
|
config.Toggle("sortReversed")
|
||||||
}
|
}
|
||||||
|
|
||||||
// init logger
|
|
||||||
log = logging.Init()
|
|
||||||
if config.GetSwitchVal("loggingEnabled") {
|
|
||||||
logging.StartServer()
|
|
||||||
}
|
|
||||||
|
|
||||||
// init ui
|
// init ui
|
||||||
if *invertFlag {
|
if *invertFlag {
|
||||||
InvertColorMap()
|
InvertColorMap()
|
||||||
|
Loading…
Reference in New Issue
Block a user