Documentation

Lake.Util.Log

Equations
inductive Lake.AnsiMode :

Whether to ANSI escape codes.

  • auto: Lake.AnsiMode

    Automatically determine whether to use ANSI escape codes based on whether the stream written to is a terminal.

  • ansi: Lake.AnsiMode

    Use ANSI escape codes.

  • noAnsi: Lake.AnsiMode

    Do not use ANSI escape codes.

Returns whether to ANSI escape codes with the stream out.

Equations
def Lake.Ansi.chalk (colorCode : String) (text : String) :

Wrap text in ANSI escape sequences to make it bold and color it the ANSI colorCode. Resets all terminal font attributes at the end of the text.

Equations
inductive Lake.OutStream :

A pure representation of output stream.

Instances For

Returns the real output stream associated with OutStream.

Equations
Equations

Unicode icon for representing the log level.

Equations

ANSI escape code for coloring text of at the log level.

Equations
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
@[inline]
def Lake.logVerbose {m : Type u_1 → Type u_2} [Monad m] [Lake.MonadLog m] (message : String) :
Equations
@[inline]
def Lake.logInfo {m : Type u_1 → Type u_2} [Monad m] [Lake.MonadLog m] (message : String) :
Equations
@[inline]
def Lake.logWarning {m : Type u_1 → Type u_2} [Lake.MonadLog m] (message : String) :
Equations
@[inline]
def Lake.logError {m : Type u_1 → Type u_2} [Lake.MonadLog m] (message : String) :
Equations
@[specialize #[]]
Equations
  • One or more equations did not get rendered due to their size.
@[deprecated]
Equations
  • One or more equations did not get rendered due to their size.
def Lake.logToStream (e : Lake.LogEntry) (out : IO.FS.Stream) (minLv : Lake.LogLevel) (useAnsi : Bool) :
Equations
@[reducible, inline]
abbrev Lake.MonadLog.nop {m : TypeType u_1} [Pure m] :
Equations
Equations
  • Lake.MonadLog.instInhabitedOfPure = { default := Lake.MonadLog.nop }
@[reducible, inline]
abbrev Lake.MonadLog.lift {m : Type u_1 → Type u_2} {n : Type u_1 → Type u_3} [MonadLiftT m n] (self : Lake.MonadLog m) :
Equations
instance Lake.MonadLog.instOfMonadLift {m : Type u_1 → Type u_2} {n : Type u_1 → Type u_3} [MonadLift m n] [methods : Lake.MonadLog m] :
Equations
  • Lake.MonadLog.instOfMonadLift = methods.lift
@[reducible, inline, deprecated]
Equations
@[reducible, inline]
Equations
Equations
@[reducible, inline]
Equations
  • out.logger minLv ansiMode = { logEntry := fun (e : Lake.LogEntry) => liftM (out.logEntry e minLv ansiMode) }
@[reducible, inline]
Equations
@[reducible, inline]
Equations
@[inline]
Equations
@[reducible, inline]
abbrev Lake.MonadLogT (m : Type u → Type v) (n : Type v → Type w) (α : Type v) :
Type (max v w)

A monad equipped with a MonadLog instance

Equations
Instances For
instance Lake.MonadLogT.instInhabitedOfPure {n : Type u_1 → Type u_2} {α : Type u_1} {m : Type u_3 → Type u_1} [Pure n] [Inhabited α] :
Equations
  • Lake.MonadLogT.instInhabitedOfPure = { default := fun (x : Lake.MonadLog m) => pure default }
instance Lake.MonadLogT.instMonadLogOfMonadOfMonadLiftT {n : Type u_1 → Type u_2} {m : Type u_1 → Type u_1} [Monad n] [MonadLiftT m n] :
Equations
@[inline]
def Lake.MonadLogT.adaptMethods {n : Type u_1 → Type u_2} {m : Type u_3 → Type u_1} {m' : Type u_4 → Type u_1} {α : Type u_1} [Monad n] (f : Lake.MonadLog mLake.MonadLog m') (self : Lake.MonadLogT m' n α) :
Equations
@[inline]
def Lake.MonadLogT.ignoreLog {m : TypeType u_1} {n : Type u_1 → Type u_2} {α : Type u_1} [Pure m] (self : Lake.MonadLogT m n α) :
n α
Equations
  • self.ignoreLog = self Lake.MonadLog.nop
Equations
structure Lake.Log.Pos :

A position in a Log (i.e., an array index). Can be past the log's end.

Instances For
Equations
Equations
@[inline]
Equations
@[inline]
Equations
  • log.size = log.entries.size
@[inline]
Equations
@[inline]
Equations
@[inline]
Equations
  • log.endPos = { val := log.entries.size }
@[inline]
Equations
  • log.push e = { entries := log.entries.push e }
@[inline]
Equations
  • log.append o = { entries := log.entries.append o.entries }
@[inline]

Takes log entries between start (inclusive) and stop (exclusive).

Equations
  • log.extract start stop = { entries := log.entries.extract start.val stop.val }
@[inline]

Removes log entries after pos (inclusive).

Equations
  • log.dropFrom pos = { entries := log.entries.shrink pos.val }
@[inline]

Takes log entries before pos (exclusive).

Equations
  • log.takeFrom pos = log.extract pos log.endPos
@[inline]

Splits the log into two from pos. The first log is from the start to pos (exclusive), and the second log is from pos (inclusive) to the end.

Equations
  • log.split pos = (log.dropFrom pos, log.takeFrom pos)
Equations
@[inline]
def Lake.Log.replay {m : Type u_1 → Type u_2} [Monad m] [logger : Lake.MonadLog m] (log : Lake.Log) :
Equations
@[inline]
Equations
@[inline]
Equations

The max log level of entries in this log. If empty, returns trace.

Equations
@[inline]

Add a LogEntry to the end of the monad's Log.

Equations
@[reducible, inline]
Equations
  • Lake.MonadLog.ofMonadState = { logEntry := Lake.pushLogEntry }
@[inline]

Returns the monad's log.

Equations
  • Lake.getLog = get
@[inline]

Returns the current end position of the monad's log (i.e., its size).

Equations
  • Lake.getLogPos = (fun (x : Lake.Log) => x.endPos) <$> Lake.getLog
@[inline]

Removes the section monad's log starting and returns it.

Equations
@[inline]

Removes the monad's log starting at pos and returns it. Useful for extracting logged errors after catching an error position from an ELogT (e.g., LogIO).

Equations
@[inline]

Backtracks the monad's log to pos. Useful for discarding logged errors after catching an error position from an ELogT (e.g., LogIO).

Equations
@[inline]
def Lake.extractLog {m : TypeType u_1} [Monad m] [MonadStateOf Lake.Log m] (x : m PUnit) :

Returns the log from x while leaving it intact in the monad.

Equations
  • Lake.extractLog x = do let iniPosLake.getLogPos x let logLake.getLog pure (log.takeFrom iniPos)
@[inline]
def Lake.withExtractLog {m : TypeType u_1} {α : Type} [Monad m] [MonadStateOf Lake.Log m] (x : m α) :
m (α × Lake.Log)

Returns the log from x and its result while leaving it intact in the monad.

Equations
  • Lake.withExtractLog x = do let iniPosLake.getLogPos let ax let logLake.getLog pure (a, log.takeFrom iniPos)
@[inline]
def Lake.withLogErrorPos {m : TypeType u_1} {α : Type} [Monad m] [MonadStateOf Lake.Log m] [MonadExceptOf Lake.Log.Pos m] (self : m α) :
m α

Performs x and backtracks any error to the log position before x.

Equations
@[inline]
def Lake.errorWithLog {m : TypeType u_1} {β : Type} [Monad m] [MonadStateOf Lake.Log m] [MonadExceptOf Lake.Log.Pos m] (self : m PUnit) :
m β

Performs x and groups all logs generated into an error block.

Equations
@[inline]
def Lake.withLoggedIO {m : TypeType u_1} {α : Type} [Monad m] [MonadLiftT BaseIO m] [Lake.MonadLog m] [MonadFinally m] (x : m α) :
m α

Captures IO in x into an informational log entry.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lake.ELog.error {m : TypeType u_1} {α : Type} [Monad m] [Lake.MonadLog m] [MonadStateOf Lake.Log m] [MonadExceptOf Lake.Log.Pos m] (msg : String) :
m α

Throw with the logged error message.

Equations
@[reducible, inline]

Alternative instance for monads with Log state and Log.Pos errors.

Equations
  • Lake.ELog.monadError = { error := fun {α : Type} => Lake.ELog.error }
@[inline]

Fail without logging anything.

Equations
  • Lake.ELog.failure = do let __do_liftLake.getLogPos throw __do_lift
@[inline]
def Lake.ELog.orElse {m : TypeType u_1} {α : Type} [Monad m] [MonadStateOf Lake.Log m] [MonadExceptOf Lake.Log.Pos m] (x : m α) (y : Unitm α) :
m α

Performs x. If it fails, drop its log and perform y.

Equations
@[reducible, inline]

Alternative instance for monads with Log state and Log.Pos errors.

Equations
@[reducible, inline]
abbrev Lake.LogT (m : TypeType) (α : Type) :

A monad equipped with a log.

Equations
Instances For
Equations
  • Lake.instMonadLogLogTOfMonad = Lake.MonadLog.ofMonadState
@[reducible, inline]
abbrev Lake.LogT.run {m : TypeType} {α : Type} [Functor m] (self : Lake.LogT m α) (log : optParam Lake.Log ) :
m (α × Lake.Log)
Equations
@[reducible, inline]
abbrev Lake.LogT.run' {m : TypeType} {α : Type} [Functor m] (self : Lake.LogT m α) (log : optParam Lake.Log ) :
m α
Equations
@[inline]
def Lake.LogT.takeAndRun {n : TypeType u_1} {m : TypeType} {α : Type} [Monad n] [MonadStateOf Lake.Log n] [MonadLiftT m n] [MonadFinally n] (self : Lake.LogT m α) :
n α

Run self with the log taken from the state of the monad n.

Warning: If lifting self from m to n fails, the log will be lost. Thus, this is best used when the lift cannot fail.

Equations
  • self.takeAndRun = do let __do_liftLake.takeLog let __discrliftM (self __do_lift) match __discr with | (a, log) => do set log pure a
@[inline]
def Lake.LogT.replayLog {n : TypeType u_1} {m : TypeType} {α : Type} [Monad n] [logger : Lake.MonadLog n] [MonadLiftT m n] (self : Lake.LogT m α) :
n α

Runs self in n and then replays the entries of the resulting log using the new monad's logger.

Equations
  • self.replayLog = do let __discrliftM (self ) match __discr with | (a, log) => do log.replay pure a
@[reducible, inline]
abbrev Lake.ELogT (m : TypeType) (α : Type) :

A monad equipped with a log and the ability to error at some log position.

Equations
Instances For
@[reducible, inline]
abbrev Lake.ELogResult (α : Type u_1) :
Type u_1
Equations
Equations
  • Lake.instMonadLogELogTOfMonad = Lake.MonadLog.ofMonadState
Equations
  • Lake.instMonadErrorELogTOfMonad = Lake.ELog.monadError
Equations
  • Lake.instAlternativeELogTOfMonad = Lake.ELog.alternative
@[reducible, inline]
abbrev Lake.ELogT.run {m : TypeType} {α : Type} (self : Lake.ELogT m α) (log : optParam Lake.Log ) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.run' {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : optParam Lake.Log ) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.toLogT {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.toLogT? {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.run? {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : optParam Lake.Log ) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.run?' {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : optParam Lake.Log ) :
m (Option α)
Equations
@[inline]
def Lake.ELogT.catchLog {m : TypeType} {α : Type} [Monad m] (f : Lake.LogLake.LogT m α) (self : Lake.ELogT m α) :
Equations
@[reducible, inline, deprecated Lake.ELogT.run?]
abbrev Lake.ELogT.captureLog {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : optParam Lake.Log ) :
Equations
@[inline]
def Lake.ELogT.takeAndRun {n : TypeType u_1} {m : TypeType} {α : Type} [Monad n] [MonadStateOf Lake.Log n] [MonadExceptOf Lake.Log.Pos n] [MonadLiftT m n] (self : Lake.ELogT m α) :
n α

Run self with the log taken from the state of the monad n,

Warning: If lifting self from m to n fails, the log will be lost. Thus, this is best used when the lift cannot fail. Note excludes the native log position failure of ELogT, which are lifted safely.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lake.ELogT.replayLog? {n : TypeType u_1} {m : TypeType} {α : Type} [Monad n] [logger : Lake.MonadLog n] [MonadLiftT m n] (self : Lake.ELogT m α) :
n (Option α)

Runs self in n and then replays the entries of the resulting log using the new monad's logger. Translates an exception in this monad to a none result.

Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lake.ELogT.replayLog {n : TypeType u_1} {m : TypeType} {α : Type} [Alternative n] [Monad n] [logger : Lake.MonadLog n] [MonadLiftT m n] (self : Lake.ELogT m α) :
n α

Runs self in n and then replays the entries of the resulting log using the new monad's logger. Translates an exception in this monad to a failure in the new monad.

Equations
  • One or more equations did not get rendered due to their size.
@[reducible, inline]
abbrev Lake.LogIO (α : Type) :

A monad equipped with a log, a log error position, and the ability to perform I/O.

Equations
Instances For
Equations
@[reducible, inline, deprecated Lake.ELogT.run?]
abbrev Lake.LogIO.captureLog {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : optParam Lake.Log ) :
Equations
@[inline]

Runs a LogIO action in BaseIO. Prints log entries of at least minLv to out.

Equations
  • One or more equations did not get rendered due to their size.