| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Shrun.Logging.Formatting
Description
Provides Log formatting functionality.
Synopsis
- formatConsoleLog :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m) => KeyHideSwitch -> ConsoleLoggingEnv -> Log -> m ConsoleLog
- formatFileLog :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m, MonadTime m) => KeyHideSwitch -> FileLoggingEnv -> Log -> m FileLog
- formatConsoleMultiLineLogs :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m) => KeyHideSwitch -> ConsoleLoggingEnv -> NonEmpty Log -> m ConsoleLog
- formatFileMultiLineLogs :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m, MonadTime m) => KeyHideSwitch -> FileLoggingEnv -> NonEmpty Log -> m FileLog
- logToColor :: Log -> Color
- logToPrefix :: Log -> Text
- levelToColor :: LogLevel -> Color
- levelToPrefix :: LogLevel -> Text
- formatCommand :: KeyHideSwitch -> Maybe (Truncation 'TruncCommandName) -> CommandP1 -> UnlinedText
- concatWithLineTrunc :: Maybe (Truncation 'TruncLine, Maybe Int) -> Text -> Text -> Text
- displayCmd :: CommandP1 -> KeyHideSwitch -> UnlinedText
- stripChars :: forall (t :: StripControlType). LogMessage -> StripControl t -> LogMessage
- brackets :: Text -> Text
- formatCommandText :: Text -> UnlinedText
High-level
formatConsoleLog :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m) => KeyHideSwitch -> ConsoleLoggingEnv -> Log -> m ConsoleLog Source #
Formats a log to be printed to the console.
formatFileLog :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m, MonadTime m) => KeyHideSwitch -> FileLoggingEnv -> Log -> m FileLog Source #
Final logs
formatConsoleMultiLineLogs :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m) => KeyHideSwitch -> ConsoleLoggingEnv -> NonEmpty Log -> m ConsoleLog Source #
Like formatConsoleLog, but for multiple logs. Concatenates all
together with a newline.
formatFileMultiLineLogs :: (HasCallStack, HasCommands env, MonadAtomic m, MonadReader env m, MonadTime m) => KeyHideSwitch -> FileLoggingEnv -> NonEmpty Log -> m FileLog Source #
Like formatFileLog, but for multiple logs. Concatenates all
together.
Low-level
Utils
formatCommand :: KeyHideSwitch -> Maybe (Truncation 'TruncCommandName) -> CommandP1 -> UnlinedText Source #
concatWithLineTrunc :: Maybe (Truncation 'TruncLine, Maybe Int) -> Text -> Text -> Text Source #
Combines a prefix p and msg m with possible line truncation. If no
truncation is given then concatWithLineTrunc is equivalent to p <> m.
If we are given some line truncation l, then we derive
k := l - prefix_len -- k is clamped to zero
and return
prefix <> t'
where t' is t truncated to k chars. Notice the prefix is always
included untarnished.
displayCmd :: CommandP1 -> KeyHideSwitch -> UnlinedText Source #
Pretty show for Command. If the command has a key, and KeyHideSwitch is
KeyHideOff then we return the key. Otherwise we return the command itself.
>>>import Shrun.Command.Types (CommandP (MkCommandP), unsafeFromInt)>>>import Shrun.Configuration.Data.CommonLogging.KeyHideSwitch (KeyHideSwitch (MkKeyHideSwitch))
>>>let idx = unsafeFromInt 1>>>let mkCmd = MkCommandP idx>>>let fmt k cmd kh = view #unUnlinedText $ displayCmd (mkCmd k cmd) kh
>>>fmt Nothing "some long command" (MkKeyHideSwitch true)"some long command"
>>>fmt Nothing "some long command" (MkKeyHideSwitch false)"some long command"
>>>fmt (Just "long") "some long command" (MkKeyHideSwitch true)"some long command"
>>>fmt (Just "long") "some long command" (MkKeyHideSwitch false)"long"
stripChars :: forall (t :: StripControlType). LogMessage -> StripControl t -> LogMessage Source #
Applies the given StripControl to the Text.
StripControlAll: All control chars.StripControlSmart: Ansi control chars.StripControlNone: Nothing.
brackets :: Text -> Text Source #
Surrounds text with brackets, appending a space if the boolean is True.
Examples
>>>brackets "text""[text]"
formatCommandText :: Text -> UnlinedText Source #
Replace newlines with whitespace before stripping, so any strings separated by newlines do not get smashed together.