nisshi
v1.0.2
Published
A very fancy logger for JavaScript
Downloads
219
Readme
nisshi for JavaScript
A very fancy logger library for JavaScript.
Navigation
Installation
npm
Install nisshi on npm:
npm i --save nisshi
then import in JavaScript:
import nisshi from 'nisshi';
From file
Download the minified JavaScript file:
wget https://codeberg.org/daysant/nisshi/raw/branch/javascript/nisshi.min.js
then import in JavaScript:
import nisshi from './nisshi.min.js'
Usage
nisshi supports various levels, toggles, and file logging.
Basic logging functions
nisshi comes with five levels of logging:
nisshi.info("Lorem ipsum dolor sit amet");
nisshi.trace(`OwO, what's ${var}?`);
nisshi.debug("A thing happened.");
nisshi.warn("JavaScript undefined jumpscare!!");
nisshi.error("Houston, we have a problem.");
nisshi.fatal("I just sharted my pants");
Fatal messages can also be supplied with an exit code.
nisshi.fatal("Segmentation fault", 139);
You can also add newlines to seperate messages:
nisshi.newline();
Multiline messages are also supported.
nisshi.info(
`Shikanoko tokotoko,
arawaru nokonoko,
tsunotsuno pyokopyoko
mitame wa onya noko?`
);
Setting different logging levels
You can set a logging level with the level
setter/getter:
nisshi.info("Now you see me");
nisshi.level.info = false;
nisshi.info("Now you dont");
This also works with newlines:
nisshi.level.newline = false;
nisshi.newline(); // won't appear
They can be retrieved by simply stating the setter/getter:
if (!nisshi.level.debug) {
nisshi.warn("Debug statements are disabled");
}
Logging to a file
nisshi can log to files. You can set it with the file
setter/getter:
nisshi.file = "program.log"
and retrieved by stating it:
if (nisshi.file) {
nisshi.info("Logging path is set")
}
The path can be changed mid-program.
nisshi.file = "first.log"
nisshi.info("File A")
nisshi.file = "second.log"
nisshi.info("File B")
Logging to a file can be disabled all together by setting it to false.
nisshi.file = false
Can be useful if you want seperate logs for different parts of the same file.
Note File logging only works in Node, as the browser does not support
fs
.
Contributing
nisshi is free to modify and use in almost every case (see the license). This means you can contribute towards nisshi.
If you want to see a feature added or find a bug, check out the (main branch)[https://codeberg.org/daysant/nisshi/src/branch/main] and open an issue.
Or you can clone nisshi directly via Git:
git clone https://codeberg.org/daysant/nisshi/src/branch/main
Running tests
Make sure to write and run tests before committing code. Tests can be run with:
npm i # to get mocha
npm run test
Changelog
1.0.2
- remove the random npm installer that was there + proper linting
1.0.1
- Initial release
- The PATCH is
1
as opposed to0
due to issues with npm's immutable versioning policy (due to accidentally publishing a broken package that was unpublished)
Credits
nisshi is created by daysant (Codeberg).
This library is licensed under the daysant license v2.