Skip to content

Commit

Permalink
update logging to use rediscmd.CmdString
Browse files Browse the repository at this point in the history
  • Loading branch information
mjc-gh committed Mar 5, 2024
1 parent c5749bd commit eaf9a5d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ go 1.19

require (
github.com/fatih/color v1.16.0
github.com/redis/go-redis/v9 v9.0.2
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5
github.com/redis/go-redis/v9 v9.0.5
github.com/stretchr/testify v1.8.2
)

Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5 h1:EaDatTxkdHG+U3Bk4EUr+DZ7fOGwTfezUiUJMaIcaho=
github.com/redis/go-redis/extra/rediscmd/v9 v9.0.5/go.mod h1:fyalQWdtzDBECAQFBJuQe5bzQ02jGd5Qcbgb97Flm7U=
github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE=
github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
github.com/redis/go-redis/v9 v9.0.5/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
25 changes: 10 additions & 15 deletions logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/fatih/color"
"github.com/redis/go-redis/extra/rediscmd/v9"
"github.com/redis/go-redis/v9"
)

Expand Down Expand Up @@ -55,24 +56,18 @@ var keyColor = color.New(color.FgCyan).SprintFunc()
var argsColor = color.New(color.FgGreen).SprintFunc()

func cmdLogParts(cmd redis.Cmder) (string, string, string) {
var name string
var key string
var args []string

cmdArgs := cmd.Args()
name := cmdColor(strings.ToUpper(cmd.Name()))

if len(cmdArgs) > 1 {
switch cmdArgs[1].(type) {
case int64:
key = keyColor(cmdArgs[1].(int64))
default:
key = keyColor(cmdArgs[1].(string))
}
}

if len(cmdArgs) > 2 {
for _, cmdArg := range cmdArgs[2:] {
args = append(args, argsColor(fmt.Sprintf("%v", cmdArg)))
cmdStr := rediscmd.CmdString(cmd)
for idx, str := range strings.Split(cmdStr, " ") {
if idx == 0 {
name = cmdColor(strings.ToUpper(str))
} else if idx == 1 {
key = keyColor(str)
} else {
args = append(args, argsColor(str))
}
}

Expand Down

0 comments on commit eaf9a5d

Please sign in to comment.