Skip to content
ConsoleMonster

Log tail

Watch a bounded log fill with synthetic events and a recoverable warning.

Demos Terminal apps

Use it when a command needs a bounded live event log that preserves its final state.

  • Live
  • 88×18
  • PowerShell 7.4+
  • .NET 8.0+
Log tail 88×1824-bitFull

How it's built

The whole program in one file, with its sample data at the top. It drew the recording above; both languages draw the same cells.

PowerShelllog-tail.ps1View on GitHub
# Reveal a bounded stream of sample log events in a live region.
[CmdletBinding()]
param(
    [switch] $StaticSnapshot,
    [ValidateRange(0, 4)] [int] $Step = 0
)

Import-Module ConsoleMonster
# All data is synthetic and inline; no services are contacted or changed.
# All values are synthetic. This example never connects to a host.

# Data: fictional inputs kept in memory.
$messages = @(
    '[muted]09:41:00[/] [accent]INFO[/]  Worker started'
    '[muted]09:41:01[/] [pass]INFO[/]  Loaded 12 queued jobs'
    '[muted]09:41:02[/] [warn]WARN[/]  Cache cold; using local fallback'
    '[muted]09:41:03[/] [pass]INFO[/]  Cache warm; queue draining'
    '[muted]09:41:04[/] [pass]INFO[/]  Batch complete; no jobs lost'
)
# Layout: construct the widgets shown on screen.
function New-DemoFrame($Tick) {
    New-ConsoleRows -Gap 1 {
        '[bold]Application log[/] [muted]· worker events[/]'
        New-ConsolePanel -Title './logs/worker.log' {
            foreach ($line in $messages[0..$Tick]) { $line }
        }
        "[muted]$($Tick + 1) / 5 events · Ctrl+C stops the live run[/]"
    }
}

# Live updates: print one state headlessly, or run the bounded simulation.
if ($StaticSnapshot -or [Console]::IsInputRedirected) {
    New-DemoFrame $Step | Write-ConsoleWidget
    return
}
$frames = @(0..4 | ForEach-Object { New-DemoFrame $_ })
$screen = New-ConsoleRegion -Name demo -Widget $frames[0]
Start-ConsoleDashboard $screen -ArgumentList (, $frames) {
    param($Frames)
    foreach ($frame in $Frames) {
        if ($ConsoleSession.Cancellation.IsCancellationRequested) { break }
        Set-ConsoleRegion -Name demo -Widget $frame
        Start-Sleep -Milliseconds 650
    }
}
C#Program.csView on GitHub
// Reveal a bounded stream of sample log events in a live region.
// All data is synthetic and inline; no services are contacted or changed.
using ConsoleMonster;
using ConsoleMonster.Layout;
using ConsoleMonster.Live;
using ConsoleMonster.Widgets;

// All values are synthetic. This example never connects to a host.

// Data: fictional inputs kept in memory.
string[] messages = {
    "[muted]09:41:00[/] [accent]INFO[/]  Worker started",
    "[muted]09:41:01[/] [pass]INFO[/]  Loaded 12 queued jobs",
    "[muted]09:41:02[/] [warn]WARN[/]  Cache cold; using local fallback",
    "[muted]09:41:03[/] [pass]INFO[/]  Cache warm; queue draining",
    "[muted]09:41:04[/] [pass]INFO[/]  Batch complete; no jobs lost"
};
// Run options: redirected input selects a deterministic snapshot.
bool snapshot = args.Contains("--snapshot") || (!args.Contains("--interactive") && Console.IsInputRedirected);
int stepAt = Array.IndexOf(args, "--step");
int step = stepAt < 0 ? 0 : int.Parse(args[stepAt + 1], System.Globalization.CultureInfo.InvariantCulture);
if (step < 0 || step > 4) throw new ArgumentOutOfRangeException(nameof(step));

// Layout: construct the widgets shown on screen.
IWidget Frame(int tick) {
    Rows lines = new Rows();
    foreach (string line in messages.Take(tick + 1)) lines.Add(new TextBlock(line));
    return new Rows(new TextBlock("[bold]Application log[/] [muted]· worker events[/]"),
        new Panel(lines, "./logs/worker.log"), new TextBlock("[muted]" +
            (tick + 1).ToString(System.Globalization.CultureInfo.InvariantCulture) +
            " / 5 events · Ctrl+C stops the live run[/]")) { Gap = 1 };
}

// Live updates: print one state headlessly, or run the bounded simulation.
if (snapshot) {
    Terminal.Write(Frame(step));
    return;
}
Slot screen = new Slot("demo", Frame(0));
using LiveSession session = new LiveSession(screen);
session.Run(live => {
    for (int tick = 0; tick <= 4 && !live.Cancellation.IsCancellationRequested; tick++) {
        screen.Handle(live).Set(Frame(tick));
        if (live.Cancellation.WaitHandle.WaitOne(650)) break;
    }
});

Run it yourself

Three steps in PowerShell, four in C#. Every command copies with one click.

  1. Install the module

    Once. Windows PowerShell 5.1 or PowerShell 7 on Windows, macOS or Linux.

    Install-Module ConsoleMonster -Scope CurrentUser
  2. Save the program

    Download it, or copy it from above into log-tail.ps1.

  3. Run it

    From the folder you saved it in.

    ./log-tail.ps1
  1. Create a project

    A plain console app; .NET 8 or later.

    dotnet new console -n Logtail; cd Logtail
  2. Add ConsoleMonster

    The only package the program needs.

    dotnet add package ConsoleMonster
  3. Replace Program.cs

    Download it, or copy the program from above.

  4. Run it

    dotnet run

Or skip the copying. Every demo ships with the module and the project template.

Show-ConsoleDemo log-tail
Get-ConsoleDemo log-tail -Path ./log-tail.ps1
dotnet new install ConsoleMonster.Templates
dotnet new consolemonster --demo log-tail -n Logtail

Make it yours

Start with these, then read the rest of the file.

  1. Replace the inline messages with your event source.

  2. Keep a bounded buffer when following long runs.

  3. Choose which levels deserve warning or failure colours.

More terminal apps

All demos