tslog is an extensible logging library designed for both Node.js and browser environments, written in TypeScript. Currently stable at version 4.10.2, it maintains an active release cadence with frequent updates and bug fixes, often addressing compatibility and build issues. Key differentiators include its universal compatibility (Node.js, Browsers, Deno, Bun), full TypeScript support with native source map integration for accurate stack traces, and flexible output options (pretty or JSON). It also handles circular structures, supports sub-loggers, allows object and error interpolation, and features masking for sensitive data, making it suitable for a wide range of application logging needs. The library has zero external dependencies, promoting a lightweight footprint.
npm install tslogVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate a `tslog` logger, configure its basic settings like log level and template, and use various logging methods. It also shows how to create a child logger for module-specific logging.
Adjust custom `transportFormatted` functions to accept `logMeta` as the fourth argument. If `settings` are still required, ensure the function signature accepts five parameters.
Migrate imports to use the primary `Logger` export from `'tslog'` instead of specific runtime helpers (e.g., `import { Logger } from 'tslog';`).Ensure your `tsconfig.json` includes `"sourceMap": true`. When running your compiled Node.js application, use `node --enable-source-maps dist/index.js` or similar for correct stack information.
Add `"type": "module"` to your `package.json` for native ESM. If you must use CommonJS, consider using `.cjs` file extensions for CJS-specific files or ensure appropriate TypeScript `moduleResolution` and `module` options.
In production environments, configure logger settings such as `hideLogPositionForProduction: true` to minimize overhead associated with collecting meta-information like code position.
For ESM projects, use `import { Logger } from 'tslog';`. For CJS projects that need to import an ESM module, you might need to use dynamic `import()` or configure `esModuleInterop: true` in `tsconfig.json` and adjust runtime environment if `type: module` is present in the dependency but not in your project. Alternatively, ensure Node.js is run in a CJS context for CJS bundle of tslog by explicitly calling `node dist/index.cjs` after compilation.If loading `tslog` via a `<script>` tag, access `Logger` through the global `tslog` object: `const logger = new tslog.Logger();`. If using a build tool, ensure it correctly handles ESM imports for browser environments.
Ensure `"sourceMap": true` is set in your `tsconfig.json`. When running your Node.js application, include the `--enable-source-maps` flag: `node --enable-source-maps dist/your-app.js`. For `ts-node`, use `--loader ts-node/esm` (ESM) or `--require ts-node/register` (CJS) with `--enable-source-maps`.
No dependency data recorded yet.