mirror of
https://github.com/beego/bee.git
synced 2024-11-30 03:11:28 +00:00
84 lines
1.7 KiB
Go
84 lines
1.7 KiB
Go
package logflags
|
|
|
|
import (
|
|
"errors"
|
|
"io/ioutil"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
var debugger = false
|
|
var gdbWire = false
|
|
var lldbServerOutput = false
|
|
var debugLineErrors = false
|
|
var rpc = false
|
|
var fnCall = false
|
|
|
|
// GdbWire returns true if the gdbserial package should log all the packets
|
|
// exchanged with the stub.
|
|
func GdbWire() bool {
|
|
return gdbWire
|
|
}
|
|
|
|
// Debugger returns true if the debugger package should log.
|
|
func Debugger() bool {
|
|
return debugger
|
|
}
|
|
|
|
// LLDBServerOutput returns true if the output of the LLDB server should be
|
|
// redirected to standard output instead of suppressed.
|
|
func LLDBServerOutput() bool {
|
|
return lldbServerOutput
|
|
}
|
|
|
|
// DebugLineErrors returns true if pkg/dwarf/line should log its recoverable
|
|
// errors.
|
|
func DebugLineErrors() bool {
|
|
return debugLineErrors
|
|
}
|
|
|
|
// RPC returns true if rpc messages should be logged.
|
|
func RPC() bool {
|
|
return rpc
|
|
}
|
|
|
|
// FnCall returns true if the function call protocol should be logged.
|
|
func FnCall() bool {
|
|
return fnCall
|
|
}
|
|
|
|
var errLogstrWithoutLog = errors.New("--log-output specified without --log")
|
|
|
|
// Setup sets debugger flags based on the contents of logstr.
|
|
func Setup(logFlag bool, logstr string) error {
|
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
if !logFlag {
|
|
log.SetOutput(ioutil.Discard)
|
|
if logstr != "" {
|
|
return errLogstrWithoutLog
|
|
}
|
|
return nil
|
|
}
|
|
if logstr == "" {
|
|
logstr = "debugger"
|
|
}
|
|
v := strings.Split(logstr, ",")
|
|
for _, logcmd := range v {
|
|
switch logcmd {
|
|
case "debugger":
|
|
debugger = true
|
|
case "gdbwire":
|
|
gdbWire = true
|
|
case "lldbout":
|
|
lldbServerOutput = true
|
|
case "debuglineerr":
|
|
debugLineErrors = true
|
|
case "rpc":
|
|
rpc = true
|
|
case "fncall":
|
|
fnCall = true
|
|
}
|
|
}
|
|
return nil
|
|
}
|