packages feed

co-log-simple 1.0.0 → 1.1.0

raw patch · 7 files changed

+135/−67 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Colog.Simple: type Target (m :: Type -> Type) = LogAction m Text
+ Colog.Simple.Message: (%) :: Formatter -> Formatter -> Formatter
+ Colog.Simple.Message: (%+) :: Formatter -> Formatter -> Formatter
+ Colog.Simple.Message: msg :: Message -> Text
+ Colog.Simple.Message: msgc :: Message -> Text
+ Colog.Simple.Message: sev :: Message -> Text
+ Colog.Simple.Message: sevc :: Message -> Text
+ Colog.Simple.Message: stack :: Message -> Text
+ Colog.Simple.Message: stackc :: Message -> Text
- Colog.Simple: logger :: forall (m :: Type -> Type). MonadIO m => Formatter -> Target m -> Severity -> LogAction m Message
+ Colog.Simple: logger :: forall (m :: Type -> Type). MonadIO m => (Message -> Text) -> LogAction m Text -> Severity -> LogAction m Message
- Colog.Simple.Message: basicFmt :: Formatter
+ Colog.Simple.Message: basicFmt :: Message -> Text
- Colog.Simple.Message: colorFmt :: Formatter
+ Colog.Simple.Message: colorFmt :: Message -> Text
- Colog.Simple.Message: colorSevFmt :: Formatter
+ Colog.Simple.Message: colorSevFmt :: Message -> Text
- Colog.Simple.Message: colorSevStackFmt :: Formatter
+ Colog.Simple.Message: colorSevStackFmt :: Message -> Text

Files

