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 🙏

© 2026 – Pkg Stats / Ryan Hefner

perfect-log

v0.0.2-beta.1

Published

A front-end logging tools

Downloads

23

Readme

Perfect Log

Build Status npm npm download times

中文

Overview

Provide a set of log tools and help to get rid of using console.log in the source code. Control the output between develop and production environment.

Also, it allows you to upload your log(including bussiness or unhandled error) to your own backend service, which you can analyze them or just push to some log manage system, like ELK.

This package is designed for browser end.

Installation

npm

$ npm i -S perfect-log

After installation, import it at the most beginning.

import PerfectLog from 'perfect-log';

// Do some configurations
PerfectLog.enableReport({
  url: 'url'
});

Then, you can use PerfectLog anywhere in your code.

import PerfectLog from 'perfect-log';

this.http.post('/url', {id: 1}).then(data => {
  PerfectLog.debug(data); 
});

Script

Directly download dist/perfect-log.js and include it in your page before any other scripts. Everything works.

<script src="perfect-log.js"></script>
<script src="other.js"></script>

API

PerfectLog.debug(...arg)

Wrapper for console.log, use it like console.log.

PerfectLog.debug(1, 2, 3);
PerfectLog.debug(document.body);
PerfectLog.debug({x: 1, y: 2});

PerfectLog.info(...arg)

Wrapper for console.info, use it like console.info.

PerfectLog.error(...arg)

Wrapper for console.error, use it like console.error.

PerfectLog.enableConsoleOutput()

Allow log info be printed in devtool console.

PerfectLog.disableConsoleOutput()

Nothing would be printed in devtools console.

PerfectLog.enableReport(options: object)

Enable the report module. According the options, log info would be sent to a backend service using POST.

PerfectLog.enableReport({
  url: 'http://some.host/received',
  level: 'INFO',
  data: {
    userId: 1
  },
  beforeSend: (log) => {
    log.version = log.data.version;
   	return log;     
  }
});

Details in options

| Field | Description | Default | | ----- | ------------------------------------------------------------ | --------- | | url | Backend service url, which can handle POST HTTP request, is necessary. | | | level | The least level should it report. Currently only 'DEBUG'/'INFO'/'ERROR' is allowed. For example, if set to 'INFO', only INFO and ERROR level would be sent to the backend. | 'ERROR' | | data | Any specified data you want to send to the backend along with the log. | | | beforeSend | Provide a function to transform log info schema into anything you want before sneding to backend. | | | sample | Expect a number between 0 and 1 or function. Math.random will be called and compare to sample number(greater than) to determine whether to report when you give a number. Or just call the sample function that return a boolean representing report or not. | |

PerfectLog.patchData(data: object)

Add user defined data anywhere before report the log.

PerfectLog.patchData(key: string, value: object)

Add user defined data, another function signature.

Log Info Schema

The data sent to backend is a JSON format defined below:

{
  "level": "INFO",
  "msg": "Uncaught ReferenceError: ppp is not defined",
  "time": "2018-04-12T13:00:37.365Z",
  "data": {
    "pluginVersion": "1.1.2",
    "userId": 1
  },
  "error": Error
  "platform": {
    "browser": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"
  }
}
  • level - The log level
  • msg - Message
  • time - UTC Time
  • data - Your own defined data
  • error - Exist on level ERROR, representing the JavaScript Error object
  • platform - An object about platform: browser is navigator.userAgent

Lisence

MIT Lisence.