Browser Console
Using the browser's console to print valuable program information is an integral part of the development process. The BrowserConsole
utility class comes with a slew of features to enhance logging capabilities.
Instance
Get an instance of BrowserConsole
using the App.console()
method. Print any Object
desired as one of the five log types: log, info, warn, error, or debug.
import static com.webforj.App.console;
// Types
console().log("Log message");
console().info("Info message");
console().warn("Warn message");
console().error("Error message");
console().debug("Debug message");
Styling
Use the builder methods to set the appearance of the log message. Each builder has options to change a specific property. It's also possible to mix multiple styles. Once a console message prints, any styling applied won't carry over to subsequent messages unless explicitly redefined.
Use the setStyle
method to change the properties of the BrowserConsole
log not specified by the builders.
Background color
Set the background color with the background()
method, which returns the BackgroundColorBuilder
.
Use methods named by color, like blue()
, or choose a specific value with colored(String color)
.
// Background Examples
console().background().blue().log("Blue background");
console().background().colored("#031f8f").log("Custom blue background");