cli-extras-0.2.0.0: Miscellaneous utilities for building and working with command line interfaces
Safe HaskellNone
LanguageHaskell2010

Cli.Extras.Logging

Description

Provides a logging handler that facilitates safe ouputting to terminal using MVar based locking. | Spinner.hs and Process.hs work on this guarantee.

Synopsis

Documentation

class AsUnstructuredError e where Source #

Indicates unstructured errors form one variant (or conceptual projection) of the error type.

Shouldn't really use this, but who has time to clean up that much!

Instances

Instances details
AsUnstructuredError Text Source # 
Instance details

Defined in Cli.Extras.Logging

newCliConfig Source #

Arguments

:: Severity

The initial log level. Messages below this severity will not be logged, unless the log level is subsequently altered using setLogLevel.

-> Bool

Should ANSI terminal formatting be disabled?

-> Bool

Should spinners be disabled?

-> (e -> (Text, ExitCode))

How to display errors, and compute the ExitCode corresponding to each error.

-> IO (CliConfig e) 

Create a new CliConfig, initialized with the provided values.

runCli :: MonadIO m => CliConfig e -> CliT e m a -> m a Source #

putLog :: CliLog m => Severity -> Text -> m () Source #

Log a message to the console.

The message is guaranteed to be logged uninterrupted, even if there are ongoing spinners.

putLogRaw :: CliLog m => Severity -> Text -> m () Source #

Like putLog but without the implicit newline added.

failWith :: (CliThrow e m, AsUnstructuredError e) => Text -> m a Source #

Like `putLog Alert` but also abrupts the program.

errorToWarning :: (HasCliConfig e m, CliLog m) => e -> m () Source #

Log an error as though it were a warning, in a non-fatal way.

withExitFailMessage :: (CliLog m, MonadCatch m) => Text -> m a -> m a Source #

Intercept ExitFailure exceptions and log the given alert before exiting.

This is useful when you want to provide contextual information to a deeper failure.

writeLog Source #

Arguments

:: MonadIO m 
=> Bool

Should a new line be printed after the message?

-> Bool

Should ANSI terminal formatting be used when printing the message?

-> WithSeverity Text

The message to print.

-> m () 

Log a message to standard output.

allowUserToMakeLoggingVerbose Source #

Arguments

:: (MonadIO m, MonadMask m, CliLog m, HasCliConfig e m) 
=> String

The key(s) which should be read to indicate a shift in verbosity.

-> Text

A description of the key that must be pressed.

-> m () 

Allows the user to immediately switch to verbose logging when a particular sequence of characters is read from the terminal.

Call this function in a thread, and kill it to turn off keystroke monitoring.

getChars :: IO String Source #

Like getChar but also retrieves the subsequently pressed keys.

Allowing, for example, the ↑ key, which consists of the three characters ['ESC','[',A] to be distinguished from an actual ESC character input.

fork :: (HasCliConfig e m, MonadIO m) => CliT e IO () -> m ThreadId Source #

Fork a computation in CliT, sharing the configuration with the child thread.