Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Safe HaskellNone

Util.Log

Contents

Description

Functions for logging.

Log msgs are used to report everything from errors and debug msgs to status reports. They are collected in a central place that writes them to a file in a machine-readable serialized format.

Synopsis

Documentation

configure :: (State -> State) -> IO.IO State Source #

Configure the logging system by modifying its internal state. Return the old state so you can restore it later.

msgs

data Msg Source #

Constructors

Msg 

Fields

data

with_dyn :: Typeable a => Text -> a -> Msg -> Msg Source #

other types

data Priority Source #

Constructors

Timer

Logs to determine where things are hanging when debugging a performance problem. Use LogView.ShowTimers to show the time elapsed between Timer logs.

Debug

Users don't look at this during normal use, but can be useful for debugging.

Notice

Informational msgs that the user might want to see. Progress messages in e.g. derivation and play status are included here.

Warn

Something went wrong in e.g. derivation. The user definitely wants to see this.

Error

Unexpected error in the app, which may quit. This is probably due to a bug.

Instances

Bounded Priority # 
Enum Priority # 
Eq Priority # 
Ord Priority # 
Read.Read Priority # 
Show Priority # 
Generics.Generic Priority # 

Associated Types

type Generics.Rep Priority :: * -> * #

Aeson.Types.ToJSON Priority # 
Aeson.Types.FromJSON Priority # 
Serialize.Serialize Priority # 
type Generics.Rep Priority # 

data State Source #

Logging state. Don't log if a handle is Nothing.

Constructors

State 

write_json :: Handle -> Msg -> IO.IO () Source #

Write logs as JSON to the given handle.

write_formatted :: Handle -> Msg -> IO.IO () Source #

Write logs as human-readable text.

msg :: CallStack.Stack => Priority -> Maybe Stack.Stack -> Text -> Msg Source #

Create a msg without initializing it, so it doesn't have to be in LogMonad.

msg_call_stack :: CallStack -> Priority -> Maybe Stack.Stack -> Text -> Msg Source #

Like msg but when you already have a CallStack.

add_prefix :: Text -> [Msg] -> [Msg] Source #

Prefix msgs with the given string.

trace_logs :: [Msg] -> a -> a Source #

Write log msgs with trace, for debugging.

LogT monad

class Monad m => LogMonad m where Source #

Previously there was an initialize_msg method, which could use the LogMonad to fill in fields, e.g. add_time. Those things can happen in write too, but the msg could be created in a different context from the call to write. In practice, though, I don't do that very much, and when I did it was usually because I wasn't in a LogMonad at all, so I used the pure msg function.

Minimal complete definition

write

Methods

write :: Msg -> m () Source #

Instances

LogMonad IO.IO # 

Methods

write :: Msg -> IO.IO () Source #

LogMonad Deriver # 

Methods

write :: Msg -> Deriver () Source #

Monad m => LogMonad (LogT m) # 

Methods

write :: Msg -> LogT m () Source #

Monad m => LogMonad (CmdT m) #

Give CmdT unlifted access to all the logging functions.

Methods

write :: Msg -> CmdT m () Source #

(Monoid w, LogMonad m) => LogMonad (WriterT w m) # 

Methods

write :: Msg -> WriterT w m () Source #

LogMonad m => LogMonad (StateT s m) # 

Methods

write :: Msg -> StateT s m () Source #

LogMonad m => LogMonad (StateT s m) # 

Methods

write :: Msg -> StateT s m () Source #

LogMonad m => LogMonad (ExceptT e m) # 

Methods

write :: Msg -> ExceptT e m () Source #

(Error e, LogMonad m) => LogMonad (ErrorT e m) # 

Methods

write :: Msg -> ErrorT e m () Source #

LogMonad m => LogMonad (ReaderT * r m) # 

Methods

write :: Msg -> ReaderT * r m () Source #

data LogT m a Source #

Instances

MonadTrans LogT # 

Methods

lift :: Monad m => m a -> LogT m a #

MonadError e m => MonadError e (LogT m) # 

Methods

throwError :: e -> LogT m a #

catchError :: LogT m a -> (e -> LogT m a) -> LogT m a #

MonadReader r m => MonadReader r (LogT m) # 

Methods

ask :: LogT m r #

local :: (r -> r) -> LogT m a -> LogT m a #

reader :: (r -> a) -> LogT m a #

MonadState st m => MonadState st (LogT m) # 

Methods

get :: LogT m st #

put :: st -> LogT m () #

state :: (st -> (a, st)) -> LogT m a #

Monad m => Monad (LogT m) # 

Methods

(>>=) :: LogT m a -> (a -> LogT m b) -> LogT m b #

(>>) :: LogT m a -> LogT m b -> LogT m b #

return :: a -> LogT m a #

fail :: String -> LogT m a #

Functor m => Functor (LogT m) # 

Methods

fmap :: (a -> b) -> LogT m a -> LogT m b #

(<$) :: a -> LogT m b -> LogT m a #

Monad m => Applicative.Applicative (LogT m) # 

Methods

pure :: a -> LogT m a #

(<*>) :: LogT m (a -> b) -> LogT m a -> LogT m b #

(*>) :: LogT m a -> LogT m b -> LogT m b #

(<*) :: LogT m a -> LogT m b -> LogT m a #

MonadIO m => MonadIO (LogT m) # 

Methods

liftIO :: IO.IO a -> LogT m a #

Monad m => LogMonad (LogT m) # 

Methods

write :: Msg -> LogT m () Source #

run :: Monad m => LogT m a -> m (a, [Msg]) Source #

format_msg :: Msg -> Text Source #

Format a msg in a nice user readable way.

serialize :: Msg -> ByteString.Lazy.ByteString Source #

Serialize a log msg. Newline separated text is nice because it's human readable and can use newlines for records. Previously I used Show, which is bulky and slow. JSON is hopefully faster, and retains the benefits of Show.

util

time_eval :: MonadIO m => m a -> m (a, Double, Double) Source #

Run an action and report the time in CPU seconds and wall clock seconds.