
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
perfect-log
Advanced tools
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.
$ 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);
});
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>
Wrapper for console.log, use it like console.log.
PerfectLog.debug(1, 2, 3);
PerfectLog.debug(document.body);
PerfectLog.debug({x: 1, y: 2});
Wrapper for console.info, use it like console.info.
Wrapper for console.error, use it like console.error.
Allow log info be printed in devtool console.
Nothing would be printed in devtools console.
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. |
Add user defined data anywhere before report the log.
Add user defined data, another function signature.
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 levelmsg - Messagetime - UTC Timedata - Your own defined dataerror - Exist on level ERROR, representing the JavaScript Error objectplatform - An object about platform: browser is navigator.userAgentMIT Lisence.
FAQs
A front-end logging tools
The npm package perfect-log receives a total of 4 weekly downloads. As such, perfect-log popularity was classified as not popular.
We found that perfect-log demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.