Search code examples
cakebuild

Cake logging with colours


I've read about cake's console aliases.

Is it possible to log using colours?

For example, I'd log success / warning / error in green / orange / red:

CustomWarning("WARN: Foo bar baz!");    // orange text

Solution

  • Cake comes with Spectre.Console as documented here: https://cakebuild.net/docs/writing-builds/console-output#advanced-output.

    You can use it to print out formatted text:

    AnsiConsole.Write(new Markup("[bold yellow]Hello[/] [red]World![/]"));
    

    To have all logs, including the ones from Cake itself or addins, replaced, you can write a custom module with an ICakeLog implementation which uses Spectre.Console to write log messages.

    See https://github.com/cake-contrib/Cake.BuildSystems.Module for an example of an module which implements custom logging.