# indexdb-log

> A front-end log tool based on IndexDB

Latest version **1.0.12** (published 2023-04-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install indexdb-log
pnpm add indexdb-log
yarn add indexdb-log
bun add indexdb-log
```

## 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 | 1.0.12 |
| Published | 2023-04-18 |
| First published | 2022-08-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jianqiaohu |

## Links

- npm: https://www.npmjs.com/package/indexdb-log
- Repository: git@code.autox.ds:infra-fe/indexdb-log
- npm.io page: https://npm.io/package/indexdb-log

## Dependencies (2)

- [idb](https://npm.io/package/idb.md) ^7.0.2
- [file-saver](https://npm.io/package/file-saver.md) ^2.0.5

## Recent versions

- 1.0.12 (latest) — 2023-04-18
- 1.0.11 — 2022-09-08
- 1.0.10 — 2022-09-08
- 1.0.9 — 2022-09-08
- 1.0.8 — 2022-09-08
- 1.0.7 — 2022-09-08
- 1.0.6 — 2022-09-08
- 1.0.5 — 2022-09-08
- 1.0.4 — 2022-08-20
- 1.0.3 — 2022-08-20
- 1.0.2 — 2022-08-20
- 1.0.1 — 2022-08-20
- 1.0.0 — 2022-08-20

## README

# indexdb-log


This is a small logger implemented with index-db, originally based on [idb](https://github.com/jakearchibald/idb).

## Install
```sh
npm install indexdb-log
```

## Usage
### Set log
```js
import  IDBLog from 'indexdb-log'

const logger = new IDBLog(config)

logger.setLog('ERROR', { hello: 'world' })

// Same as logger.setLog('INFO', { hello: 'world' })
logger.info({ hello: 'world' })

// Same as logger.setLog('ERROR', { hello: 'world' })
logger.error({ hello: 'world' })

// Same as logger.setLog('WARN', { hello: 'world' })
logger.warn({ hello: 'world' })

```

### Create logger config
| Name               | Description                 | Type | Default
| ------------------ |:-----------------------------------------:|:----:|:---|
| dbName             | The name of indexdb database.                    | string | `log-store`
| logStoreName       | The name of log store in a database.                 |  string | `logs`
| metaStoreName      | The name of meta data store in a database.                              | string | `meta`
| countKey      | The name of key which store logs counts.                              | string | `log-count`
| dbVersion      | Version of database.                              | number | 1
| exclude      |  A function to determine whether set a log or not, and return a boolean value.                             | function | `() => false`
| duration      | The number of seconds to keep logs, the expired logs will be dropped.                 | number | 2 days (60 * 1000 * 60 * 24 * 2)
| maxCount      |  Max counts of logs. Oldest logs will be dropped when reached max count.                              | number | 40 thousand
| consoleLog      | Print console log or not when set log                              | boolean | `false`

### Save log files

```react
<button
    onClick={() => logger.saveLogFile(config)}
>
    download logs
</button>
```

### Save logs config
| Name               | Description                 | Type | Default
| ------------------ |:-----------------------------------------:|:----:|:---|
| title             | The name of log file.                    | string | `Logs${CurrentTimestamp}.txt`
| genLog       | A function to create log files format.                 |  function |

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