# @capybaracode/logger

> A simple logger

Latest version **2.0.0** (published 2023-09-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @capybaracode/logger
pnpm add @capybaracode/logger
yarn add @capybaracode/logger
bun add @capybaracode/logger
```

## Health

**Score 30/100 (F)** — status: abandoned.

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2023-09-30 |
| First published | 2023-09-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | miqueiasbrs |
| Maintainers | miqueiasbrs |
| Keywords | logger, tools |

## Links

- npm: https://www.npmjs.com/package/@capybaracode/logger
- Repository: https://github.com/miqueiasbrs/logger
- Homepage: https://github.com/miqueiasbrs/logger#readme
- Issues: https://github.com/miqueiasbrs/logger/issues
- npm.io page: https://npm.io/package/@capybaracode/logger

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

- 2.0.0 (latest) — 2023-09-30
- 1.0.1 — 2023-09-30
- 1.0.0 — 2023-09-23

## README

# logger
Simple logging

## Usage
There are two ways to use the logger. The first is to use the default settings and the second is to use the custom settings. However, in both configurations, the logger module monitors the environment variable below.

|Environment|Default|Description                                                |
|-|-|-|
|LOG_LEVEL|info|Values accepted:<br/>***off*** - disabled<br/>***trace*** - all logs<br/>***debug*** - only debug, info, warn and error logs<br/>***info*** - only info, warn and error logs<br/>***warn*** - only the warn and error logs<br/>***error*** - only the error logs|
|LOG_FILE_DIR|logs|Path where the logs will be saved|
|LOG_FILE_MODE|off|Values accepted:<br/>***off*** - disabled<br/>***join*** - all logs together in a single file.<br/>***split*** - split logs into files|
|LOG_CONSOLE_MODE|on|Values accepted:<br/>***off*** - disabled<br/>***on*** - log enabled<br/>***local*** - pretty log for local terminal|




## Using
### Simple Use
```ts
import logger from '@letsdelivery/logger'

logger.trace('Log level trace')
// TRACE  {"event":"Log level trace","location":"file:///index.ts:2:"} 
logger.debug({ data: 'Log level debug' })
// DEBUG  {"event":{"data":"Log level debug"},"location":"file:///index.ts:3:"} 
logger.info(['log level info'])
// INFO  {"event":["log level info"],"location":"file:///index.ts:4:"} 
logger.warn(new Error('Warn'))
// WARN  {"event":{},"location":"file:///index.ts:5:"} 
logger.error(new URL('https://error.log'))
// ERROR  {"event":"https://error.log/","location":"file:///index.ts:6:"} 
```

### Using an Identifier
If you want to add an identifier to your log, you can set the requestId in the global log, from then on all new logs will be displayed with this identifier.

```ts
import logger from '@letsdelivery/logger'
logger.setRequestId('myrequestid')

logger.info(['log level info'])
// INFO myrequestid {"event":["log level info"],"location":"file:///index.ts:4:"}
```
for additional identifiers use metadata by key and value
```ts
import logger from '@letsdelivery/logger'
logger.setMetadata({ id: 'myrequestid' })

logger.info(['log level info'])
// INFO  {"event":["log level info"],"metadata":{"id":"myrequestid"},"location":"file:///index.ts:4:"}
```

---
_Source: https://npm.io/package/@capybaracode/logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
