OverrideRuntimeErrorHandler overrides the standard runtime error handler that logs to stdout with a file logger that logs all runtime.HandleErrors to errors.log
(discard bool)
| 67 | // OverrideRuntimeErrorHandler overrides the standard runtime error handler that logs to stdout |
| 68 | // with a file logger that logs all runtime.HandleErrors to errors.log |
| 69 | func OverrideRuntimeErrorHandler(discard bool) { |
| 70 | overrideOnce.Do(func() { |
| 71 | if discard { |
| 72 | if len(runtime.ErrorHandlers) > 0 { |
| 73 | runtime.ErrorHandlers[0] = func(err error) {} |
| 74 | } else { |
| 75 | runtime.ErrorHandlers = []func(err error){ |
| 76 | func(err error) {}, |
| 77 | } |
| 78 | } |
| 79 | } else { |
| 80 | errorLog := GetFileLogger("errors") |
| 81 | if len(runtime.ErrorHandlers) > 0 { |
| 82 | runtime.ErrorHandlers[0] = func(err error) { |
| 83 | errorLog.Errorf("Runtime error occurred: %s", err) |
| 84 | } |
| 85 | } else { |
| 86 | runtime.ErrorHandlers = []func(err error){ |
| 87 | func(err error) { |
| 88 | errorLog.Errorf("Runtime error occurred: %s", err) |
| 89 | }, |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | }) |
| 94 | } |
| 95 | |
| 96 | func (f *fileLogger) addPrefixes(message string) string { |
| 97 | prefix := "" |
no test coverage detected