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

loglevel-local-storage

v1.1.3

Published

NPM plugin for JS logger loglevel which will log all messages to localStorage

Downloads

132

Readme

NPM plugin for JS logger loglevel which will log all messages to localStorage

Features

  • Messages put on a stack, stack is stored entirely.
  • Max stack size for logs to be stored can be set.
  • You can specify prefix function which would dynamically add prefix for all log messages (app name, current user, etc.).

Installation

  • Using npm = npm install loglevel-local-storage

Configuration

import loglevel and loglevel-localStorage scripts to your file first. Then configure the plugin:

##loglevelLocalStorage(logger, options) Extend loglevel with new plugin which will send log information to the log-sever

| Param | Type | Description | | ----- | ---- | ----------- | | logger | object | loglevel instance to be extended | | options | object | | | [options.storeKey='loglevelLocalStorage'] | string | Name for the store in localStorage. | | [options.maxLogStackSize=100] | number | Max stack size to store. | | [options.callOriginal=false] | Bool | If set to true - original loglevel method for logging would be called | | [options.prefix=null] | string | function | Prefix for all log messages. Either string or function wich should return string and accept log severity and message as parameters | | [options.level=logger.levels.WARN] | string | number | Log level. Either string or number, See loglevel.setLevel. | | [options.persistentLog=false] | Bool | If set to true - persist log entries between instantiations of the same log stack. |

Example

                                                
var debuglog = require('loglevel'); // import debuglog from 'loglevel';
var loglevelLocalStorage = require('../loglevel-localStorage.js'); // import loglevelLocalStorage from 'loglevel-local-storage';
 
debuglog.setLevel(1);
 
loglevelLocalStorage(debuglog, {
    level: 'info',
    prefix: function (logSev /* , ...message */) {
        var message = Array.prototype.slice.call(arguments, 1);
        return '[' + new Date().toISOString() + '] ' + logSev + ': ' + message.join(' ');
    },
    callOriginal: true,
    maxLogStackSize: 10
});
 
var foo = function () {
    var test = "123";
    debuglog.info("test", test);
};
 
foo();
 
// output console (callOriginal = true):  
// test 123
// output localStorage (see prefix function above):
// [2016-07-19T15:39:18.110Z] info: test 123
 
// ES6 example:
import debuglog from 'loglevel';
import loglevelLocalStorage from 'loglevel-local-storage';

debuglog.setLevel("DEBUG");
loglevelLocalStorage(debuglog, {
    level: 'info',
    prefix(logSev, ...args) {
        // Stringify for storage in localStorage
        const newArgs = args.map(arg => ((typeof arg === 'object' && !(arg instanceof Date)) ? JSON.stringify(arg) : arg));
        return `[${new Date().toISOString()}] ${logSev}: ${newArgs.join(' ')}`;
    },
    callOriginal: true,
    maxLogStackSize: 10,
});
 

Another Prefix Example

You may keep the log in a JSON format to be able to parse later

    ...
    prefix: function (logLevel) {
        var message = Array.prototype.slice.call(arguments, 1);
        return [new Date(), logLevel, message];
    }
    ...