Copyright | (c) Adam Conner-Sax 2019 |
---|---|
License | BSD-3-Clause |
Maintainer | adam_conner_sax@yahoo.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Polysemy logger effect, using pretty-printing and severity based on logging-effect. Adds a Prefixing effect so that it's easy to wrap entire functions, etc. in logging prefixes and thus to distinguish where things are being logged from more easily. Also allows filtering by severity.
Synopsis
- data LogSeverity
- data LogEntry = LogEntry {
- severity :: LogSeverity
- message :: Text
- data Logger a m r where
- data PrefixLog m r
- log :: Member (Logger a) effs => a -> Sem effs ()
- logLE :: Member (Logger LogEntry) effs => LogSeverity -> Text -> Sem effs ()
- wrapPrefix :: Member PrefixLog effs => Text -> Sem effs a -> Sem effs a
- getPrefix :: Member PrefixLog effs => Sem effs Text
- logWithPrefixToIO :: LogWithPrefixIO
- filteredLogEntriesToIO :: MonadIO (Sem r) => (LogSeverity -> Bool) -> Sem (Logger LogEntry ': (PrefixLog ': r)) x -> Sem r x
- logAll :: LogSeverity -> Bool
- logDebug :: Int -> LogSeverity -> Bool
- logDiagnostic :: LogSeverity -> Bool
- nonDiagnostic :: LogSeverity -> Bool
- type PrefixedLogEffects a = [PrefixLog, Logger a]
- type PrefixedLogEffectsLE = PrefixedLogEffects LogEntry
- type LogWithPrefixes a effs = Members (PrefixedLogEffects a) effs
- type LogWithPrefixesLE effs = LogWithPrefixes LogEntry effs
- type LogWithPrefixIO = Text -> LogEntry -> IO ()
Logging Types
data LogSeverity Source #
Severity/importance of message.
Debug Int | Most detailed levels of logging. Int argument can be used adding fine distinctions between debug levels. |
Diagnostic | Minimal details about effects and what is being called. |
Info | Informational messages about progress of compuation or document knitting. |
Warning | Messages intended to alert the user to an issue in the computation or document production. |
Error | Likely unrecoverable issue in computation or document production. |
Instances
A basic log entry with a severity and a (Text
) message
LogEntry | |
|
Effects
Actions
log :: Member (Logger a) effs => a -> Sem effs () Source #
Add one log entry of arbitrary type. If you want to log with another type besides @LogEntry.
logLE :: Member (Logger LogEntry) effs => LogSeverity -> Text -> Sem effs () Source #
Add one log-entry of the LogEntry
type.
wrapPrefix :: Member PrefixLog effs => Text -> Sem effs a -> Sem effs a Source #
Add a prefix for the block of code.
logWithPrefixToIO :: LogWithPrefixIO Source #
This function can be used to log directly to IO, bypassing the effect. It's here to allow logging from within functions that must be run under more limited stacks and then embedded.
Interpreters
filteredLogEntriesToIO :: MonadIO (Sem r) => (LogSeverity -> Bool) -> Sem (Logger LogEntry ': (PrefixLog ': r)) x -> Sem r x Source #
Subsets for filtering
logAll :: LogSeverity -> Bool Source #
log everything.
logDebug :: Int -> LogSeverity -> Bool Source #
log debug messages with level lower than or equal to the given Int
.
logDiagnostic :: LogSeverity -> Bool Source #
log all but Debug
messages.
nonDiagnostic :: LogSeverity -> Bool Source #
log everything above Diagnostic
.
Type Synonyms and Constraints for convenience
type PrefixedLogEffects a = [PrefixLog, Logger a] Source #
List of Logger effects for a prefixed log of type a
type PrefixedLogEffectsLE = PrefixedLogEffects LogEntry Source #
List of Logger effects for a prefixed log of type LogEntry
type LogWithPrefixes a effs = Members (PrefixedLogEffects a) effs Source #
Constraint helper for logging with prefixes
type LogWithPrefixesLE effs = LogWithPrefixes LogEntry effs Source #
Constraint helper for LogEntry
type with prefixes