Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/fullstack-build/tslog
- Owner: fullstack-build
- License: mit
- Created: 2020-04-23T09:08:24.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T19:26:48.000Z (11 months ago)
- Last Synced: 2024-05-01T09:47:17.949Z (9 months 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: 6.35 MB
- Stars: 1,259
- Watchers: 8
- Forks: 60
- Open Issues: 41
-
Metadata Files:
- Readme: README.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
[![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:
```htmltslog 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, //