Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jathu/with-logger
A simple logger with context.
https://github.com/jathu/with-logger
Last synced: 6 days ago
JSON representation
A simple logger with context.
- Host: GitHub
- URL: https://github.com/jathu/with-logger
- Owner: jathu
- Created: 2021-08-24T14:59:55.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-26T20:38:50.000Z (about 1 year ago)
- Last Synced: 2024-10-06T08:38:22.887Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/with-logger
- Size: 114 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![with-logger](banner.png)
![npm Version](https://img.shields.io/npm/v/with-logger) ![Total Downloads](https://img.shields.io/npm/dt/with-logger?label=Downloads) ![Workflow status](https://github.com/jathu/with-logger/actions/workflows/release.yml/badge.svg)
## Installation
[npmjs.com/package/with-logger](https://www.npmjs.com/package/with-logger)
```bash
# yarn
$ yarn add with-logger# npm
$ npm install with-logger
```## Usage
Use it like `console`:
```typescript
import { logger } from "with-logger";const metadata = {
userId: "2e01d247-1dc1-4d39-a287-f8a069544d43",
location: "San Francisco, CA"
};logger.info("👋 Hello World");
// 2021-01-01 12:34:56.416 info : 👋 Hello Worldlogger.debug("User metadata", metadata);
// 2021-01-01 12:34:56.416 debug : User metadata {
// userId: "2e01d247-1dc1-4d39-a287-f8a069544d43",
// location: "San Francisco, CA"
// }logger.with({ userId: metadata.userId }).info("User changed location to", newLocation);
// 2021-01-01 12:34:56.416 info [userId=2e01d247-1dc1-4d39-a287-f8a069544d43] : User changed location to Menlo Park, CAlogger.with({ ...metadata }).warn("Failed to sync user location");
// 2021-01-01 12:34:56.416 info [userId=2e01d247-1dc1-4d39-a287-f8a069544d43] [location=San Francisco, CA] : Failed to sync user locationtry {
perform();
} catch (error) {
logger.with({ ...session }).error(error);
}
// 2021-01-01 12:34:56.416 error [id=6033bda3-1a63-44a9-97f1-e15e097c98c0] : Unable to reach server
```------
August 2021 - Toronto