A fast, flexible JSON logger.
The package.json has two configurations related to Node.js installations:
main
: points to the minified version compiled for v6.0.0 and above.module
: points to the src files. Module field details.
The index.js points to the minified version compiled for v6.0.0 and above.
npm install --save perj
Use the dist files or bundle from src.
Type | Size | CDN |
---|---|---|
gzipped | https://unpkg.com/perj/dist/perj.min.js.gz | |
minified | https://unpkg.com/perj/dist/perj.min.js | |
full (source map) | https://unpkg.com/perj/dist/perj.js |
See Unpkg for fixed version options.
- Designed to be integrated (DIY) ✔️
- Cross platform (Node.js and Browser) ✔️
- Flexible log and additional property options ✔️
- Fast ✔️
- No dependencies.
- Flexible API (change almost everything).
- Flexible log methods:
- Log items can be any number in any order of any type.
- The first string is nested under the 'msg' key:
- First string includes a string argument or an Error message.
- Additional string arguments are nested under the data key.
- Objects are nested under the 'data' key as an object or array of objects.
- Repeated string top level properties become hierarchical.
- Examples to get you started.
The following example adds ver
, name
, host
, pid
and file
top level property to the log output:
import Perj from 'perj';
import os from 'os';
import path from 'path';
// Customize the variables below as needed. They are not required.
const ver = 1;
const name = 'QuickStart';
const host = os.hostname();
const pid = process.pid;
const file = path.basename(import.meta.url, '.js');
const log = new Perj({ ver, name, host, pid, file });
log.info('the quick brown fox jumps over the lazy dog');
/*
The following string is sent to standard out:
{"level":"info","lvl":30,"ver":1,"name":"QuickStart","host":"Dev","pid":233241,"file":"quick-start","time":1526102959677,"msg":"the quick brown fox jumps over the lazy dog","data":""}
*/
The following example adds ver
, name
, and host
top level property to the log entries:
import Perj from "https://unpkg.com/perj/dist/perj.js"
// Customize the variables below as needed. They are not required.
const ver = 1;
const name = "QuickStart";
const host = location.hostname;
const log = new Perj({ ver, name, host });
log.info("the quick brown fox jumps over the lazy dog");
/*
The following string is sent to the console:
{"level":"info","lvl":30,"ver":1,"name":"QuickStart","host":"http://Dev","time":1526103303019,"msg":"the quick brown fox jumps over the lazy dog","data":""}
*/
For full documentation see the Wiki.
I'm Grant Carthew, a technologist from Queensland, Australia, with a passion for coding. I delve into personal projects and develop custom solutions when the existing tools fall short.
This repository hosts my custom logging solution, created because I couldn't find a logging package that met my needs.
All my open-source work is crafted in my own time, as a contribution to the community that has supported me.
If my projects have been useful to you and you'd like to express your appreciation or support, please consider joining me on Patreon. Your support helps sustain and grow these initiatives!
See my other projects on NPM.
This project only exists because it is standing on the shoulders of GIANTS.
Special thanks to the guys working on pino being:
A lot of the inspiration for perj
came from the pino package.
Not to mention the other packages and resources used to help develop on the Node.js platform.
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D