@@ -79,6 +79,7 @@ module Control.Distributed.Process.Internal.Primitives
79 , withMonitor
79 , withMonitor
80 , withMonitor_
80 , withMonitor_
81 -- * Logging
81 -- * Logging
83 -- * Registry
84 -- * Registry
84 , register
85 , register
@@ -126,8 +127,9 @@ module Control.Distributed.Process.Internal.Primitives
126import Prelude hiding (catch)
127import Prelude hiding (catch)
129−import Data.Binary (decode)
130+import Data.Binary (Binary(..), Put, Get, decode)
130−import Data.Time.Clock (getCurrentTime)
131+import Data.Time.Clock (getCurrentTime, UTCTime(..))
132+import Data.Time.Calendar (Day(..))
131import Data.Time.Format (formatTime)
133import Data.Time.Format (formatTime)
132#if MIN_VERSION_time(1,5,0)
134#if MIN_VERSION_time(1,5,0)
133import Data.Time.Format (defaultTimeLocale)
135import Data.Time.Format (defaultTimeLocale)
@@ -1077,17 +1079,52 @@ unlinkPortAsync (SendPort cid) =
1077-- Logging --
1079-- Logging --
1078--------------------------------------------------------------------------------
1080--------------------------------------------------------------------------------
1082+data SayMessage = SayMessage { sayTime :: UTCTime
1083+ , sayProcess :: ProcessId
1084+ , sayMessage :: String }
1085+ deriving (Typeable)
1087+-- There is sadly no Show UTCTime instance
1088+instance Show SayMessage where
1090+ showParen (p >= 11)
1091+ $ showString "SayMessage "
1092+ . showString (formatTime defaultTimeLocale "%c" (sayTime msg))
1094+ . showsPrec 11 (sayProcess msg) . showChar ' '
1095+ . showsPrec 11 (sayMessage msg) . showChar ' '
1097+instance Binary SayMessage where
1099+ putUTCTime (sayTime s)
1102+ get = SayMessage <$> getUTCTime <*> get <*> get
1104+-- Sadly there is no Binary UTCTime instance
1105+putUTCTime :: UTCTime -> Put
1106+putUTCTime (UTCTime (ModifiedJulianDay day) tod) = do
1108+ put (toRational tod)
1110+getUTCTime :: Get UTCTime
1114+ return $! UTCTime (ModifiedJulianDay day)
1080-- | Log a string
1117-- | Log a string
1082−-- @say message@ sends a message (time, pid of the current process, message)
1119+-- @say message@ sends a message of type 'SayMessage' with the current time and
1083−-- to the process registered as 'logger'. By default, this process simply
1120+-- 'ProcessId' of the current process to the process registered as @logger@. By
1084−-- sends the string to 'stderr'. Individual Cloud Haskell backends might
1121+-- default, this process simply sends the string to @stderr@. Individual Cloud
1085−-- replace this with a different logger process, however.
1122+-- Haskell backends might replace this with a different logger process, however.
1086say :: String -> Process ()
1123say :: String -> Process ()
1087say string = do
1124say string = do
1088 now <- liftIO getCurrentTime
1125 now <- liftIO getCurrentTime
1089 us <- getSelfPid
1126 us <- getSelfPid
1090− nsend "logger" (formatTime defaultTimeLocale "%c" now, us, string)
1127+ nsend "logger" (SayMessage now us string)
1092--------------------------------------------------------------------------------
1129--------------------------------------------------------------------------------
1093-- Registry --
1130-- Registry --