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.

def Lake.Ansi.chalk (colorCode 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
Equations

Unicode icon for representing the log level.

Equations

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

Equations
Equations
  • One or more equations did not get rendered due to their size.
Equations
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 "No deprecation message available." (since := "2024-05-18")]
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
@[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
@[reducible, inline, deprecated "Deprecated without replacement." (since := "2024-05-18")]
Equations
@[reducible, inline]
abbrev Lake.MonadLog.stream {m : TypeType u_1} [MonadLiftT BaseIO m] (out : IO.FS.Stream) (minLv : Lake.LogLevel := Lake.LogLevel.info) (useAnsi : Bool := false) :
Equations
@[inline]
def Lake.MonadLog.error {m : Type u_1 → Type u_2} {α : Type u_1} [Alternative m] [Lake.MonadLog m] (msg : String) :
m α
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
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
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
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]
def Lake.Log.extract (log : Lake.Log) (start stop : Lake.Log.Pos) :

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.take 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
@[inline]

Returns the monad's log.

Equations
@[inline]

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

Equations
@[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
@[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
@[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]

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

Equations
@[inline]

Fail without logging anything.

Equations
@[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
@[reducible, inline]
abbrev Lake.LogT.run {m : TypeType} {α : Type} [Functor m] (self : Lake.LogT m α) (log : Lake.Log := ) :
m (α × Lake.Log)
Equations
@[reducible, inline]
abbrev Lake.LogT.run' {m : TypeType} {α : Type} [Functor m] (self : Lake.LogT m α) (log : 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
@[reducible, inline]
abbrev Lake.ELogT.run {m : TypeType} {α : Type} (self : Lake.ELogT m α) (log : Lake.Log := ) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.run' {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : 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 : Lake.Log := ) :
Equations
@[reducible, inline]
abbrev Lake.ELogT.run?' {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : 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? (since := "2024-05-18")]
abbrev Lake.ELogT.captureLog {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : 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. This 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
@[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
@[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
@[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.
@[reducible, inline]
abbrev Lake.LogIO.captureLog {m : TypeType} {α : Type} [Functor m] (self : Lake.ELogT m α) (log : Lake.Log := ) :
Equations
@[reducible, inline]
abbrev Lake.LoggerIO (α : Type) :

A monad equipped with a log function and the ability to perform I/O. Unlike LogIO, log entries are not retained by the monad but instead eagerly passed to the log function.

Equations
Instances For
@[inline]

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

Equations
  • self.toBaseIO minLv ansiMode out = do let __do_liftout.getLogger minLv ansiMode (fun (x : Except PUnit α) => x.toOption) <$> (ReaderT.run self __do_lift).toBaseIO
Equations
  • One or more equations did not get rendered due to their size.
@[inline]
def Lake.LoggerIO.run?' {α : Type} (self : Lake.LoggerIO α) (logger : Lake.LogEntryBaseIO PUnit := fun (x : Lake.LogEntry) => pure ()) :
Equations