Skip to content

Commit

Permalink
kpkg: modules/logger: streamline debug mode, make sure it works the s…
Browse files Browse the repository at this point in the history
…ame across all places
  • Loading branch information
kreatoo committed Dec 23, 2024
1 parent 0987dbe commit 9a6c837
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions kpkg/modules/logger.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -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"
Expand Down

0 comments on commit 9a6c837

Please sign in to comment.