# @netease-yunxin/log-storage

> a log storage tool, support manual reporting

Latest version **1.0.5** (published 2021-06-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install @netease-yunxin/log-storage
pnpm add @netease-yunxin/log-storage
yarn add @netease-yunxin/log-storage
bun add @netease-yunxin/log-storage
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2021-06-01 |
| First published | 2021-05-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 83.4 KB |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| Author | mayingying |
| Maintainers | netease-yunxin |
| Keywords | log, storage, report |

## Links

- npm: https://www.npmjs.com/package/@netease-yunxin/log-storage
- npm.io page: https://npm.io/package/@netease-yunxin/log-storage

## Dependencies (9)

- [idb](https://npm.io/package/idb.md) ^5.0.7
- [core-js](https://npm.io/package/core-js.md) ^3.13.1
- [@babel/core](https://npm.io/package/@babel/core.md) ^7.14.3
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.14.0
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ^3.11.0
- [regenerator-runtime](https://npm.io/package/regenerator-runtime.md) ^0.13.7
- [@babel/runtime-corejs3](https://npm.io/package/@babel/runtime-corejs3.md) ^7.14.0
- [@babel/plugin-transform-classes](https://npm.io/package/@babel/plugin-transform-classes.md) ^7.14.4
- [@babel/plugin-transform-arrow-functions](https://npm.io/package/@babel/plugin-transform-arrow-functions.md) ^7.13.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

- 1.0.5 (latest) — 2021-06-01
- 1.0.4 — 2021-05-31
- 1.0.3 — 2021-05-31
- 1.0.2 — 2021-05-31
- 1.0.1 — 2021-05-31
- 1.0.0 — 2021-05-31

## README

## log-storage的是什么

一个基于 IndexedDB 的本地日志存储工具。

它不包含上传功能，由使用者定义日志的上传，这也保证了它的纯粹和轻量


## TODO

日志量变多后的一些问题

- 分表存储
- 分批查询

## 使用方式

```
const logger = new LogStorage('db_name')

// 打印日志
logger.log('log', '这是一条普通日志')
logger.log('warn', '这是一条警告')
logger.log('error', '这是一条错误')

const now = Date.now()
// 读取日志
logger.get({start: 0, end: now}).then(res => {
  console.log('获取到now之前的日志', res)
  logger.delete({start: 0, end: now}) // 删除日志
})
```
多业务场景
```
const imLogger = new LogStorage('db_im')
const wbLogger = new LogStorage('nim-wb')
const meetingLogger = new LogStorage('db_meeting')

imLogger.log('info', 'im业务的一条info日志')
wbLogger.log('warn', '白板业务的一条警告日志')
meetingLogger.log('error', '会议业务的一条错误日志')

const now = Date.now()
imLogger.get({start: 0, end: now}).then(res => console.log('获取IM业务日志'))
wbLogger.get({start: 0, end: now}).then(res => console.log('获取白板业务日志'))
meetingLogger.get({start: 0, end: now}).then(res => console.log('获取会议业务日志'))
```

### 注意事项

目前暂未实现数据库分表，数据量太大时查询/更新都会很慢，因此建议expire不要设置的太大，设置一个够用的最小值即可

## 为什么要写log-storage

- 将日志存储在用户本地，按需收集

## 开发流程

### 目录结构

```
./demo    测试页代码
./src     源码
./uml     uml时序图
```
### 开发中

执行 `npm run dev`
打开 `http://localhost:8090/demo/`调试

### 打包

`npm run build`后，`./dist/index.js`即为目标SDK文件

### 打包后调试

1. 在工程目录下起静态服务器， 假设端口是8091
2. 访问`http://localhost:8091/demo/`调试

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