gdritter repos bb8 / master src / BB8 / Common.hs
master

Tree @master (Download .tar.gz)

Common.hs @masterraw · history · blame

module BB8.Common (debug, debugShow) where

import qualified Control.Concurrent.MVar as M
import qualified Data.Time.Clock as Time
import qualified Data.Time.Format as Time
import qualified System.IO.Unsafe as Sys
import qualified System.IO as Sys

globalLock :: M.MVar ()
globalLock = Sys.unsafePerformIO $ M.newMVar ()

debug :: String -> IO ()
debug msg = M.withMVar globalLock $ \ () -> do
  now <- Time.formatTime Time.defaultTimeLocale "%F %T:%q: " <$> Time.getCurrentTime
  Sys.hPutStrLn Sys.stderr (now ++ msg)

debugShow :: (Show t) => t -> IO ()
debugShow = debug . show