Debugging
@portablesheep/brevity-plugin-debug adds development logs and error pages. It doesn't create routes or middleware automatically; you choose what to expose.
Add diagnostics
import { createApp, HttpError } from "@portablesheep/brevity";
import { DebugPlugin, type DebugService } from "@portablesheep/brevity-plugin-debug";
export function debugApp(enabled = process.env.NODE_ENV !== "production") {
let debug: DebugService;
const app = createApp({
onError(error, req, res) {
if (enabled && error instanceof Error && !(error instanceof HttpError)) {
debug.renderErrorResponse(res, error, { method: req?.method, path: req?.path });
}
// Returning without a response uses core's safe default handler.
},
plugins: [new DebugPlugin({ enabled, verbose: true })],
});
debug = app.container.get<DebugService>("debug");
app.use(async (req, res, next) => {
debug.info(`${req.method} ${req.path}`);
return next(req, res);
});
if (enabled) {
app.router.get("/debug", (_req, res) => res.json({ logs: debug.getLogs() }));
}
app.router.get("/", (_req, res) => res.json({ ok: true }));
return app;
}This example adds a request logger, a development-only /debug route, and an onError hook. Known HttpErrors use the normal response; unexpected production errors stay generic and are logged on the server.
Keep debug routes private
Error pages can contain stacks and request details. Don't pass cookies, tokens, or raw request bodies to the renderer. Disabling the service hides its error details, but doesn't protect a custom route that calls getLogs().
Logs
Use info, warn, or error with a message and optional data. debug also requires verbose: true. Logs go to the console and a process-local history of up to 100 entries.
getLogs() returns a copy; clear() removes history. Disabling doesn't erase existing entries. For durable production logs and metrics, use your host's observability tools. See the plugin reference.