A drop-in logging module to enhance console.log() that provides the following:
- All logs and metrics in JSON format to STDOUT
- Metrics Logging
- Blazing fast high-performance non-blocking STDOUT writer (benchmark a million log events, 301M, in 2.3s)
- Handles formating javascript error
- Not a framework
- Does not support log files
Add to your project
deno add jsr:@daringway/logger
In your applications entry point
import { initLogger } from "@daringway/logger";
initLogger();Start logging with console.error, console.warn, console.log,
console.info, and console.trace, it's that easy.
Preconfigured support for ExpressJS and Fresh V1 provides the following:
- Metrics (Request and Logger)
- Log Levels
- Trace Logging
- Metadata
import { expressLoggerMiddleware, initLogger } from "@daringway/logger";
initLogger(backendConfig.logConfig);
const app: Express = express();
// Set this up first, it registers the logger onFinsih and starts the metrics timer
app.use(expressLoggerMiddleware());In fresh.config.ts
import { freshV1LoggerPlugin, initLogger } from "@daringway/logger";
initLogger();
export default defineConfig({
plugins: [
tailwind(),
freshV1LoggerPlugin(),
],
});export type RequestContext = {
trace: {
requestId: string;
tracePath: string[];
correlationId: string;
sessionId: string;
};
client: {
userAgent: string;
applicationName: string;
applicationVersion: string;
};
request: {
method: string;
path: string;
};
metrics?: MetricsTracker<never>;
};LOG_LEVEL: "error" | "warn" | "info" | "log" | "debug" | "trace" Sets the logging level. error and metrics will always log. Default: "log"
LOG_SECONDS_BETWEEN_METRICS: number Number of seconds between automatic metrics logging. Default: 500
LOG_OBJECTS: boolean Enable logging of full objects in trace logs. Use for WebStorm testing. Default: false
LOG_PRETTY: boolean Enable pretty printing of logs for development. Use for CLI testing. Default: false
LOG_WITH_CONSOLE: boolean Enable logging to console. Default: false, writes to STDOUT
When logging use this as a guide on which level to log at.
- metrics: Keeping tabs on the numbers and performance stats (always logged)
- error: Uh-oh, something went wrong! Think of it like the 'outer safety net' catching unexpected surprises. (always logged)
- warn: Heads up! Something is off, but we're still okay for now.
- info: Just keeping you posted—things like the service starting up or shutting down.
- log: Everyday chatter-like requests coming in and going out, nothing out of the ordinary.
- debug: Developer-level love. The nitty-gritty details only developers adore.
- trace: Super-detailed breadcrumbs—like tracking function calls or variable values.