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

logmorphic

v0.0.5

Published

isomorphic logger library supports saving log to browser storage

Downloads

9

Readme

Build Status Testling

logmorphic

isomorphic logger. you can also save to localStorage.

API

// `<script src='node_modules/logmorphic/index.js></script>` in browser
// or
// `npm install logmorphic` in node

var Logger = Logger || require('logmorphic').Logger;

var format = '[%date] %category %level (%file) - %message';
var appLogger = Logger.getLogger('APP', {
  loglevel: 'DEBUG',
  format: format,
  storage: {
    type: 'localStorage',
    key: 'log',
    limit: 1000 * 10 // 10K
  }
});

var a = { hoge: 100 };
appLogger.trace('the value of "hoge" at', a, 'is', 100);
appLogger.debug('the value of "hoge" at', a, 'is', 100);
appLogger.info('the value of "hoge" at', a, 'is', 100);
appLogger.warn('the value of "hoge" at', a, 'is', 100);
appLogger.error('the value of "hoge" at', a, 'is', 100);
appLogger.fatal('the value of "hoge" at', a, 'is', 100);

output (no TRACE because of loglevel settings to DEBUG)

$ node sample/sample.js
[2015-03-06T07:11:00.036Z] APP DEBUG (sample.js:16) - the value of "hoge" at {"hoge":100} is 100
[2015-03-06T07:11:00.038Z] APP INFO (sample.js:17) - the value of "hoge" at {"hoge":100} is 100
[2015-03-06T07:11:00.039Z] APP WARN (sample.js:18) - the value of "hoge" at {"hoge":100} is 100
[2015-03-06T07:11:00.039Z] APP ERROR (sample.js:19) - the value of "hoge" at {"hoge":100} is 100
[2015-03-06T07:11:00.040Z] APP FATAL (sample.js:20) - the value of "hoge" at {"hoge":100} is 100
  • TRACE/DEBUG/INFO log outs to STDOUT
  • WANR/ERROR/FATAL log outs to STDERROR

or open sample/index.html in browser

format

format has these place-holder

  • %date: current date time with date.toISOString(). change format with override Logger.prototype._date.
  • %level: level of log name in upper case (DEBUG, INFO, WARN, ERROR, FATAL).
  • %category: set by getLogger() first arg.
  • %message: given args to logger. string or serialized number/object/functions.
  • %file: file name and line number, but has performace consideration.

caution: %file is build by stack trace from Error object because JS doesn't has API for that. this is heavy operation, so consider carefully in production environment.

using file only in develop environment and replace format in production are recomended. if you wanna get more info in production, use logger.trace() or out the given Error instance, which has stack property.

localStorage

save logs to localStorage on browser by specifying storage option. saving are non blocking using setTimeout.

  • type: storage type, default to 'localStorage' and supported that only now.
  • key: key of storage column, default to 'logStorage'. keep all log in 1 column of storage for avoid occupy storage, and save order of log.
  • limit: limit for save to storage, defalut to 20K. remove as FIFO

install & commands

$ npm install logmorphic

you can call all build task from npm run-scripts. (actually it calls gulp task, please see package.json scripts directive.

$ npm install
$ npm test
$ npm run lint

TypeScript support

use logmorphic.d.ts for typescript.

FAQ

how to save logs to the file ?

logmorphic currentry doesn't support logging to file. because system usually running with process management tools like supervisord, forever, monit etc they usually have logging support which gets log from STDOUT/STDERROR, and saves to file, logserver, fluentd etc, and also log-rotation, log-versioning, log-destroy or so. just use that.

CHANGELOG

  • v0.0.5: update dependencies and fix for new .eslintrc

License

MIT: http://jxck.mit-license.org/