CHANGELOG.md view
@@ -1,3 +1,10 @@+1.1.0 (2025-08-11)++  * Exciting new formatter design, deprecated older formatters+  * Fixed various documentation issues+  * Added cabal categories++ 1.0.0 (2025-08-07)    * Initial release
README.md view
@@ -19,8 +19,9 @@    Warning. 2. I've often wanted different colors for severities which is much easier with    co-log than hslogger-3. This library also includes a variety of formatters that should prove useful-   for various types of projects+3. This library also includes some functions for formatting different parts of+   a log message like the severity or the message itself. These are to be+   composed together with the (%) and (%+) operators.  For usage examples, see `src/examples/Main.hs` and the API docs for `Colog.Simple`
co-log-simple.cabal view
@@ -1,7 +1,7 @@ cabal-version: 2.2  name: co-log-simple-version: 1.0.0+version: 1.1.0 synopsis: Simple enhancements for logging with co-log description: A library built upon co-log that makes constructing and using   `LogAction`s simpler with some predefined formatters and a slightly enhanced@@ -9,7 +9,7 @@ author: Dino Morelli maintainer: dino@ui3.info copyright: 2025 Dino Morelli-category: Unclassified+category: Logging license: ISC license-file: LICENSE build-type: Simple
src/examples/Main.hs view
@@ -4,26 +4,35 @@   where  import Colog.Monad (usingLoggerT)-import Colog.Simple (LogAction, Message, Severity (Debug, Notice), basicFmt,-  colorFmt, colorSevFmt, logger, logInfo, logNotice, logTest, logTextStderr,-  logTextStdout)+import Colog.Simple (LogAction, Message, Severity (Debug, Notice), (%), (%+),+  logger, logInfo, logNotice, logTest, logTextStderr, logTextStdout, msg, msgc,+  sevc, stack)   main :: IO () main = do-  usingLoggerT (logger colorSevFmt logTextStdout Debug) $ do-    logNotice "Examples of all Severity values\n"+  putStrLn "------------------------------------------"+  usingLoggerT (logger (sevc % msg) logTextStdout Debug) $ do+    logNotice "Examples of all Severity values"     logTest -  usingLoggerT (logger colorFmt logTextStderr Notice) $ do-    logNotice "\nExample of a different formatter with Severity set to Notice"-    logNotice "These are going to stderr\n"+  putStrLn "------------------------------------------"+  usingLoggerT (logger msgc logTextStderr Notice) $ do+    logNotice "Example of a different formatter with Severity set to Notice"+    logNotice "These are going to stderr"     logTest -  usingLoggerT (logger basicFmt logTextStdout Debug) $ do-    logNotice "\nNo colors is possible of course\n"+  putStrLn "------------------------------------------"+  usingLoggerT (logger msg logTextStdout Debug) $ do+    logNotice "No colors is possible of course"     logTest +  putStrLn "------------------------------------------"+  usingLoggerT (logger (sevc % msg %+ stack) logTextStdout Debug) $ do+    logNotice "With call stack info"+    logTest++  putStrLn "------------------------------------------"   -- Example of completely turning off logging   usingLoggerT (mempty :: LogAction IO Message) $     logInfo "This message should never be shown"
src/lib/Colog/Simple.hs view
@@ -6,22 +6,19 @@ import Colog.Monad (usingLoggerT) import Colog.Simple (Severity (..), colorSevFmt, logger, logNotice, logTextStdout) -usingLoggerT (logger colorSevFmt logTextStdout Debug) $ logNotice "Take note of this!"+usingLoggerT (logger (sevc % msg) logTextStdout Debug) $ logNotice "Take note of this!" @  The 'LogAction' produced by 'logger' above is what you would put in your-'ReaderT' environment as well. See co-log documentation for more info on+ReaderT environment as well. See co-log documentation for more info on integrating with transformers.  <https://github.com/co-log/co-log/blob/main/tutorials/custom/Custom.md> -} module Colog.Simple   (-    -- * Types-    Target-     -- * Constructing LogAction loggers-  , logger+    logger      -- * Utility functions   , logTest@@ -48,17 +45,13 @@ import Colog.Simple.Severity  --- | A synonym for ordinary co-log 'LogAction' types parameterized with 'Text'-type Target m = LogAction m Text-- -- | Construct a logging action logger :: MonadIO m-  => Formatter  -- ^ Format function-  -> Target m   -- ^ Where log message output will go-  -> Severity   -- ^ The severity level to filter at or above+  => (Message -> Text)  -- ^ Format function+  -> LogAction m Text   -- ^ Where log message output will go+  -> Severity           -- ^ The severity level to filter at or above   -> LogAction m Message-logger formatter target sev = setSeverity sev . formatWith formatter $ target+logger fmtFs targetAction sev' = setSeverity sev' . formatWith fmtFs $ targetAction   -- | Test function to generate messages with every severity in this library
src/lib/Colog/Simple/Message.hs view
@@ -12,8 +12,11 @@     -- * Functions for logging with a specific severity   , logDebug, logInfo, logNotice, logWarning, logError +    -- * Functions for composing formatters+  , (%), (%+)+     -- * Message formatting functions-  , basicFmt, colorFmt, colorSevFmt, colorSevStackFmt+  , sev, sevc, stack, stackc, msg, msgc      -- * Other functions   , colorize@@ -24,6 +27,9 @@      -- * Re-exported from co-log   , Msg (..)++    -- * Deprecated message formatting functions+  , basicFmt, colorFmt, colorSevFmt, colorSevStackFmt   )   where @@ -39,30 +45,11 @@ import Colog.Simple.Severity (Severity (..))  --- | The type of a 'Msg' parameterized with the custom severity type in this+-- | The type of a Msg parameterized with the custom severity type in this --   library type Message = Msg Severity --- | The type of functions which format 'Message's into 'Text'-type Formatter = Message -> Text ---- | Wrap some 'Text' in the ANSI codes to color it in a terminal-colorize :: Color -> Text -> Text-colorize c txt =-  pack (setSGRCode [SetColor Foreground Vivid c])-  <> txt-  <> pack (setSGRCode [Reset])---showSeverity :: Severity -> Text-showSeverity Debug    = colorize Green  "[Debug]   "-showSeverity Info     = colorize Blue   "[Info]    "-showSeverity Notice   = colorize White  "[Notice]  "-showSeverity Warning  = colorize Yellow "[Warning] "-showSeverity Error    = colorize Red    "[Error]   "-- -- | Log a message with 'Debug' severity logDebug :: WithLog env Message m => Text -> m () logDebug = withFrozenCallStack (log Debug)@@ -88,31 +75,102 @@ logError = withFrozenCallStack (log Error)  --- | No color formatting. Just the message, no severity label-basicFmt :: Formatter-basicFmt (Msg _ _ txt) = txt+-- | Wrap some 'Text' in the ANSI codes to color it in a terminal+colorize :: Color -> Text -> Text+colorize c txt =+  pack (setSGRCode [SetColor Foreground Vivid c])+  <> txt+  <> pack (setSGRCode [Reset])  --- | Format with no severity labels but message colors for each severity-colorFmt :: Formatter-colorFmt (Msg Debug _ txt) = colorize Green txt-colorFmt (Msg Info _ txt) = colorize Blue txt-colorFmt (Msg Notice _ txt) = colorize White txt-colorFmt (Msg Warning _ txt) = colorize Yellow txt-colorFmt (Msg Error _ txt) = colorize Red txt+showSeverity :: Severity -> Text+showSeverity Debug    = "[Debug]   "+showSeverity Info     = "[Info]    "+showSeverity Notice   = "[Notice]  "+showSeverity Warning  = "[Warning] "+showSeverity Error    = "[Error]   "  --- | Format with colored severity labels and no color for the message-colorSevFmt :: Formatter-colorSevFmt (Msg sev _ txt) = showSeverity sev <> txt+colorForSeverity :: Severity -> Color+colorForSeverity Debug = Green+colorForSeverity Info = Blue+colorForSeverity Notice = White+colorForSeverity Warning = Yellow+colorForSeverity Error = Red  --- | Format with colored severity labels, call stack info, and no color for the---   message-colorSevStackFmt :: Formatter-colorSevStackFmt (Msg sev cs txt) = showSeverity sev <> showSourceLoc cs <> txt+-- | The type of functions which format 'Message's into 'Text'+type Formatter = Message -> Text  +-- | Apply two formatters to a 'Message' and combine the resulting 'Text's.+--   With apologies to the formatting library for stealing their operator!+(%) :: Formatter -> Formatter -> Formatter+f % g = \msg' -> f msg' <> g msg'+++-- | Apply two formatters to a 'Message' and combine the resulting 'Text'+--   output with a space between.+--   Again, with apologies to the formatting library for stealing their operator!+(%+) :: Formatter -> Formatter -> Formatter+f %+ g = f % const " " % g+++-- | Format 'Severity'+sev :: Message -> Text+sev (Msg s _ _) = showSeverity s+++-- | Format 'Severity' with color based on the value+sevc :: Message -> Text+sevc (Msg s _ _) = colorize (colorForSeverity s) $ showSeverity s+++-- | Format call stack info+stack :: Message -> Text+stack (Msg _ cs _) = showSourceLoc cs+++-- | Format call stack info with color based on the 'Severity'+stackc :: Message -> Text+stackc (Msg s cs _) = colorize (colorForSeverity s) $ showSourceLoc cs+++-- | Format the log message+msg :: Message -> Text+msg (Msg _ _ m) = m+++-- | Format the log message with color based on the 'Severity'+msgc :: Message -> Text+msgc (Msg s _ m) = colorize (colorForSeverity s) m++ -- | Filter log messages for greater than or equal to the given 'Severity' setSeverity :: Applicative m => Severity -> LogAction m Message -> LogAction m Message setSeverity targetSev = cfilter (\(Msg msgSev _ _) -> msgSev >= targetSev)+++-- | No color formatting. Just the message, no severity label+basicFmt :: Message -> Text+basicFmt = msg+{-# DEPRECATED basicFmt "Use msg instead" #-}+++-- | Format with no severity labels but message colors for each severity+colorFmt :: Message -> Text+colorFmt = msgc+{-# DEPRECATED colorFmt "Use msgc instead" #-}+++-- | Format with colored severity labels and no color for the message+colorSevFmt :: Message -> Text+colorSevFmt = sevc % msg+{-# DEPRECATED colorSevFmt "Use (sevc % msgc) instead" #-}+++-- | Format with colored severity labels, call stack info, and no color for the+--   message+colorSevStackFmt :: Message -> Text+colorSevStackFmt = sevc % stack %+ msg+{-# DEPRECATED colorSevStackFmt "Use (sevc % stack %+ msgc) instead" #-}
src/lib/Colog/Simple/Severity.hs view
@@ -6,7 +6,7 @@ that can be filtered by a verbosity setting. This is distinct from debugging or logging warnings/errors. -The code in this module is parameterized with this Severity type, not the+The code in this library is parameterized with this Severity type, not the "stock" one in co-log/co-log-core. -} module Colog.Simple.Severity