npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

indexeddb-logger

v1.0.4

Published

一个使用 IndexedDB 的简单日志记录器

Downloads

2

Readme

IndexedDB Logger

IndexedDB Logger 是一个使用 IndexedDB 存储日志记录的 JavaScript 类。它可以方便地在浏览器中记录和管理日志,适用于需要持久化日志数据的前端应用程序。

功能

  • 使用 IndexedDB 存储日志数据
  • 支持记录日志条目,包括操作类型和详细信息
  • 支持查询所有日志条目
  • 支持根据 ID 查询特定日志条目
  • 支持清空所有日志
  • 支持将日志导出为 JSON 文件

安装

你可以通过 npm 安装该包:

npm install indexeddb-logger

使用方法

导入并创建 Logger 实例

import { IndexedDBLogger } from 'indexeddb-logger';

// 创建一个新的日志记录器实例
const loggerInstance = new IndexedDBLogger({
  dbName: 'MyLoggerDB',
  storeName: 'myLogs',
  version: 1
});

记录日志

loggerInstance.log('userAction', { name:"Bob", age:99 });

获取所有日志

loggerInstance.getLogs((logs) => {
  console.log('All logs:', logs);
});

根据 ID 查询日志

const logId = 'someUniqueId';
loggerInstance.findLogById(logId, (log) => {
  console.log('Log with ID:', logId, log);
});

清空所有日志

loggerInstance.clearLogs();
console.log('All logs cleared');

导出日志为 JSON 文件

loggerInstance.exportToJson().then(() => {
  console.log('Logs exported to JSON file');
});

配置选项

创建 IndexedDBLogger 实例时可以传递以下配置选项:

  • dbName (string): IndexedDB 数据库的名称,默认为 'LoggerDB'
  • storeName (string): 数据存储对象的名称,默认为 'logs'
  • version (number): IndexedDB 数据库的版本,默认为 1

示例

下面是一个完整的使用示例:

import { IndexedDBLogger } from 'indexeddb-logger';

// 创建一个新的日志记录器实例
const loggerInstance = new IndexedDBLogger({
  dbName: 'MyLoggerDB',
  storeName: 'myLogs',
  version: 1
});

// 记录一个日志条目
loggerInstance.log('userAction', { name:"Bob", age:99 });

// 获取所有日志条目
loggerInstance.getLogs((logs) => {
  console.log('All logs:', logs);
});

// 根据 ID 查询日志条目
const logId = 'someUniqueId';
loggerInstance.findLogById(logId, (log) => {
  console.log('Log with ID:', logId, log);
});

// 清空所有日志条目
loggerInstance.clearLogs();
console.log('All logs cleared');

// 导出日志为 JSON 文件
loggerInstance.exportToJson().then(() => {
  console.log('Logs exported to JSON file');
});

贡献

欢迎提问、反馈和贡献代码。如果你发现了 Bug 或有改进建议,请提交 Issue 或 Pull Request。

许可证

此项目使用 MIT 许可证。详见 LICENSE 文件。