https://github.com/fullstack-build/tslog
๐ tslog - Universal Logger for TypeScript and JavaScript
https://github.com/fullstack-build/tslog
error-handling exceptions json json-api logger logging logging-library pretty-print stack stacktrace typescript-library
Last synced: 27 days ago
JSON representation
๐ tslog - Universal Logger for TypeScript and JavaScript
- Host: GitHub
- URL: https://github.com/fullstack-build/tslog
- Owner: fullstack-build
- License: mit
- Created: 2020-04-23T09:08:24.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2026-02-06T13:36:19.000Z (about 1 month ago)
- Last Synced: 2026-02-16T01:27:46.355Z (29 days ago)
- Topics: error-handling, exceptions, json, json-api, logger, logging, logging-library, pretty-print, stack, stacktrace, typescript-library
- Language: TypeScript
- Homepage: https://tslog.js.org
- Size: 5.62 MB
- Stars: 1,608
- Watchers: 7
- Forks: 74
- Open Issues: 76
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome - fullstack-build/tslog - ๐ tslog - Universal Logger for TypeScript and JavaScript (TypeScript)
README
# ๐ tslog: Beautiful logging experience for TypeScript and JavaScript
[](https://www.typescriptlang.org)

[](https://www.npmjs.com/package/tslog)

[](https://codecov.io/github/fullstack-build/tslog?branch=master)
[](https://github.com/prettier/prettier)
[](https://github.com/sponsors/fullstack-build)
[](https://github.com/fullstack-build/tslog)
> Powerful, fast and expressive logging for TypeScript and JavaScript

## Highlights
โก **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**
## Example
```typescript
import { Logger, ILogObj } from "tslog";
const log: Logger = new Logger();
log.silly("I am a silly log.");
```
## [Become a Sponsor](https://github.com/sponsors/fullstack-build)
Donations help me allocate more time for my open source work.
[](https://github.com/sponsors/fullstack-build)
## Install
```bash
npm install tslog
```
### Node.js
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.
### Deno
```ts
// main.ts
import { Logger } from "npm:tslog";
const logger = new Logger();
logger.info("Hello from Deno");
```
```bash
deno run main.ts
# grant optional metadata access: deno run --allow-env main.ts
```
### Bun
```ts
// main.ts
import { Logger } from "tslog";
const logger = new Logger();
logger.info("Hello from Bun");
```
```bash
bun run main.ts
# or add "dev": "bun run src/main.ts" to package.json scripts
```
Browser:
```html
tslog example
Example
const logger = new tslog.Logger();
logger.silly("I am a silly log.");
```
**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, //