From 80cecf1ed3c1f46934071e8685f3c2ae3c8de2ed Mon Sep 17 00:00:00 2001 From: appleboy Date: Sun, 23 Jul 2023 07:30:08 +0800 Subject: [PATCH] refactor: improve code clarity and logging functionality - Add a comment to clarify the purpose of the `format` function - Add a comment to clarify the purpose of the `log` function - Modify the `log` function to always print the message, removing the previous conditional statement Signed-off-by: appleboy --- plugin.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin.go b/plugin.go index 582e2bb..d17792b 100644 --- a/plugin.go +++ b/plugin.go @@ -155,20 +155,23 @@ loop: } } +// format string func (p Plugin) format(format string, args ...string) string { r := strings.NewReplacer(args...) return r.Replace(format) } +// log output to console func (p Plugin) log(host string, message ...interface{}) { if p.Writer == nil { p.Writer = os.Stdout } if count := len(p.Config.Host); count == 1 { fmt.Fprintf(p.Writer, "%s", fmt.Sprintln(message...)) - } else { - fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...)) + return } + + fmt.Fprintf(p.Writer, "%s: %s", host, fmt.Sprintln(message...)) } // Exec executes the plugin.