Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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: 3 months ago
JSON representation

๐Ÿ“ tslog - Universal Logger for TypeScript and JavaScript

Awesome Lists containing this project

README

        

# ๐Ÿ“ 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 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**

## 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
```

In order to run a native ES module in Node.js, you have to do two things:

1) Set `"type": "module"` in `package.json`.
2) For now, start with `--experimental-specifier-resolution=node`

Example `package.json`
```json5
{
"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:
```bash
npm run build
npm start
```

**Otherwise:**

ESM: Node.js with JavaScript:
```bash
node --enable-source-maps --experimental-specifier-resolution=node
```

CJS: Node.js with JavaScript:
```bash
node --enable-source-maps
```

ESM: Node.js with TypeScript and `ts-node`:
```bash
node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm
```

CJS: Node.js with TypeScript and `ts-node`:
```bash
node --enable-source-maps --no-warnings --loader ts-node/cjs
```

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