hardlog
v4.0.4
Published
A NodeJS library for logging to the console and keeping a hard record of whatever is logged to the console. Forget console.log(), forever!
Downloads
10
Readme
HardLog
A NodeJS library for logging to the console and keeping a hard record of whatever is logged to the console. Forget console.log(), forever!
Installation
Use the following command to install HardLog via NPM:
npm i hardlog --save
Usage
Follow this syntax while using hardlog:
var logs = require('hardlog');
// logs.init() must be used before any other hardlog method
logs.init("Your Name", "Version Number of your software");
// write hardlog code below
logs.write("Write anything to hardlog here!")
Console Output:
hardLog v3.0.0 initialized. Created by Ray Voice and Anna Voice!
Follow them: @RayShortHead @AnnaShortHead --2021-06-17T00:25:05.361Z
Write anything to hardlog here! --2021-06-17T00:25:05.362Z
./LogFile.txt Output:
hardLog v3.0.0 initialized. Created by Ray Voice and Anna Voice!
Follow them: @RayShortHead @AnnaShortHead --2021-06-17T00:25:05.361Z
Write anything to hardlog here! --2021-06-17T00:25:05.362Z
.write(logString1, logString2, ...)
: Used to logs something to both the hardlog file and to the stdout console..shadow(logString1, logString2, ...)
: Used to log something to the hardlog file only, no console output..log(logString1, logString2, ...)
: Same as console.log(), but chainable..generalLogsDir = logsDir
: to change the default logs storage directory to logsDir. (Not chainable).generalLogFile = logFile
: to change the default logs file to logFile. (Not chainable).logFileExists(fileURL)
: to check if the logs file exists..logsHash()
: to get the sha256-hex hash of the entire logs file..closeLogs()
: to close-off the logs file, writing a hash of the logs file it the very last line. If someone tempers with the logs file, this adds a layer of protection to it. This method is (Not chainable) on purpose..value
: to get the value of the chainable method. (Not chainable itself).setValue
: to set the internal Value of hardlog. The setting of value can be done withhardlog.value = "something"
, but using.setValue
allows chains.Comming Soon: Verify hash, alter-chrome integration, etc.
Example
Most methods in hardlog
are either "chainable" or "terminal". Hence we can write the code in a chain unless we use a "terminal" prop or method.
var logs = require('hardlog');
logs.init("Ray Voice", "1.0.3");
logs
.write("First HardLog")
.shadow("Write anything to hardlog here, without Terminal dispay!")
.closeLogs(); // Must write this at the very last hardlog
Tips
- Use the
chalk
library to color strings and then pass them to hardlog. - HardLogs are time-stamped.
- Avoid using
console.log
, instead usehardlog.log()
. - Don't pass more than a single argument to
hardlog.write()
orhardlog.shadow()
. - Use
.closeLogs()
for an added layer of security, in case someone tampers with the log file.
LICENSE
MIT License
Copyright (c) 2021 Ray Voice
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.