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:
@ -1,6 +1,7 @@
|
||||
package logging
|
||||
|
||||
import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/op/go-logging"
|
||||
@ -13,7 +14,7 @@ const (
|
||||
var (
|
||||
Log *CTopLogger
|
||||
exited bool
|
||||
level = logging.INFO
|
||||
level = logging.INFO // default level
|
||||
format = logging.MustStringFormatter(
|
||||
`%{color}%{time:15:04:05.000} ▶ %{level:.4s} %{id:03x}%{color:reset} %{message}`,
|
||||
)
|
||||
@ -33,6 +34,11 @@ func Init() *CTopLogger {
|
||||
logging.NewMemoryBackend(size),
|
||||
}
|
||||
|
||||
if debugMode() {
|
||||
level = logging.DEBUG
|
||||
StartServer()
|
||||
}
|
||||
|
||||
backendLvl := logging.AddModuleLevel(Log.backend)
|
||||
backendLvl.SetLevel(level, "")
|
||||
|
||||
@ -71,3 +77,5 @@ func (log *CTopLogger) Exit() {
|
||||
exited = true
|
||||
StopServer()
|
||||
}
|
||||
|
||||
func debugMode() bool { return os.Getenv("CTOP_DEBUG") == "1" }
|
||||
|
Reference in New Issue
Block a user