# @basd/logger

> @basd/logger is a versatile and robust logging module for Node.js and the browser.

Latest version **0.0.5** (published 2023-10-24) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2023-10-24 |
| First published | 2023-07-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 34.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Basedwon |
| Maintainers | basedwon |
| Keywords | javascript, nodejs, library, logger, logging, winston, database-logging, console-logging, file-logging, log-management, error-logging, info-logging, debug-logging, log-levels |

## Links

- npm: https://www.npmjs.com/package/@basd/logger
- Repository: https://gitlab.com/frenware/core/basd/logger
- Homepage: https://gitlab.com/frenware/core/basd/logger#readme
- Issues: https://gitlab.com/frenware/core/basd/logger/issues
- npm.io page: https://npm.io/package/@basd/logger

## Dependencies (3)

- [winston](https://npm.io/package/winston.md) ^3.10.0
- [@basd/base](https://npm.io/package/@basd/base.md) ^0.0.7
- [winston-daily-rotate-file](https://npm.io/package/winston-daily-rotate-file.md) ^4.7.1

## 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.0.5 (latest) — 2023-10-24
- 0.0.4 — 2023-10-06
- 0.0.3 — 2023-09-23
- 0.0.2 — 2023-07-27
- 0.0.1 — 2023-07-27

## README

# @basd/logger

> the more you know — never forget

[![npm](https://img.shields.io/npm/v/@basd/logger?style=flat&logo=npm)](https://www.npmjs.com/package/@basd/logger)
[![pipeline](https://gitlab.com/frenware/core/basd/logger/badges/master/pipeline.svg)](https://gitlab.com/frenware/core/basd/logger/-/pipelines)
[![license](https://img.shields.io/npm/l/@basd/logger)](https://gitlab.com/frenware/core/basd/logger/-/blob/master/LICENSE)
[![downloads](https://img.shields.io/npm/dw/@basd/logger)](https://www.npmjs.com/package/@basd/logger) 

[![Gitlab](https://img.shields.io/badge/Gitlab%20-%20?logo=gitlab&color=%23383a40)](https://gitlab.com/frenware/core/basd/logger)
[![Twitter](https://img.shields.io/badge/@basdwon%20-%20?logo=twitter&color=%23383a40)](https://twitter.com/basdwon)
[![Discord](https://img.shields.io/badge/Basedwon%20-%20?logo=discord&color=%23383a40)](https://discordapp.com/users/basedwon)

`@basd/logger` is a versatile and robust logging module for Node.js and the browser. It is part of the [basd](https://gitlab.com/basedwon/basd) ecosystem of libraries and uses `@basd/base` for some of its core utilities. It supports logging directly to the console, to files, and to a specified database.

## Installation

```sh
npm install @basd/logger
```

## Usage

The logger library supports different logging levels (debug, info, warn, error, log) and can print to the console or write to a database.

```javascript
const Logger = require('@basd/logger')

const myLogger = new Logger()

myLogger.debug('This is a debug message')
myLogger.info('This is an info message')
myLogger.warn('This is a warning message')
myLogger.error('This is an error message')
myLogger.log('This is a generic log message')
```

### Logger Options

You can instantiate the logger with certain options:

```javascript
const myLogger = new Logger({
  db: myDatabaseInstance, // provide a database instance
  winston: true, // enable winston logging
})
```

### Database Logging

When provided a database instance during instantiation, the logger will write logs to the database:

```javascript
myLogger.print('debug', 'This is a debug message stored in the DB')
```

### Reading Logs

With the NodeLogger you can read the logs from the filesystem.

```javascript
const NodeLogger = require('@basd/logger')

const nodeLogger = new NodeLogger()

nodeLogger.list().then(console.log) // list all log files
nodeLogger.read().then(console.log) // read the latest log file
nodeLogger.read('2023-07-24').then(console.log) // read a specific log file by date
nodeLogger.read([new Date('2023-01-01'), new Date()]).then(console.log) // read all logs between two dates
```

## Documentation

- [API Reference](/docs/api.md)

## Tests

In order to run the test suite, simply clone the repository and install its dependencies:

```bash
git clone https://gitlab.com/frenware/core/basd/logger.git
cd basd
npm install
```

To run the tests:

```bash
npm test
```

## Contributing

Thank you! Please see our [contributing guidelines](/docs/contributing.md) for details.

## Donations

If you find this project useful and want to help support further development, please send us some coin. We greatly appreciate any and all contributions. Thank you!

**Bitcoin (BTC):**
```
1JUb1yNFH6wjGekRUW6Dfgyg4J4h6wKKdF
```

**Monero (XMR):**
```
46uV2fMZT3EWkBrGUgszJCcbqFqEvqrB4bZBJwsbx7yA8e2WBakXzJSUK8aqT4GoqERzbg4oKT2SiPeCgjzVH6VpSQ5y7KQ
```

## License

Logger is [MIT licensed](https://gitlab.com/frenware/core/basd/logger/-/blob/master/LICENSE).

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