-- Copyright: 2009 Dino Morelli
-- License: BSD3 (see LICENSE)
-- Author: Dino Morelli <dino@ui3.info>

{-# LANGUAGE FlexibleContexts #-}

module Erbu.Log
   ( LogEvent (..), logMsg )
   where

import Control.Monad
import System.Locale ( defaultTimeLocale )
import System.Time ( formatCalendarTime , getClockTime , toCalendarTime )
import Text.Printf ( printf )


data LogEvent = STATUS | COMMAND | ERROR
   deriving Show


-- Format the time right now
date :: IO String
date = liftM ( formatCalendarTime defaultTimeLocale "%Y-%m-%d %H:%M:%S")
   $ getClockTime >>= toCalendarTime


logMsg :: LogEvent -> String -> IO ()
logMsg event msg = do
   d <- date
   printf "%s %-7s: %s\n" d (show event) msg

