Extensible TypeScript Logger for Node.js and Browser.
npm install tslog
!License: MIT

!CI: GitHub




> Powerful, fast and expressive logging for TypeScript and JavaScript
โก Fast and powerful
๐ชถ Lightweight and flexible
๐ Universal: Works in Browsers, Node.js, Deno and Bun
๐ฎโ๏ธ Fully typed with TypeScript support (native source maps)
๐ _Pretty_ or JSON output
๐ Customizable log level
โญ๏ธ Supports _circular_ structures
๐ฆธ Custom pluggable loggers
๐
Object and error interpolation
๐ค Stack trace and pretty errors
๐จโ๐งโ๐ฆ Sub-logger with inheritance
๐ Mask/hide secrets and keys
๐ฆ CJS & ESM with tree shaking support
โ๏ธ Well documented and tested
``typescript
import { Logger, ILogObj } from "tslog";
const log: Logger
log.silly("I am a silly log.");
`

`bash`
npm install tslog
Enable native ESM by setting "type": "module" and run Node with source maps for accurate stack traces:
`json5`
{
"name": "NAME",
"version": "1.0.0",
"type": "module",
"scripts": {
"build": "tsc -p .",
"start": "node --enable-source-maps dist/index.js"
},
"dependencies": {
"tslog": "^4"
}
}
After building (npm run build), start your app with:
`bash`
npm start
Other handy entry points:
- node --enable-source-maps dist/index.cjs โ run the CommonJS bundle.node --enable-source-maps --loader ts-node/esm src/index.ts
- โ execute TypeScript via ts-node in ESM mode.node --enable-source-maps --require ts-node/register src/index.ts
- โ execute TypeScript via ts-node in CommonJS mode.
`ts
// main.ts
import { Logger } from "npm:tslog";
const logger = new Logger();
logger.info("Hello from Deno");
`
`bash`
deno run main.tsgrant optional metadata access: deno run --allow-env main.ts
`ts
// main.ts
import { Logger } from "tslog";
const logger = new Logger();
logger.info("Hello from Bun");
`
`bash`
bun run main.tsor add "dev": "bun run src/main.ts" to package.json scripts
Browser:
`htmlExample
`
Enable TypeScript source map support:
This feature enables tslog to reference a correct line number in your TypeScript source code.
`json5
// tsconfig.json
{
// ...
compilerOptions: {
// ...
"inlineSourceMap": true, //