nosole
v0.0.0
Published
A lightweight logger that keeps your console clean in production.
Readme
nosole
A lightweight logger for JavaScript and TypeScript that keeps your console clean in production by default.
- 🌐 Works everywhere — Node.js, Browsers, Bun, Deno, Edge runtimes, and Workers
- 📦 ESM + CommonJS support out of the box
- 🚀 Zero-overhead muted logs using noop functions
- 🛡️ Automatically disables logs in production
- 🪶 Zero dependencies and tiny bundle size
Installation
npm install nosoleQuick Start
Basic Usage
import { log, info, warn, error, debug } from "nosole";
log("Hello from your app!");
info("User session initialized.");
warn("Rate limit approaching...");
error("Failed to fetch dashboard data.");
debug("Internal cache state:", { items: 4 });In development:
- logs behave normally
In production:
- logs are automatically muted
Scoped Loggers
import { createLogger } from "nosole";
const authLogger = createLogger({
prefix: "AuthService",
});
authLogger.info("User logged in successfully");Output:
[AuthService] User logged in successfullyAPI
createLogger(options?)
Creates a custom logger instance.
interface LoggerOptions {
prefix?: string;
enabled?: boolean;
}Example
const logger = createLogger({
prefix: "API",
enabled: true,
});Environment Detection
nosole safely detects production environments using:
process.env.NODE_ENVDeno.env.get("NODE_ENV")import.meta.env
Supported runtimes:
- Node.js
- Bun
- Deno
- Browsers
- Vite
- Edge runtimes
- Cloudflare Workers
License
MIT
