1.0.0 • Published 2 years ago

terminali v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

TERMINALI

INSTALL BADGE LICENSE BADGE VERSION BADGE

Still using console.log in 2022?! With Terminali, you can attach timestamps to your logs, organize your logs into different categories (levels) with their own unique colors and more!

TERMINALI PREVIEW IMAGE

[ 9:33:34.291 AM ]      [ +3ms ]        Initial log.
[ 9:33:35.609 AM ]      [ +1s +318ms ]  Sent a {COIN} in return for a {EGG} to 89211452::-_67.
[ 9:33:36.309 AM ]      [ +700ms ]      {COIN} returned with a code of "0".
[ 9:33:36.607 AM ]      [ +298ms ]      Sent a {COIN} to 67671093::0YqU.
[ 9:33:37.594 AM ]      [ +987ms ]      Doing a security check...
[ 9:33:39.583 AM ]      [ +1s +989ms ]  Security check results: an invalid {SPOON} is in possession.
[ 9:33:40.376 AM ]      [ +793ms ]      Sent a {BISCUIT} in return for a {EGG} to 09826791::Oo2W.
[ 9:33:40.565 AM ]      [ +189ms ]      Sent a {SPOON} to 09278912::9i1Z.
[ 9:33:42.492 AM ]      [ +1s +927ms ]  {SPOON} returned with a code of "1". Node has terminated.

FEATURES

Features include:

  • Ability to have each log show the exact date and time when it was sent to the console.
  • Ability to have relative timestamps in your logs. These include timestamps relative to when the previous message was logged to the console.
  • Being able to add or remove any of these types of timestamps from your logs.
  • You can also log messages to up to 6 different levels of importance all with their own unique colors!
  • As well as that, you can even create custom levels with whatever color you desire!

BASIC USAGE

First, import the Terminal class from Terminali.

import Terminal from "terminali";

Next up is to create your terminal.

const terminal = new Terminal({
	levels: [
		// Levels...
	]
});

Right inside of levels is where you are free to define your different levels/categories that you can log to. But to save time, you can import a bunch of preset levels like this:

import Terminal, { advancedLevels } from "terminali";

const terminal = new Terminal({ levels: advancedLevels });

NOTE: If you want to learn how to create custom levels, continue reading here.

To start logging things, do so like this:

terminal.log.trace("Initial log.");

trace in this case is the name of one of the preset levels that you can log to. If you were logging an error, for example, you can use the error level.

terminal.log.error("Something happened.");

Output:

OUTPUT IMAGE

[ 9:40:11.146 PM ]      [ +1ms ]        Initial log.
[ 9:40:11.298 PM ]      [ +152ms ]      Something happened.

Notice how the second log is highlighted in red as it is an error.

CUSTOMIZABILITY

Upon creating a new instance of the Terminal class, you can turn on and off a bunch of options that determine how logs are to be displayed in the terminal. In the following example, there are three different instances of the Terminal class all with different settings.

Code:

import Terminal, { advancedLevels } from "terminali";

const t1 = new Terminal({
	levels: advancedLevels
});

const t2 = new Terminal({
	levels: advancedLevels,
	showDate: true,
	showLevelName: true,
	showTimestampRelativeToLastLog: false,
	use24HourClock: true
});

const t3 = new Terminal({
	levels: advancedLevels,
	showArrow: true,
	showRelativeTimestamp: true,
	showTimestamp: false
});

t1.log.warn("The fox is coming...");
t2.log.warn("The fox is coming...");
t3.log.warn("The fox is coming...");

Output:

OUTPUT IMAGE

[ 10:16:34.72 PM ]      [ +7ms ]        The fox is coming...
[ WARN ]        [ 28d/3m/2022y | 22:16:34.281 ] The fox is coming...
[ 217ms | +217ms ] >>           The fox is coming...

CUSTOM LEVELS

Creating custom levels is as simple as it gets! In the following example, there are two additional custom levels, alongside the preset levels, called weather and victory.

Code:

import Terminal, { advancedLevels } from "terminali";

const terminal = new Terminal({
	showLevelName: true,

	levels: [
		...advancedLevels,
		{
			color: ["bgGreen", "white", "bold"],
			isError: false,
			name: "victory"
		},
		{
			color: ["cyan", "bold", "underline"],
			isError: false,
			name: "weather"
		}
	]
});

terminal.log.weather("Today will be 280°C (about the same as an oven).");
terminal.log.victory("The octopus has won.");

Output:

OUTPUT IMAGE

[ WEATHER ]     [ 3:40:57.60 AM ]       [ +2ms ]        Today will be 280°C (about the same as an oven).
[ VICTORY ]     [ 3:40:57.441 AM ]      [ +381ms ]      The octopus has won.

CONTRIBUTING

Please help improve this package by contributing. If you have a feature suggestion or have found a nasty bug in the code, create an issue here. Pull requests are also much appreciated. You are free to create one here.

As of now, this NPM package is still being developed on. More features are coming soon. Thanks for your patience.


LICENSE

MIT License

Copyright (c) 2022 Benjalaazshah

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.