Loading...
Loading...
Guide for Workleap's logging library (@workleap/logging) that provides structured, composable logging for frontend TypeScript applications. Use this skill when: (1) Setting up logging in a Workleap frontend application (2) Creating or configuring loggers (BrowserConsoleLogger, CompositeLogger) (3) Understanding log levels (debug, information, warning, error, critical) (4) Building complex log entries with chained segments (withText, withObject, withError) (5) Using logging scopes to group related log entries (6) Styling log output in browser console (7) Composing multiple loggers to send logs to different destinations (8) Filtering logs by severity level (9) Integrating logging with LogRocket or other telemetry tools (10) Reviewing logging-related changes in pull requests (11) Questions about logging best practices specific to wl-logging
npx skill4agent add workleap/wl-logging workleap-loggingpnpm add @workleap/loggingdebuginformationwarningerrorcriticalRootLoggerLoggeruseLogger()RootLogger// Squide example:
import { useLogger } from "@squide/firefly";
import type { RootLogger } from "@workleap/logging";
const logger = useLogger();
(logger as RootLogger).startScope("User signup");import { BrowserConsoleLogger, LogLevel } from "@workleap/logging";
// Basic usage
const logger = new BrowserConsoleLogger();
// With minimum log level
const logger = new BrowserConsoleLogger({ logLevel: LogLevel.information });import { BrowserConsoleLogger, CompositeLogger } from "@workleap/logging";
import { LogRocketLogger } from "@workleap/telemetry"; // or from "@workleap/logrocket"
const logger = new CompositeLogger([
new BrowserConsoleLogger(),
new LogRocketLogger()
]);logger.debug("message");
logger.information("message");
logger.warning("message"); // or logger.warn("message")
logger.error("message");
logger.critical("message");logger
.withText("Processing order")
.withObject({ orderId: 123 })
.withError(new Error("Failed"))
.error();logger.withText("Success", {
style: { color: "green", fontWeight: "bold" }
}).information();logger
.withText("Line 1")
.withLineChange()
.withText("Line 2")
.debug();const scope = logger.startScope("User signup");
scope.information("Form loaded");
scope.debug("Validating...");
scope.withText("Failed").withError(err).error();
// Output all scope entries
scope.end();
// Or dismiss without output
scope.end({ dismiss: true });// At creation
const scope = logger.startScope("Label", {
labelStyle: { backgroundColor: "purple", color: "white" }
});
// At end (useful for status-based styling)
scope.end({
labelStyle: { backgroundColor: "green", color: "white" }
});CompositeLoggerimport { createCompositeLogger, BrowserConsoleLogger } from "@workleap/logging";
import { LogRocketLogger } from "@workleap/telemetry"; // or from "@workleap/logrocket"
const logger = createCompositeLogger(false, [new BrowserConsoleLogger(), new LogRocketLogger()]);verboseBrowserConsoleLoggerloggersCompositeLoggerLogRocketLogger@workleap/telemetry@workleap/logrocketimport { LogRocketLogger } from "@workleap/telemetry"; // or from "@workleap/logrocket"
const logger = new LogRocketLogger();
logger.debug("Application started!");CompositeLoggerimport { BrowserConsoleLogger, CompositeLogger } from "@workleap/logging";
import { LogRocketLogger } from "@workleap/telemetry"; // or from "@workleap/logrocket"
const logger = new CompositeLogger([
new BrowserConsoleLogger(),
new LogRocketLogger()
]);
logger.debug("Application started!"); // Processed by both loggersimport { BrowserConsoleLogger, CompositeLogger, LogLevel } from "@workleap/logging";
const isDev = process.env.NODE_ENV === "development";
const logger = new BrowserConsoleLogger({
logLevel: isDev ? LogLevel.debug : LogLevel.information
});try {
await processOrder(orderId);
} catch (error) {
logger
.withText("Failed to process order")
.withObject({ orderId })
.withError(error as Error)
.error();
}async function registerModule(moduleName: string) {
const scope = logger.startScope(`${moduleName} registration`);
try {
scope.debug("Registering routes...");
await registerRoutes();
scope.debug("Routes registered");
scope.debug("Fetching data...");
await fetchData();
scope.debug("Data loaded");
scope.end({ labelStyle: { color: "green" } });
} catch (error) {
scope.withText("Registration failed").withError(error as Error).error();
scope.end({ labelStyle: { color: "red" } });
throw error;
}
}import { BrowserConsoleLogger, CompositeLogger, LogLevel } from "@workleap/logging";
import { LogRocketLogger } from "@workleap/telemetry"; // or from "@workleap/logrocket"
const logger = new CompositeLogger([
new BrowserConsoleLogger({
logLevel: LogLevel.error
}),
new LogRocketLogger({
logLevel: LogLevel.debug
})
]);| Environment | Recommended Level |
|---|---|
| Development | |
| Production | |
.debug().error()scope.end()errorwarningwithObject()withError()RootLoggeruseLogger()RootLogger(logger as RootLogger).startScope("Label")