@micromint1npm/quos-est-inventore v1.0.0
About @micromint1npm/quos-est-inventore
@micromint1npm/quos-est-inventore is a simple but flexible console logging library written in JavaScript with no dependencies. @micromint1npm/quos-est-inventore comes with common-sense builtin functions and defaults, and works right out of the box.
The package provides you with functions logm(), infom() and timem() to log messages to the console with standard formatting, as well as functions errm(), warnm() and throwm() for error handling. Also included is printm(), a simple wrapper for console.log() that returns an array of the arguments it's given.
Install
Install @micromint1npm/quos-est-inventore via NPM:
$ npm i @micromint1npm/quos-est-inventoreBasic Usage
Import:
Import the library in your code:
import @micromint1npm/quos-est-inventore from "@micromint1npm/quos-est-inventore";
// or
import { logm, errm, warnm, infom, timem, printm, throwm } from "@micromint1npm/quos-est-inventore";
@micromint1npm/quos-est-inventoremust be imported as an ES6 module.
Logging:
To log to the console:
import lm from "@micromint1npm/quos-est-inventore";
lm.logm("This is a log message");
lm.errm("Failed to connect to server");
lm.warnm("Request for /:user failed without authorization");
lm.infom("Server listening on port 3000");
lm.timem("Received a GET request for /");
lm.printm("A regular console.log() statement");
lm.throwm("Invalid configuration file");Output:
LOGM: This is a log message
ERRM: Failed to connect to server
WARNM: Request for /:user failed without authorization
INFOM: Server listening on port 3000
12/31/1999, 12:35:00 PM: Received a GET request for /
A regular console.log() statement
THROWM: Invalid configuration file
<stackTrace>
throw new Error(`${toString(errPrefix, errSeparator)} ${checkObject(errMessage)}`);
^
Error: THROWM: Invalid configuration file
at <stackTrace>Configuration
If dotenv is installed in the project, message defaults can be configured using a .env file:
### Prefix abbreviation
### (leave commented to not print a prefix abbreviation)
PREFIX_ABR = "APP"
### Separator between abbreviation and prefix
### (leave commented to use the default separator)
PREFIX_SEPARATOR = "-"
### Default message type prefixes
### (leave commented to use the default prefixes)
LOGM_PREFIX = "LOG"
ERRM_PREFIX = "ERROR"
THROWM_PREFIX = "ERROR-THROWN"
WARNM_PREFIX = "WARNING"
INFOM_PREFIX = "INFORMATION"
### Default separator between the prefix and message
### (leave commented to use the default separator)
MESSAGE_SEPARATOR = " ::"
### Default text for undefined messages
### (leave commented to use the default text)
LOG_MESSAGE = "a new message was logged"
ERROR_MESSAGE = "a new error has occurred"
WARN_MESSAGE = "a new warning was logged"
### Time message locale
### (leave commented to use "en-US")
### ex.: "en-US", "en-GB", "ko-KR", "ar-EG", "ja-JP-u-ca-japanese", etc.
TIMEM_LOCALE = "en-GB"If dotenv is not installed, @micromint1npm/quos-est-inventore will use the builtin defaults.
Documentation
logm()
Log a message to the console.
Parameters
messageany— the message content. (optional, defaultnull)prefixstring— the message prefix text. (optional, defaultnull)separatorstring— the separator string between the prefix and message text. (optional, defaultnull)
Examples
Code:
logm("logged message", "LOG", " |");Output:
LOG | logged messageReturns string — the full message string as {prefix}{separator} {message}.
errm()
Log an error to the console with the desired message.
Parameters
messageany— the error message content. (optional, defaultnull)errError— a target error to print to print. (optional, defaultnull)prefixstring— the error message prefix text. (optional, defaultnull)separatorstring— the separator string between the prefix and error message text. (optional, defaultnull)
Examples
Code:
errm("error message", new Error("error text"), "ERROR", " |");Output:
ERROR | error message
Error: error text
at <stackTrace>Returns string — the full error message string as {prefix}{separator} {message}.
warnm()
Log a warning message/error to the console with the desired message.
Parameters
messageany— the warning message content. (optional, defaultnull)errError— a target error to print. (optional, defaultnull)separatorstring— the separator string between the prefix and warning message text. (optional, defaultnull)
Examples
Code:
warnm("warning message", new Error("error text"), " |");Output:
WARNM | warning message
Error: error text
at <stackTrace>Returns string — the full warning message string as {prefix}{separator} {message}.
infom()
Log an info message/error to the console with the desired message.
Parameters
messageany— the info message content. (optional, defaultnull)errError— a target error to print. (optional, defaultnull)separatorstring— the separator string between the prefix and info message text. (optional, defaultnull)
Examples
Code:
infom("information message", undefined, " |");Output:
INFOM | information messageReturns string — the full info message string as {prefix}{separator} {message}.
timem()
Log a message/error to the console with the desired message and the current time.
Parameters
messageany— the message content. (optional, defaultnull)errError— a target error to print. (optional, defaultnull)separatorstring— the separator string between the prefix and message text. (optional, defaultnull)
Examples
Code:
timem("time-logged message", undefined, " |");Output:
12/31/1999, 12:35:00 PM | time-logged messageReturns string — the full message string as {prefix}{separator} {message}.
printm()
Print a message to the console (wrapper for console.log()).
Parameters
messageany— the message content.optionalParams...any— additional values or objects for output.
Examples
Code:
printm("printed message", "& additional output");Output:
printed message & additional outputReturns Array — an array of the arguments passed.
throwm()
Throw an error with the desired message.
Parameters
messageany— the error message content. (optional, defaultnull)errError— a target error to print. (optional, defaultnull)prefixstring— the error message prefix text. (optional, defaultnull)separatorstring— the separator string between the prefix and error message text. (optional, defaultnull)
Examples
Code:
throwm("thrown error message", new Error("error text"), "ERROR", " |");Output:
ERROR | thrown error message
<stackTrace>
throwm("thrown error message", new Error("error text"), "ERROR", " |");
^
Error: error text
at <stackTrace>Returns string — the full error message string as {prefix}{separator} {message}.
1 year ago