зеркало из https://github.com/mozilla/mig.git
[minor] support debug mode in api
This commit is contained in:
Родитель
ad47c222cc
Коммит
9d21c89e11
|
@ -30,6 +30,7 @@ func main() {
|
||||||
|
|
||||||
// command line options
|
// command line options
|
||||||
var config = flag.String("c", "/etc/mig/api.cfg", "Load configuration from file")
|
var config = flag.String("c", "/etc/mig/api.cfg", "Load configuration from file")
|
||||||
|
var debug = flag.Bool("d", false, "Debug mode: run in foreground, log to stdout.")
|
||||||
var showversion = flag.Bool("V", false, "Show build version and exit")
|
var showversion = flag.Bool("V", false, "Show build version and exit")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ func main() {
|
||||||
// The context initialization takes care of parsing the configuration,
|
// The context initialization takes care of parsing the configuration,
|
||||||
// and creating connections to database, syslog, ...
|
// and creating connections to database, syslog, ...
|
||||||
fmt.Fprintf(os.Stderr, "Initializing API context...")
|
fmt.Fprintf(os.Stderr, "Initializing API context...")
|
||||||
ctx, err = Init(*config) //ctx is a global variable
|
ctx, err = Init(*config, *debug) //ctx is a global variable
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("\nFATAL: %v\n", err)
|
fmt.Printf("\nFATAL: %v\n", err)
|
||||||
os.Exit(9)
|
os.Exit(9)
|
||||||
|
|
|
@ -52,7 +52,7 @@ type Context struct {
|
||||||
|
|
||||||
// Init() initializes a context from a configuration file into an
|
// Init() initializes a context from a configuration file into an
|
||||||
// existing context struct
|
// existing context struct
|
||||||
func Init(path string) (ctx Context, err error) {
|
func Init(path string, debug bool) (ctx Context, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
err = fmt.Errorf("Init() -> %v", e)
|
err = fmt.Errorf("Init() -> %v", e)
|
||||||
|
@ -71,6 +71,10 @@ func Init(path string) (ctx Context, err error) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if debug {
|
||||||
|
ctx.Logging.Level = "debug"
|
||||||
|
ctx.Logging.Mode = "stdout"
|
||||||
|
}
|
||||||
ctx.Logging, err = mig.InitLogger(ctx.Logging, "mig-api")
|
ctx.Logging, err = mig.InitLogger(ctx.Logging, "mig-api")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|
Загрузка…
Ссылка в новой задаче