Safe Haskell | None |
---|---|
Language | Haskell2010 |
Provides logging for analyses. MonadLogger
is a type class for monads which
support logging. LoggerT
is a concrete monad transformer instantiating the
class.
As a logger runs, it may print out log messages on the fly (depending on the
provided LogOutput
function). It also collects logs to be inspected at the end
of the computation.
A log message must usually include an Origin
, which describes where in a
Fortran source file the message originated. This is made more convenient via
functions such as 'logWarn'', which produces an Origin
based on a piece of
Fortran syntax, along with a default source file stored in the environment.
Log messages each come with an associated LogLevel
:
LogError
is for hard errors which will often cause the computation to fail.LogWarn
is for messages about things that are likely to cause problems.LogInfo
is for general information about what the computation is doing.LogDebug
is for extra-verbose output that helps with debugging, but which will be uninteresting to most users.
Synopsis
- class Describe a where
- describe :: a -> Text
- describeBuilder :: a -> Builder
- tellDescribe :: (MonadWriter Builder m, Describe a) => a -> m ()
- describeShow :: Show a => a -> Text
- builderToStrict :: Builder -> Text
- data Builder
- data Text
- (<>) :: Semigroup a => a -> a -> a
- data Origin = Origin {}
- data ParsedOrigin = ParsedOrigin FilePath (Int, Int) (Int, Int)
- parseOrigin :: String -> Maybe ParsedOrigin
- oFile :: Lens' Origin FilePath
- oSpan :: Lens' Origin SrcSpan
- data LogLevel
- data LogMessage a = LogMessage {}
- lmOrigin :: forall a. Lens' (LogMessage a) (Maybe Origin)
- lmMsg :: forall a a. Lens (LogMessage a) (LogMessage a) a a
- data SomeMessage e w
- = MsgError (LogMessage e)
- | MsgWarn (LogMessage w)
- | MsgInfo (LogMessage Text)
- | MsgDebug (LogMessage Text)
- _MsgError :: forall e w e. Prism (SomeMessage e w) (SomeMessage e w) (LogMessage e) (LogMessage e)
- _MsgWarn :: forall e w w. Prism (SomeMessage e w) (SomeMessage e w) (LogMessage w) (LogMessage w)
- _MsgInfo :: forall e w. Prism' (SomeMessage e w) (LogMessage Text)
- _MsgDebug :: forall e w. Prism' (SomeMessage e w) (LogMessage Text)
- class Monad m => MonadLogger e w m | m -> e w where
- setDefaultSourceFile :: FilePath -> m ()
- getDefaultSourceFile :: m FilePath
- recordLogMessage :: SomeMessage e w -> m ()
- logError :: Origin -> e -> m ()
- logError' :: Spanned a => a -> e -> m ()
- logWarn :: Origin -> w -> m ()
- logWarn' :: Spanned a => a -> w -> m ()
- logInfo :: Origin -> Text -> m ()
- logInfo' :: Spanned a => a -> Text -> m ()
- logInfoNoOrigin :: Text -> m ()
- logDebug :: Origin -> Text -> m ()
- logDebug' :: Spanned a => a -> Text -> m ()
- atSpanned :: (MonadLogger e w m, Spanned a) => a -> m Origin
- atSpannedInFile :: Spanned a => FilePath -> a -> Origin
- data LoggerT e w m a
- mapLoggerT :: Functor m => (e -> e') -> (w -> w') -> LoggerT e w m a -> LoggerT e' w' m a
- data LogOutput m
- logOutputStd :: MonadIO m => Bool -> LogOutput m
- logOutputNone :: Monad m => Bool -> LogOutput m
- runLoggerT :: (Monad m, Describe e, Describe w) => FilePath -> LogOutput m -> LogLevel -> LoggerT e w m a -> m (a, [SomeMessage e w])
Conversion to text description
class Describe a where Source #
A type class for efficiently converting values to human-readable output.
Can be automatically instantiated for Show
types, but this will not be very
human-readable for a lot of types.
Nothing
describe :: a -> Text Source #
Convert the value to a human-readable output as a strict Text
value.
describeBuilder :: a -> Builder Source #
Convert the value to human-readable output in a text Builder
which can
be efficiently concatenated with other Builder
s.
default describeBuilder :: Show a => a -> Builder Source #
Instances
tellDescribe :: (MonadWriter Builder m, Describe a) => a -> m () Source #
Write a Describe
-able value directly into a writer monad.
describeShow :: Show a => a -> Text Source #
builderToStrict :: Builder -> Text Source #
A Builder
is an efficient way to build lazy Text
values.
There are several functions for constructing builders, but only one
to inspect them: to extract any data, you have to turn them into
lazy Text
values using toLazyText
.
Internally, a builder constructs a lazy Text
by filling arrays
piece by piece. As each buffer is filled, it is 'popped' off, to
become a new chunk of the resulting lazy Text
. All this is
hidden from the user of the Builder
.
A space efficient, packed, unboxed Unicode text type.
Instances
Hashable Text | |
Defined in Data.Hashable.Class | |
Ixed Text | |
Defined in Control.Lens.At | |
AsEmpty Text | |
Defined in Control.Lens.Empty | |
Reversing Text | |
Defined in Control.Lens.Internal.Iso | |
Describe Text Source # | |
ExitCodeOfReport Text Source # | |
Defined in Camfort.Analysis exitCodeOf :: Text -> Int Source # exitCodeOfSet :: [Text] -> Int Source # | |
Strict Text Text | |
Defined in Control.Lens.Iso | |
Cons Text Text Char Char | |
Snoc Text Text Char Char | |
(a ~ Char, b ~ Char) => Each Text Text a b | |
Defined in Control.Lens.Each | |
type Item Text | |
type Index Text | |
Defined in Control.Lens.At | |
type IxValue Text | |
Defined in Control.Lens.At |
(<>) :: Semigroup a => a -> a -> a infixr 6 #
An associative operation.
>>>
[1,2,3] <> [4,5,6]
[1,2,3,4,5,6]
Messages
A message origin, containing a file and a source span.
Instances
Eq Origin Source # | |
Ord Origin Source # | |
Show Origin Source # | |
Generic Origin Source # | |
NFData Origin Source # | |
Defined in Camfort.Analysis.Logger | |
Describe Origin Source # | |
type Rep Origin Source # | |
Defined in Camfort.Analysis.Logger type Rep Origin = D1 ('MetaData "Origin" "Camfort.Analysis.Logger" "camfort-1.0.1-inplace" 'False) (C1 ('MetaCons "Origin" 'PrefixI 'True) (S1 ('MetaSel ('Just "_oFile") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 FilePath) :*: S1 ('MetaSel ('Just "_oSpan") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 SrcSpan))) |
data ParsedOrigin Source #
Instances
Eq ParsedOrigin Source # | |
Defined in Camfort.Analysis.Logger (==) :: ParsedOrigin -> ParsedOrigin -> Bool # (/=) :: ParsedOrigin -> ParsedOrigin -> Bool # | |
Ord ParsedOrigin Source # | |
Defined in Camfort.Analysis.Logger compare :: ParsedOrigin -> ParsedOrigin -> Ordering # (<) :: ParsedOrigin -> ParsedOrigin -> Bool # (<=) :: ParsedOrigin -> ParsedOrigin -> Bool # (>) :: ParsedOrigin -> ParsedOrigin -> Bool # (>=) :: ParsedOrigin -> ParsedOrigin -> Bool # max :: ParsedOrigin -> ParsedOrigin -> ParsedOrigin # min :: ParsedOrigin -> ParsedOrigin -> ParsedOrigin # | |
Show ParsedOrigin Source # | |
Defined in Camfort.Analysis.Logger showsPrec :: Int -> ParsedOrigin -> ShowS # show :: ParsedOrigin -> String # showList :: [ParsedOrigin] -> ShowS # |
parseOrigin :: String -> Maybe ParsedOrigin Source #
Extract information about filename and source span from a string.
A logging level. At each logging level, only produce output at that level or lower.
LogError | At level |
LogWarn | At level |
LogInfo | At level |
LogDebug | At level |
data LogMessage a Source #
A logged message with an origin and a message value.
Instances
lmMsg :: forall a a. Lens (LogMessage a) (LogMessage a) a a Source #
data SomeMessage e w Source #
A message at one of the four LogLevel
s.
MsgError (LogMessage e) | |
MsgWarn (LogMessage w) | |
MsgInfo (LogMessage Text) | |
MsgDebug (LogMessage Text) |
Instances
_MsgError :: forall e w e. Prism (SomeMessage e w) (SomeMessage e w) (LogMessage e) (LogMessage e) Source #
_MsgWarn :: forall e w w. Prism (SomeMessage e w) (SomeMessage e w) (LogMessage w) (LogMessage w) Source #
_MsgInfo :: forall e w. Prism' (SomeMessage e w) (LogMessage Text) Source #
_MsgDebug :: forall e w. Prism' (SomeMessage e w) (LogMessage Text) Source #
Logging monad
class Monad m => MonadLogger e w m | m -> e w where Source #
MTL-style type class for monads that support logging.
Nothing
setDefaultSourceFile :: FilePath -> m () Source #
Set the default source file, i.e. the file in which messages originate by default.
default setDefaultSourceFile :: (MonadTrans t, MonadLogger e w m', m ~ t m') => FilePath -> m () Source #
getDefaultSourceFile :: m FilePath Source #
Get the current default source file, i.e. the file in which messages originate by default.
default getDefaultSourceFile :: (MonadTrans t, MonadLogger e w m', m ~ t m') => m FilePath Source #
recordLogMessage :: SomeMessage e w -> m () Source #
Record a log message. Output it based on the LogOutput
function used
and store it in the collected logs.
default recordLogMessage :: (MonadTrans t, MonadLogger e w m', m ~ t m') => SomeMessage e w -> m () Source #
logError :: Origin -> e -> m () Source #
Log an error message at the given Origin
.
logError' :: Spanned a => a -> e -> m () Source #
Log an error message. The origin is the current default source file, with the source span of the given piece of Fortran syntax.
logWarn :: Origin -> w -> m () Source #
Log a warning message at the given Origin
.
logWarn' :: Spanned a => a -> w -> m () Source #
Log a warning message. The origin is the current default source file, with the source span of the given piece of Fortran syntax.
logInfo :: Origin -> Text -> m () Source #
Log an information message at the given Origin
.
logInfo' :: Spanned a => a -> Text -> m () Source #
Log an information message. The origin is the current default source file, with the source span of the given piece of Fortran syntax.
logInfoNoOrigin :: Text -> m () Source #
Log an information message with no origin. For example, use this when printing output about the progress of an analysis which cannot be associated with a particular bit of source code.
logDebug :: Origin -> Text -> m () Source #
Log a debugging message at the given Origin
.
logDebug' :: Spanned a => a -> Text -> m () Source #
Log a debugging message. The origin is the current default source file, with the source span of the given piece of Fortran syntax.
Instances
atSpanned :: (MonadLogger e w m, Spanned a) => a -> m Origin Source #
Make an origin at the source span of a piece of Fortran syntax, in the current file.
atSpannedInFile :: Spanned a => FilePath -> a -> Origin Source #
Make an origin at the source span of a piece of Fortran syntax, in the given file.
The logging monad transformer, containing errors of type e
and warnings
of type w
.
Instances
mapLoggerT :: Functor m => (e -> e') -> (w -> w') -> LoggerT e w m a -> LoggerT e' w' m a Source #
Change the error and warning types in a logger computation. To change the
underlying monad use hoist
.
Running a logger
:: MonadIO m | |
=> Bool | If |
-> LogOutput m |
Output logs to standard output (i.e. the console).
Output no logs.
:: (Monad m, Describe e, Describe w) | |
=> FilePath | The initial default source file. This is only used for displaying message origins. |
-> LogOutput m | The logging output function. E.g. |
-> LogLevel | The log level for on-the-fly logging. Doesn't affect which logs are collected at the end. |
-> LoggerT e w m a | The logging action to run. |
-> m (a, [SomeMessage e w]) |
Run the logging monad transformer. Returns the action's result value and a list of logs which were collected as it ran.