Powerful, fast and expressive logging for TypeScript and JavaScript
โก Fast and powerful
๐ชถ Lightweight and flexible
๐ Universal: Works in Browsers and Node.js
๐ฎโ๏ธ 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
import { Logger, ILogObj } from "tslog";
const log: Logger<ILogObj> = new Logger();
log.silly("I am a silly log.");
Donations help me allocate more time for my open source work.
npm install tslog
In order to run a native ES module in Node.js, you have to do two things:
- Set
"type": "module"
inpackage.json
. - For now, start with
--experimental-specifier-resolution=node
Example package.json
{
"name": "NAME",
"version": "1.0.0",
"main": "index.js",
// here:
"type": "module",
"scripts": {
"build": "tsc -p .",
// and here:
"start": "node --enable-source-maps --experimental-specifier-resolution=node index.js"
},
"dependencies": {
"tslog": "^4"
},
"devDependencies": {
"typescript": "^4"
},
"engines": {
"node": ">=16"
}
}
With this package.json
you can simply build and run it:
npm run build
npm start
Otherwise:
ESM: Node.js with JavaScript:
node --enable-source-maps --experimental-specifier-resolution=node
CJS: Node.js with JavaScript:
node --enable-source-maps
ESM: Node.js with TypeScript and ts-node
:
node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm
CJS: Node.js with TypeScript and ts-node
:
node --enable-source-maps --no-warnings --loader ts-node/cjs
Browser:
<!doctype html>
<html lang="en">
<head>
<title>tslog example</title>
</head>
<body>
<h1>Example</h1>
<script src="tslog.js"></script>
<script>
const logger = new tslog.Logger();
logger.silly("I am a silly log.");
</script>
</body>
</html>
Enable TypeScript source map support:
This feature enables tslog
to reference a correct line number in your TypeScript source code.