Safe Haskell | Safe-Inferred |
---|
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
- configure :: (State -> State) -> IO.IO ()
- rotate :: IO.FilePath -> IO.IO IO.Handle
- rotate_config :: Int -> Int -> IO.FilePath -> IO.IO IO.Handle
- with_stdio_lock :: IO.IO () -> IO.IO ()
- data Msg = Msg {
- msg_date :: !UTCTime
- msg_caller :: !CallStack.Caller
- msg_priority :: !Priority
- msg_stack :: !(Maybe Stack.Stack)
- msg_text :: !Text
- msg_data :: !(Map Text Data)
- msg_string :: Msg -> String
- with_int :: Text -> Int -> Msg -> Msg
- with_text :: Text -> Text -> Msg -> Msg
- with_dyn :: Typeable a => Text -> a -> Msg -> Msg
- lookup_int :: Text -> Msg -> Maybe Int
- lookup_text :: Text -> Msg -> Maybe Text
- lookup_dyn :: Typeable a => Text -> Msg -> Maybe a
- data Priority
- data State = State {
- state_write_msg :: Msg -> IO.IO ()
- state_priority :: Priority
- write_json :: IO.Handle -> Msg -> IO.IO ()
- write_formatted :: IO.Handle -> Msg -> IO.IO ()
- msg :: CallStack.Stack => Priority -> Maybe Stack.Stack -> Text -> Msg
- msg_call_stack :: CallStack -> Priority -> Maybe Stack.Stack -> Text -> Msg
- log :: (CallStack.Stack, LogMonad m) => Priority -> Text -> m ()
- timer :: (CallStack.Stack, LogMonad m) => Text -> m ()
- debug :: (CallStack.Stack, LogMonad m) => Text -> m ()
- notice :: (CallStack.Stack, LogMonad m) => Text -> m ()
- warn :: (CallStack.Stack, LogMonad m) => Text -> m ()
- error :: (CallStack.Stack, LogMonad m) => Text -> m ()
- debug_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m ()
- notice_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m ()
- warn_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m ()
- error_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m ()
- add_prefix :: Text -> Msg -> Msg
- class Monad m => LogMonad m where
- data LogT m a
- run :: Monad m => LogT m a -> m (a, [Msg])
- type LogId a = LogT Identity a
- run_id :: LogId a -> (a, [Msg])
- format_msg :: Msg -> Text
- serialize :: Msg -> ByteString.Lazy.ByteString
- deserialize :: ByteString.Lazy.ByteString -> Either String Msg
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
Msg | |
|
msg_string :: Msg -> String Source #
data
other types
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
Logging state. Don't log if a handle is Nothing.
State | |
|
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.
debug_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m () Source #
notice_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m () Source #
warn_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m () Source #
error_stack :: (CallStack.Stack, LogMonad m) => Stack.Stack -> Text -> m () Source #
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.
Instances
LogMonad IO.IO Source # | |
LogMonad Deriver Source # | |
Monad m => LogMonad (CmdT m) Source # | Give CmdT unlifted access to all the logging functions. |
Monad m => LogMonad (UiLogT m) Source # | |
Monad m => LogMonad (LogT m) Source # | |
(Error e, LogMonad m) => LogMonad (Error.ErrorT e m) Source # | |
LogMonad m => LogMonad (Except.ExceptT e m) Source # | |
LogMonad m => LogMonad (Reader.ReaderT r m) Source # | |
LogMonad m => LogMonad (State.Lazy.StateT s m) Source # | |
LogMonad m => LogMonad (State.Strict.StateT s m) Source # | |
(Monoid w, LogMonad m) => LogMonad (Writer.WriterT w m) Source # | |
Instances
MonadTrans LogT Source # | |
MonadError e m => MonadError e (LogT m) Source # | |
Defined in Util.Log throwError :: e -> LogT m a # catchError :: LogT m a -> (e -> LogT m a) -> LogT m a # | |
MonadReader r m => MonadReader r (LogT m) Source # | |
MonadState st m => MonadState st (LogT m) Source # | |
MonadIO m => MonadIO (LogT m) Source # | |
Monad m => Applicative (LogT m) Source # | |
Functor m => Functor (LogT m) Source # | |
Monad m => Monad (LogT m) Source # | |
Monad m => LogMonad (UiLogT m) Source # | |
Monad m => LogMonad (LogT m) 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.