Socket
Socket
Sign inDemoInstall

localstorage-logger

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-logger


Version published
Maintainers
1
Created

Readme

Source

localstorage-logger

Logging library for writing to and exporting from local storage.

What is it?

This JavaScript library provides a mechanism to log to local storage and export the most recent entries. It will overwrite the oldest entries when writing a new entry if adding the entry makes the log bigger than maxLogSizeInBytes.

Motivation

At the time of writing, all the libraries we could find that provide logging or queuing in local storage used a single storage key. This means that they had to serialize the whole log/queue on any modification. This resulted in worse performance as the log got bigger.

Instead of a single key, we use many keys. Therefore, the cost of serialization on each modification is much lower than in the other libraries we found. However, this means we lose atomicity when making modifications to the underlying data structure. JavaScript is single-threaded so this doesn't pose much of a problem but theoretically a browser crash at exactly the right moment could corrupt the underlying data structure built on top of local storage.

Usage

This is how you can use the logging functionality:

import createLog from 'localstorage-logger';

const log = createLog({
  logName: 'my-app-log-name',
  maxLogSizeInBytes: 500 * 1024 // 500KB
});

// Log something
// debug | info | warn | error
log.info('something', {
  foo: 'bar'
}, 42);

// Export the log entries
const logEntries = log.exportToArray();

Keywords

FAQs

Last updated on 13 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc