Skip to content

Commit

Permalink
Merge pull request #14 from kubescape/logger-message
Browse files Browse the repository at this point in the history
Adding details to the spinner message
  • Loading branch information
matthyx committed Aug 10, 2023
2 parents 0ab446e + 802df4e commit 4b73283
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
24 changes: 14 additions & 10 deletions prettylogger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,21 @@ func (pl *PrettyLogger) Success(msg string, details ...helpers.IDetails) {
pl.print(helpers.SuccessLevel, msg, details...)
}
func (pl *PrettyLogger) Start(msg string, details ...helpers.IDetails) {
pl.StartSpinner(pl.writer, msg)
pl.StartSpinner(pl.writer, generateMessage(msg, details))
}
func (pl *PrettyLogger) StopSuccess(msg string, details ...helpers.IDetails) {
pl.StopSpinner(getSymbol("success") + msg + "\n")
pl.StopSpinner(getSymbol("success") + generateMessage(msg, details) + "\n")
}
func (pl *PrettyLogger) StopError(msg string, details ...helpers.IDetails) {
pl.StopSpinner(getSymbol("error") + msg + "\n")
pl.StopSpinner(getSymbol("error") + generateMessage(msg, details) + "\n")
}

func (pl *PrettyLogger) print(level helpers.Level, msg string, details ...helpers.IDetails) {
pl.PauseSpinner()
if !level.Skip(pl.level) {
pl.mutex.Lock()
prefix(level)(pl.writer, "%s", getSymbol(level.String()))
if d := detailsToString(details); d != "" {
msg = fmt.Sprintf("%s. %s", msg, d)
}
message(pl.writer, fmt.Sprintf("%s\n", msg))
message(pl.writer, fmt.Sprintf("%s\n", generateMessage(msg, details)))
pl.mutex.Unlock()
}
pl.ResumeSpinner()
Expand All @@ -103,12 +100,19 @@ func getSymbol(level string) string {
case "warning":
return "❗ "
case "success":
return "✔️ "
return " "
case "fatal", "error":
return "❌ "
case "debug":
return " "
return "🐞 "
default:
return "〜 "
return "ℹ️ "
}
}

func generateMessage(msg string, details []helpers.IDetails) string {
if d := detailsToString(details); d != "" {
msg = fmt.Sprintf("%s. %s", msg, d)
}
return msg
}
6 changes: 3 additions & 3 deletions prettylogger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,11 @@ func TestGetSymbol(t *testing.T) {
expect string
}{
{"Warning", "warning", "❗ "},
{"Success", "success", "✔️ "},
{"Success", "success", " "},
{"Fatal", "fatal", "❌ "},
{"Error", "error", "❌ "},
{"Debug", "debug", " "},
{"Default", "info", " "},
{"Debug", "debug", "🐞 "},
{"Default", "info", "ℹ️ "},
}

for _, tt := range tests {
Expand Down

0 comments on commit 4b73283

Please sign in to comment.