shrun
Safe HaskellNone
LanguageGHC2021

Shrun.Logging

Description

Provides logging functionality. This is a high-level picture of how logging works:

  1. Shrun.IO sends logs per command based on the environment (i.e. is file logging on and/or do we log commands). If any logs are produced, they are formatted and sent directly to a queue.
  2. Shrun also produces logs. These are "higher-level" e.g. success/failure status of a given command, fatal errors, etc. Shrun uses the functions here (e.g. putRegionLog) that handles deciding if a given log should be written to eitherboth of the consolefile log queues.
  3. Shrun has two threads -- one for each queue -- that poll their respective queues and writes logs as they are found. These do no environment checking; any logs that make it to the queue are eventually written.
Synopsis

Writing logs

putRegionLog Source #

Arguments

:: forall m env. (HasCallStack, HasCommands env, HasLogging env m, MonadAtomic m, MonadReader env m, MonadTime m) 
=> Region m

Region.

-> Log

Log to send.

-> m () 

Unconditionally writes a log to the console queue. Conditionally writes the log to the file queue, if Logging's fileLogging is present.

putRegionMultiLineLog Source #

Arguments

:: forall m env. (HasCallStack, HasCommands env, HasLogging env m, MonadAtomic m, MonadReader env m, MonadTime m) 
=> Region m

Region.

-> NonEmpty Log

Log to send.

-> m () 

Unconditionally writes a log to the console queue. Conditionally writes the log to the file queue, if Logging's fileLogging is present.

regionLogToConsoleQueue Source #

Arguments

:: (HasCallStack, MonadAtomic m) 
=> TBQueue (LogRegion (Region m))

Region.

-> LogRegion (Region m)

Log to send.

-> m () 

Writes the log to the console queue.

logToFileQueue Source #

Arguments

:: (HasCallStack, MonadAtomic m) 
=> FileLoggingEnv

FileLogging config.

-> FileLog

Log to send.

-> m () 

Writes the log to the file queue.

Direct logs

putRegionLogDirect :: (HasCallStack, HasCommands env, HasLogging env m, MonadAtomic m, MonadHandleWriter m, MonadReader env m, MonadRegionLogger m, MonadTime m) => Log -> m () Source #

Like putRegionLog, except this logs directly to the console / file, rather than placing the log in a queue. This is for when log queues are shutdown (e.g. terminated). This should only be called from a single thread.

putRegionMultiLineLogDirect :: (HasCallStack, HasCommands env, HasLogging env m, MonadAtomic m, MonadHandleWriter m, MonadReader env m, MonadRegionLogger m, MonadTime m) => NonEmpty Log -> m () Source #

Like putRegionMultiLineLog, except this logs directly to the console / file, rather than placing the log in a queue. This is for when log queues are shutdown (e.g. terminated). This should only be called from a single thread.

Debug

Misc

mkUnfinishedCmdLogs :: forall m env. (HasCallStack, HasCommands env, HasCommonLogging env, MonadAtomic m, MonadReader env m) => m (Maybe (NonEmpty Log), Maybe (NonEmpty Log)) Source #

Returns formatted log for unfinished commands (waiting and running). Does not actually cancel any commands itself; that is handled by async (race_).

Returns "multi logs", as each command is rendered on a newline. Hence this should be used with the multi-line log options.

logDebug :: (HasCommonLogging env, MonadReader env m) => (LogLevel -> m ()) -> m () Source #

Rungs the action when debug is on.

logFile :: forall (p :: HandleMode) m. (CanWrite p, HasCallStack, MonadHandleWriter m) => LockedHandle p -> FileLog -> m () Source #

Logs to a file. This function is not thread-safe! Hence care must be taken to avoid it being called by multiple threads.