You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

localstorage-logger

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

localstorage-logger

A rolling logger that logs to local storage

0.1.1
latest
Source
npm
Version published
Weekly downloads
201
-0.99%
Maintainers
1
Weekly downloads
 
Created
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

typescript

FAQs

Package 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