func (r *LogEntry) finishOperation(suppress bool) { entry := cli.Log.WithFields(logrus.Fields{ "duration_ms": calculateDurationMillis(r.startTime), "status": r.status, "pid": os.Getpid(), }) if r.path != "" { entry = entry.WithField("path", r.path) } if r.args != "" { entry = entry.WithField("args", r.args) } if r.result != "" { entry = entry.WithField("result", r.result) } if r.cacheUsed { entry = entry.WithField("cache_hit", r.cacheHit) } if !suppress { entry.Debug(r.name) } if r.err != nil { cli.Log.Errorln(util.ErrorWithCauseChain(r.err)) } r.logTrace(entry) }
func TestFileBufferSync(t *testing.T) { dev := &delegateDeviceClient{ stat: statFiles(&goadb.DirEntry{ Name: "/file", Mode: 0664, }), openRead: openReadString("hello"), } file := newTestFileBuffer(t, O_RDONLY, FileBufferOptions{ Path: "/file", Client: dev, }) assert.Equal(t, "hello", file.Contents()) // Success. dev.openRead = openReadString("world") err := file.Sync(&LogEntry{}) assert.NoError(t, err) assert.Equal(t, "world", file.Contents()) // Failure. dev.openRead = openReadError(util.Errorf(util.NetworkError, "fail")) err = file.Sync(&LogEntry{}) assert.Equal(t, `NetworkError: error opening file stream on device caused by NetworkError: fail`, util.ErrorWithCauseChain(err)) assert.Equal(t, "world", file.Contents()) }
func (r *LogEntry) logTrace(entry *logrus.Entry) { var msg string // Use a different formatter for logging to HTML trace viewer since the TextFormatter will include color escape codes. msgBytes, err := traceEntryFormatter.Format(entry) if err != nil { msg = fmt.Sprint(entry) } else { msg = string(msgBytes) } r.trace.LazyPrintf("%s", msg) if r.err != nil { r.trace.SetError() r.trace.LazyPrintf("%s", util.ErrorWithCauseChain(r.err)) } r.trace.Finish() }
// ErrorMsg records a failure result. // Panics if called more than once. func (r *LogEntry) ErrorMsg(err error, msg string, args ...interface{}) { r.Error(fmt.Errorf("%s: %v", fmt.Sprintf(msg, args...), util.ErrorWithCauseChain(err))) }