Copyright | (c) 2020-2021 Sam May |
---|---|
License | GPL-3.0-or-later |
Maintainer | ag@eitilt.life |
Stability | stable |
Portability | non-portable (requires libcdio) |
Safe Haskell | None |
Language | Haskell2010 |
Sound.Libcdio.Logging
Description
The underlying library is rather loud in its error and warning messages, potentially emitting a lot of impure terminal clutter even on some otherwise-pure functions. Very helpfully, it also provides a mechanism for integrating the logs with whatever framework is in place for the larger project; that mechanism can be leveraged to cache the logs in memory until specifically asked for, at which point they can be packaged into Haskell types. Some of the immediacy—and therefore user ability to match note to source—is unfortunately lost, but the apparent purity is worth it.
Synopsis
- class LibcdioLogger m where
- data LogEntry = LogEntry {
- logLevel :: LogLevel
- logMessage :: String
- data LogLevel
- isolateLogs :: (Monad m, LibcdioLogger m) => m a -> m a
- setupLogger :: IO ()
Types
class LibcdioLogger m where #
An environment which integrates the libcdio logging interface; will almost
always be a Monad
, but as an Applicative
might technically be able to
implement these, that constraint isn't enforced.
Methods
Arguments
:: m LogLevel | Check the current minimum severity which will be recorded in the logs. |
Arguments
:: LogLevel | |
-> m () | Set the minimum severity required for a message to be recorded in the logs. |
Arguments
:: m [LogEntry] | Retrieve all messages currently in the log for further processing.
Note that this retains the contents of the log for future calls; to
remove them, a separate call to
|
Arguments
:: m () | Empty all messages currently in the log. There is no way to
selectively remove only some messages; if that is desired, call
|
Arguments
:: LogEntry | |
-> m () | Append a message to the logs. |
Instances
LibcdioLogger IO # | The required initialization function |
LibcdioLogger Cdio # | |
LibcdioLogger CdText # | |
An unstructured message emitted from the library to let the user know what's going on behind the scenes.
Constructors
LogEntry | |
Fields
|
Instances
Eq LogEntry # | |
Read LogEntry # | |
Show LogEntry # | |
Storable LogEntry # | |
Defined in Foreign.Libcdio.Logging |
How much detail should be recorded in the logs.
Instances
Bounded LogLevel # | |
Enum LogLevel # | |
Defined in Foreign.Libcdio.Types.Enums | |
Eq LogLevel # | |
Ord LogLevel # | |
Defined in Foreign.Libcdio.Types.Enums | |
Read LogLevel # | |
Show LogLevel # | |
Utility
isolateLogs :: (Monad m, LibcdioLogger m) => m a -> m a #
Keep the monad pure by preventing it from reading stale logs, but since the outer IO might still care about them, restore the entire stack after.
Note that the logs are not thread-safe; messages from other threads may be interwoven with those from the passed computation even after this function is called.
setupLogger :: IO () #
Initialize the log-management backend to use the mechanisms provided by this library instead of just printing to standard output. While this will usually be taken care of automatically, it may still be necessary to call this explicitly if messages are being recorded before any disc session is opened.