From 979f26e24dbe22b137f90428b4ec5e6a46160b27 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Wed, 13 Nov 2024 17:02:47 +1300 Subject: [PATCH 1/2] feat: add helper function to check whether -check flag used --- health/check.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/health/check.go b/health/check.go index f9029a9..a770ae6 100644 --- a/health/check.go +++ b/health/check.go @@ -2,6 +2,7 @@ package health import ( "context" + "flag" "fmt" "io" "net/http" @@ -66,3 +67,14 @@ func CheckStatus(servicePath string, timeout time.Duration) int { return 0 } + +// RunningHealthCheck returns whether the -check flag was used when starting the program. +// This flag indicates that the program is being used to run a health check on another program. +func RunningHealthCheck() bool { + + var isHealthCheck bool + flag.BoolVar(&isHealthCheck, "check", false, "Whether the program is being used to run a health check") + flag.Parse() + + return isHealthCheck +} From 7c048c2eebf9618c9f6bde80b4f236039cccdc37 Mon Sep 17 00:00:00 2001 From: bpeng Date: Fri, 15 Nov 2024 11:01:08 +1300 Subject: [PATCH 2/2] minor change for slogger to not print duplicate messages --- slogger/logger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slogger/logger.go b/slogger/logger.go index 653cf34..5f45a8f 100644 --- a/slogger/logger.go +++ b/slogger/logger.go @@ -46,8 +46,8 @@ func (sl *SmartLogger) Log(message ...any) int { if repeated && now.Sub(sl.lastLogTime) <= sl.window { sl.repeatCount++ } else { - log.Println(msgString) if sl.repeatedPrefix != "" && !repeated { //this is a random message + log.Println(msgString) sl.lastMessage = "" // Reset lastMessage to avoid tracking it as a repeated message sl.lastLogTime = time.Time{} // Reset the time return 0