Karya, built on 2023-08-29T07:47:28 (patch 7a412d5d6ba4968ca4155ef276a062ccdeb9109a)
Safe HaskellSafe-Inferred

Util.Log

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

setup

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

Configure the logging system by modifying its internal state.

rotate_config :: Int -> Int -> IO.FilePath -> IO.IO IO.Handle Source #

Get a file handle for writing log msgs, first rotating logs if necessary.

with_stdio_lock :: IO.IO () -> IO.IO () Source #

Reuse the log lock, presumably to write to stdout or stderr. It doesn't really belong here, but stdout and stderr are already global, so reusing a lock for them doesn't seem like a big deal.

msgs

data Msg Source #

Constructors

Msg 

Fields

Instances

Instances details
Read.Read Msg Source # 
Instance details

Defined in Util.Log

Show Msg Source # 
Instance details

Defined in Util.Log

Methods

showsPrec :: Int -> Msg -> ShowS #

show :: Msg -> String #

showList :: [Msg] -> ShowS #

DeepSeq.NFData Msg Source # 
Instance details

Defined in Util.Log

Methods

rnf :: Msg -> () #

Eq Msg Source # 
Instance details

Defined in Util.Log

Methods

(==) :: Msg -> Msg -> Bool #

(/=) :: Msg -> Msg -> Bool #

Pretty Msg Source # 
Instance details

Defined in Util.Log

Serialize.Serialize Msg Source # 
Instance details

Defined in Util.Log

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

Instances details
Bounded Priority Source # 
Instance details

Defined in Util.Log

Enum Priority Source # 
Instance details

Defined in Util.Log

Generics.Generic Priority Source # 
Instance details

Defined in Util.Log

Associated Types

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

Read.Read Priority Source # 
Instance details

Defined in Util.Log

Show Priority Source # 
Instance details

Defined in Util.Log

Eq Priority Source # 
Instance details

Defined in Util.Log

Ord Priority Source # 
Instance details

Defined in Util.Log

Serialize.Serialize Priority Source # 
Instance details

Defined in Util.Log

Aeson.Types.FromJSON Priority Source # 
Instance details

Defined in Util.Log

Aeson.Types.ToJSON Priority Source # 
Instance details

Defined in Util.Log

type Generics.Rep Priority Source # 
Instance details

Defined in Util.Log

data State Source #

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

Constructors

State 

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

Write logs as JSON to the given handle.

write_formatted :: IO.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 a msg with the given string.

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.

Methods

write :: Msg -> m () Source #

Instances

Instances details
LogMonad IO.IO Source # 
Instance details

Defined in Util.Log

Methods

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

LogMonad Deriver Source # 
Instance details

Defined in Derive.Deriver.Monad

Methods

write :: Msg -> Deriver () Source #

Monad m => LogMonad (CmdT m) Source #

Give CmdT unlifted access to all the logging functions.

Instance details

Defined in Cmd.Cmd

Methods

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

Monad m => LogMonad (UiLogT m) Source # 
Instance details

Defined in Ui.UiLog

Methods

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

Monad m => LogMonad (LogT m) Source # 
Instance details

Defined in Util.Log

Methods

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

(Error e, LogMonad m) => LogMonad (Error.ErrorT e m) Source # 
Instance details

Defined in Util.Log

Methods

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

LogMonad m => LogMonad (Except.ExceptT e m) Source # 
Instance details

Defined in Util.Log

Methods

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

LogMonad m => LogMonad (Reader.ReaderT r m) Source # 
Instance details

Defined in Util.Log

Methods

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

LogMonad m => LogMonad (State.Lazy.StateT s m) Source # 
Instance details

Defined in Util.Log

Methods

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

LogMonad m => LogMonad (State.Strict.StateT s m) Source # 
Instance details

Defined in Util.Log

Methods

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

(Monoid w, LogMonad m) => LogMonad (Writer.WriterT w m) Source # 
Instance details

Defined in Util.Log

Methods

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

data LogT m a Source #

Instances

Instances details
MonadTrans LogT Source # 
Instance details

Defined in Util.Log

Methods

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

MonadError e m => MonadError e (LogT m) Source # 
Instance details

Defined in Util.Log

Methods

throwError :: e -> LogT m a #

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

MonadReader r m => MonadReader r (LogT m) Source # 
Instance details

Defined in Util.Log

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) Source # 
Instance details

Defined in Util.Log

Methods

get :: LogT m st #

put :: st -> LogT m () #

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

MonadIO m => MonadIO (LogT m) Source # 
Instance details

Defined in Util.Log

Methods

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

Monad m => Applicative (LogT m) Source # 
Instance details

Defined in Util.Log

Methods

pure :: a -> LogT m a #

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

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

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

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

Functor m => Functor (LogT m) Source # 
Instance details

Defined in Util.Log

Methods

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

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

Monad m => Monad (LogT m) Source # 
Instance details

Defined in Util.Log

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 #

Monad m => LogMonad (UiLogT m) Source # 
Instance details

Defined in Ui.UiLog

Methods

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

Monad m => LogMonad (LogT m) Source # 
Instance details

Defined in Util.Log

Methods

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

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

run_id :: LogId a -> (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.