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!

Usage no npm install needed!

<script type="module">
  import hardlog from 'https://cdn.skypack.dev/hardlog';
</script>

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
  1. .write(logString1, logString2, ...): Used to logs something to both the hardlog file and to the stdout console.

  2. .shadow(logString1, logString2, ...): Used to log something to the hardlog file only, no console output.

  3. .log(logString1, logString2, ...): Same as console.log(), but chainable.

  4. .generalLogsDir = logsDir: to change the default logs storage directory to logsDir. (Not chainable)

  5. .generalLogFile = logFile: to change the default logs file to logFile. (Not chainable)

  6. .logFileExists(fileURL): to check if the logs file exists.

  7. .logsHash(): to get the sha256-hex hash of the entire logs file.

  8. .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.

  9. .value: to get the value of the chainable method. (Not chainable itself)

  10. .setValue: to set the internal Value of hardlog. The setting of value can be done with hardlog.value = "something", but using .setValue allows chains.

  11. 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

  1. Use the chalk library to color strings and then pass them to hardlog.
  2. HardLogs are time-stamped.
  3. Avoid using console.log, instead use hardlog.log().
  4. Don't pass more than a single argument to hardlog.write() or hardlog.shadow().
  5. 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.