| 149 | } |
| 150 | |
| 151 | func (m *RequestLogMiddleware) Handle(ctx Context) error { |
| 152 | var timeDuration time.Duration |
| 153 | var timeTaken uint64 |
| 154 | err := m.Next(ctx) |
| 155 | if ctx.Items().Exists(ItemKeyHandleDuration) { |
| 156 | var errParse error |
| 157 | timeDuration, errParse = time.ParseDuration(ctx.Items().GetString(ItemKeyHandleDuration)) |
| 158 | if errParse != nil { |
| 159 | timeTaken = 0 |
| 160 | } else { |
| 161 | timeTaken = uint64(timeDuration / time.Millisecond) |
| 162 | } |
| 163 | } else { |
| 164 | var begin time.Time |
| 165 | beginVal, exists := ctx.Items().Get(ItemKeyHandleStartTime) |
| 166 | if !exists { |
| 167 | begin = time.Now() |
| 168 | } else { |
| 169 | begin = beginVal.(time.Time) |
| 170 | } |
| 171 | timeTaken = uint64(time.Now().Sub(begin) / time.Millisecond) |
| 172 | } |
| 173 | log := ctx.Request().Url() + " " + logContext(ctx, timeTaken) |
| 174 | ctx.HttpServer().Logger().Debug(log, LogTarget_HttpRequest) |
| 175 | return err |
| 176 | } |
| 177 | |
| 178 | // get default log string |
| 179 | func logContext(ctx Context, timetaken uint64) string { |