# ๐Ÿ“ tslog: Beautiful logging experience for TypeScript and JavaScript [![lang: Typescript](https://img.shields.io/badge/Language-Typescript-Blue.svg?style=flat-square)](https://www.typescriptlang.org) ![License: MIT](https://img.shields.io/npm/l/tslog?logo=tslog&style=flat-square) [![npm version](https://img.shields.io/npm/v/tslog?color=76c800&logoColor=76c800&style=flat-square)](https://www.npmjs.com/package/tslog) ![CI: GitHub](https://github.com/fullstack-build/tslog/actions/workflows/ci.yml/badge.svg) [![codecov.io](https://codecov.io/github/fullstack-build/tslog/coverage.svg?branch=v4)](https://codecov.io/github/fullstack-build/tslog?branch=master) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/fullstack-build) [![GitHub stars](https://img.shields.io/github/stars/fullstack-build/tslog.svg?style=social&label=Star)](https://github.com/fullstack-build/tslog) > Powerful, fast and expressive logging for TypeScript and JavaScript ![tslog pretty output](https://raw.githubusercontent.com/fullstack-build/tslog/master/docs/assets/tslog.png "tslog pretty output in browser and Node.js") ## 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://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](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

``` **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, //