From 7d34d2c51841548618d0a7eb51f6e424f4f56764 Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Mon, 21 May 2018 13:22:28 -0300 Subject: [PATCH] cli: copied LogRequest() call from HTTP handler --- executor.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/executor.go b/executor.go index a5a968b5..bba1751a 100644 --- a/executor.go +++ b/executor.go @@ -38,6 +38,16 @@ type executor struct { root *Command } +// RequestLogger copies the `LogRequest` method from +// `github.com/ipfs/go-ipfs/commands.Context`. +// Copied from the `http` package as now the request are logged +// both online (HTTP) and offline (CLI, `cmds`) but removed the `cmd` +// import prefix, the `Request` already belongs to this package. +// TODO: How to unify both? +type RequestLogger interface { + LogRequest(*Request) func() +} + func (x *executor) Execute(req *Request, re ResponseEmitter, env Environment) (err error) { cmd := req.Command @@ -105,6 +115,12 @@ func (x *executor) Execute(req *Request, re ResponseEmitter, env Environment) (e } }() + + if reqLogger, ok := env.(RequestLogger); ok { + done := reqLogger.LogRequest(req) + defer done() + } + cmd.Run(req, re, env) return nil }