{-# LANGUAGE FlexibleContexts #-}{-# LANGUAGE OverloadedStrings #-}{-# LANGUAGE NoImplicitPrelude #-}module HWM.Runtime.Logging (logIssue, debug) whereimport Data.Time (getCurrentTime)import HWM.Core.Common (Name)import HWM.Core.Formatting (Color (Cyan), chalk)import HWM.Core.Options (whenCI, whenDebug)import HWM.Core.Result (Severity)import HWM.Runtime.Files (prepareDir)import HWM.Runtime.UI (MonadUI, putLine)import Reludeimport qualified System.IO as TIOlogRoot :: FilePathlogRoot = ".hwm/logs"logPath :: Name -> FilePathlogPath name = logRoot <> "/" <> toString name <> ".log"logIssue :: (MonadIO m, MonadUI m) => Name -> Severity -> [(Text, Text)] -> Text -> m FilePathlogIssue name severity table content = do prepareDir logRoot timestamp <- liftIO getCurrentTime let logInfo = [("TIMESTAMP", show timestamp), ("SEVERITY", show severity)] let path = logPath name let boxTop = "┌──────────────────────────────────────────────────────────" boxBottom = "└──────────────────────────────────────────────────────────" rows = map (\(k, v) -> "│ " <> k <> ": " <> v) (table <> logInfo) header = unlines (boxTop : rows <> [boxBottom, "", content, ""]) liftIO $ TIO.appendFile path (toString header) whenCI $ putLine content pure pathdebug :: (MonadIO m, MonadUI m) => Text -> m ()debug msg = whenDebug $ putLine $ chalk Cyan "[DEBUG] " <> msg