{-|
    Module      :  Control.ERNet.Foundations.Event.Logger
    Description :  processes and channels within networks
    Copyright   :  (c) Michal Konecny
    License     :  BSD3

    Maintainer  :  mik@konecny.aow.cz
    Stability   :  experimental
    Portability :  portable

    Abstraction of an event logger in the IO monad.
    
    To be imported qualified, usually with the prefix LG.
-}
module Control.ERNet.Foundations.Event.Logger where

import Control.ERNet.Foundations.Event

class Logger lg where
    new :: IO lg
    addEvent :: lg -> ERNetEvent -> IO ()
    emptyAndDo :: lg -> (ERNetEvent -> IO a) -> IO ()
    emptyAndGetEvents :: lg -> IO ([ERNetEvent])

putLogWhileRunning logger =
    emptyAndDo logger (putStrLn . show)

putCompleteLog logger =
    do
    events <- emptyAndGetEvents logger
    putStrLn $ unlines $ map show events