Skip to content

Commit

Permalink
Add colours (#168)
Browse files Browse the repository at this point in the history
* Note in README

* update README

* Adding some colour to output to help quickly scan logs

* add colored debug log when considering URI

* turn off color

* remove my README header

---------

Co-authored-by: Jonathan C. Dietrich <jcdietrich@gmail.com>
  • Loading branch information
jdietrich-tc and jcdietrich committed Apr 25, 2024
1 parent 65368af commit 7b2ae02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/server/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (di *Dispatcher) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}

log.Infof("New request: %s %s\n", req.Method, req.URL.String())
log.Infof("\033[35mNew request:\033[0m %s %s\n", req.Method, req.URL.String())

mock, transaction := di.getMatchingResult(&mRequest)

Expand Down Expand Up @@ -138,9 +138,16 @@ func getProxyResponse(request *mock.Request, definition *mock.Definition) *mock.

func (di *Dispatcher) getMatchingResult(request *mock.Request) (*mock.Definition, *match.Transaction) {
var response *mock.Response
var colour = "\033[31m"
var stop_colour = "\033[0m"
mock, result := di.Resolver.Resolve(request)

log.Infof("Definition match found: %s. Name : %s\n", strconv.FormatBool(result.Found), mock.URI)
if result.Found {
colour = "\033[32m"
}

log.Infof("%sDefinition match found:%s%s. Name : %s\n", colour, stop_colour, strconv.FormatBool(result.Found), mock.URI)


if result.Found {
if len(mock.Control.ProxyBaseURL) > 0 {
Expand Down
3 changes: 2 additions & 1 deletion internal/server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (rr *Router) Resolve(req *mock.Request) (*mock.Definition, *match.Result) {
mLog.Errors = make([]match.Error, 0, len(mocks))

for _, m := range mocks {
log.Debugf("\033[34mConsidering:\033[0m %s", m.URI)
r, err := rr.Checker.Match(req, &m, true)
if r {
//we return a copy of it, not the config itself because we will working on it.
Expand All @@ -61,7 +62,7 @@ func (rr *Router) Resolve(req *mock.Request) (*mock.Definition, *match.Result) {
}
mLog.Errors = append(mLog.Errors, match.Error{URI: m.URI, Reason: err.Error()})
if !errors.Is(err, match.ErrPathNotMatch) {
log.Infof("Discarding mock: %s Reason: %s\n", m.URI, err.Error())
log.Infof("\033[31mDiscarding mock:\033[0m %s Reason: %s\n", m.URI, err.Error())
}
}
return getNotFoundResult(), mLog
Expand Down

0 comments on commit 7b2ae02

Please sign in to comment.