# simple-leveled-log-methods

> a simple and opinionated logging library. plays well with aws lambda + cloudwatch.

Latest version **0.4.1** (published 2024-07-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-leveled-log-methods
pnpm add simple-leveled-log-methods
yarn add simple-leveled-log-methods
bun add simple-leveled-log-methods
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2024-07-27 |
| First published | 2019-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 34.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 0 |
| Author | ehmpathy |
| Maintainers | uladkasach |
| Keywords | log, logs, level, simple, filter, aws, lambda, cloudwatch, requestId |

## Links

- npm: https://www.npmjs.com/package/simple-leveled-log-methods
- Repository: https://github.com/ehmpathy/simple-leveled-log-methods
- Issues: https://github.com/ehmpathy/simple-leveled-log-methods/issues
- npm.io page: https://npm.io/package/simple-leveled-log-methods

## Dependencies (1)

- [type-fns](https://npm.io/package/type-fns.md) ^1.16.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.4.1 (latest) — 2024-07-27
- 0.4.0 — 2024-04-27
- 0.3.0 — 2022-10-27
- 0.2.2 — 2021-12-16
- 0.2.1 — 2021-12-13
- 0.2.0 — 2021-12-13
- 0.1.4 — 2021-03-24
- 0.1.2 — 2020-12-17
- 0.1.3 — 2020-12-17
- 0.1.1 — 2019-11-22
- 0.1.0 — 2019-11-22

## README

# simple-leveled-log-methods

a simple and opinionated logging library. plays well with aws lambda + cloudwatch.

# features

- distinguish different priorities of logs with standard levels
  - i.e., `log.debug`, `log.info`, `log.warn`, and `log.error`
- filter which levels of log to emit
  - i.e., choose based on environment whether to emit all logs or skip some of the logs
- utilizes `console.warn` and `console.log` under the hood
  - which ensures that the aws cloudwatch requestId is present on each log message automatically
- formats log metadata based on environment
  - i.e., stringify in local environments to reduce visual noise
  - i.e., don't stringify in aws-lambda environment for optimal cloudwatch parsing


# installation

```
npm install --save simple-leveled-log-methods
```

# usage

### init
```ts
// e.g., in `src/utils/log.ts
import { generateLogMethods } from 'simple-leveled-log-methods';

export const log = generateLogMethods();
```

### use in code
```ts
import { log } from '../utils/log';

log.error(`the sky is falling and we're loosing money!`, metadata); // use `.error` when you want someone to respond immediately, even if its 4am

log.warn(`this shouldn't be happening and should be looked at asap`, metadata); // use `.warn` when you want someone to look at it asap, but not wake up in the middle of the night

log.info(`we either want to or should keep track of this`, metadata); // use `.info` for anything we may be interested in knowing about

log.debug(`this will help debug if things go wrong`, metadata); // use this for any information that could help debug when things go wrong (e.g., request/response data)
```

---
_Source: https://npm.io/package/simple-leveled-log-methods · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
