From 9a6c837764bcf4a542dc0c22a807e93004da0cd2 Mon Sep 17 00:00:00 2001 From: Kreato Date: Mon, 23 Dec 2024 04:16:31 +0300 Subject: [PATCH] kpkg: modules/logger: streamline debug mode, make sure it works the same across all places --- kpkg/modules/logger.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kpkg/modules/logger.nim b/kpkg/modules/logger.nim index 90fe099..9635545 100644 --- a/kpkg/modules/logger.nim +++ b/kpkg/modules/logger.nim @@ -2,12 +2,16 @@ import os import strutils import terminal +proc isDebugMode*(): bool = + ## Returns true if the debug mode is enabled. + return parseBool(getEnv("KPKG_ENABLE_DEBUG", $(not defined(release)))) + proc debug*(debug: string) = ## Handles debug messages. # KPKG_ENABLE_DEBUG will be "true" as default if # the binary is built as anything but release. - if parseBool(getEnv("KPKG_ENABLE_DEBUG", $(not defined(release)))): + if isDebugMode(): styledEcho("kpkg: ", fgYellow, "debug: ", fgDefault, debug) proc info*(info: string, exitAfterwards = false) = @@ -17,7 +21,7 @@ proc info*(info: string, exitAfterwards = false) = debug "infoProc: exiting" quit(0) -proc err*(error: string, removeLockFile = true, raiseExceptionInstead = parseBool(getEnv("KPKG_ENABLE_EXCEPTIONS", $(not defined(release))))) = +proc err*(error: string, removeLockFile = true, raiseExceptionInstead = isDebugMode()) = ## Handles errors. styledEcho("kpkg: ", fgRed, "error: ", fgDefault, error) echo "kpkg: if you think this is a bug, please open an issue at https://github.com/kreatolinux/src"