func ExampleLogger_ToConsole() { // Simply log to console. ol.Info.Println(nil, "The log text.") ol.Trace.Println(nil, "The log text.") ol.Warn.Println(nil, "The log text.") ol.Error.Println(nil, "The log text.") // Use short aliases. ol.I(nil, "The log text.") ol.T(nil, "The log text.") ol.W(nil, "The log text.") ol.E(nil, "The log text.") }
// http standard error response. // @remark for not SystemError, we will use logger.E to print it. // @remark user can use WriteError() for simple api. func Error(ctx ol.Context, err error) http.Handler { // for complex error, use code instead. if v, ok := err.(SystemComplexError); ok { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ol.E(ctx, "Serve", r.URL, "failed. err is", err.Error()) jsonHandler(ctx, v).ServeHTTP(w, r) }) } // for int error, use code instead. if v, ok := err.(SystemError); ok { return jsonHandler(ctx, map[string]int{"code": int(v)}) } return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { SetHeader(w) w.Header().Set("Content-Type", HttpJson) // unknown error, log and response detail http.Error(w, err.Error(), http.StatusInternalServerError) ol.E(ctx, "Serve", r.URL, "failed. err is", err.Error()) }) }
func (v *aspContextNoExit) WatchParent() { ppid := os.Getppid() go func() { for { if pid := os.Getppid(); pid == 1 || pid != ppid { ol.E(v.ctx, "quit for parent problem, ppid is", pid) select { case v.quit <- true: default: } break } //ol.T(v.ctx, "parent pid", ppid, "ok") time.Sleep(v.interval) } }() ol.T(v.ctx, "parent process watching, ppid is", ppid) }
func (v *aspContext) WatchParent() { ppid := os.Getppid() go func() { for { if pid := os.Getppid(); pid == 1 || pid != ppid { ol.E(v.ctx, "quit for parent problem, ppid is", pid) if v.callback != nil { v.callback() } os.Exit(0) } //ol.T(v.ctx, "parent pid", ppid, "ok") time.Sleep(v.interval) } }() ol.T(v.ctx, "parent process watching, ppid is", ppid) }