DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • What Is Test Pyramid: Getting Started With Test Automation Pyramid
  • Build a Simple Chat Server With gRPC in .Net Core
  • Apache Kafka vs. Message Queue: Trade-Offs, Integration, Migration
  • Working on an Unfamiliar Codebase
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Maintenance
  4. Starting Off With LogT

Starting Off With LogT

In this article, we will be talking about LogT and how to use it. This particular library is distinguished by its logs and by the importance of making its labels unique.

Daniel Onugha user avatar by
Daniel Onugha
·
May. 11, 23 · Tutorial
Like (4)
Save
Tweet
Share
3.22K Views

Join the DZone community and get the full member experience.

Join For Free

In researching loggers, I noticed this library LogT. This frontend tool is different from other logs with its unique feature of colorful labels.

The term log refers to a logarithmic function or a log statement in a program. In coding, a log statement is used to record events or messages during the execution of a program, usually for debugging.

LogT is a colorful logger made for browsers. You can use this logger for your front-end projects.

LogT is a colorful logger made for browsers. You can use this logger for your front-end projects.

Features of LogT

  • Colorful labels: This particular library is distinguished by its logs and by the importance of making its labels unique.
  • Library size: This library occupies only 1.46KB of gzip, which means that it is tiny.
  • Only logs equal to or above logLevel will be shown, showing log messages that are not visible to the logger.

The logs that the log level shows are stated below:

JavaScript
 
const logger = new LogT(0);
logger.warn("TAG", "warning message"); // Will not print anything to console
logger.info("TAG", "info message"); // Will not print anything to console
logger.debug("TAG", "debug message"); // Will not print anything to console
logger.silly("TAG", "silly message"); // Will not print anything to console

logger.showHidden(1); // Will print the warning message
logger.showHidden(2); // Will print the info message
logger.showHidden(5); // Will print the debug as well as silly message


As we can see in the code block above, the words that the logger will print to the console and the ones it won't print.

  • Hides less important log messages with its log level
  • To use the custom logger, you have to override the default console methods anywhere on the web page. This is where the read console method comes in readConsole().

In replacing the default console.error, console.warm, console.log, and console.info, implement the logtlogger.

Example:

JavaScript
 

const logger = new LogT(0);
logger.readConsole();

console.error(new Error("test error")); // will be same as logger.error('console', new Error('test error'));
console.warn("warn message"); // will be same as logger.warn('console', 'warn message');
console.log("info message"); // will be same as logger.info('console', 'info message');
console.log("log message"); // will be same as logger.debug('console', 'log message');


With the code blocks above, we can see how the custom logger logToverrides the default console.

  • Its detailed type information is built with typescript and its autocomplete format.
const logger

Installation

To install this library, run the following command below:

JavaScript
 
$ npm i logt -S


When you are done installing, go to your package.jason. This is how it would look, according to the version:

JavaScript
 
"logt": "^1.4.5",


Usage

This logger can be used for front-end projects, either as an ES6 module or directly in HTML. 

As an ES6 Module

ES6 is a feature of the ECMAScript 6 (ES6) language specification that provides a way to organize and share Javascript code in a modular way.

Create a file and name it logger.ts.

JavaScript
 

import LogT from "logt";

const LOG_TAG = "sample tag";
let logger;
if (process.env.NODE_ENV === "production") {
  logger = new LogT("error"); // or logger = new LogT("none");
} else {
  logger = new LogT("silly");
}

//To see the documentation for readConsole() for usage.
// logger.readConsole();

logger.error(LOG_TAG, new Error("example error"));


Usage in HTML

LogT is also used in HTML; you can see it in the code blocks below:

JavaScript
 

<script src="https://cdn.jsdelivr.net/gh/sidhantpanda/logt/dist/logt.min.js"></script>
<script>
  var LOG_TAG = 'sample tag';
  var logger = createLogger('error');

//To see the documentation for readConsole() for usage.
  // logger.readConsole();

  logger.error(LOG_TAG, new Error('example error'));
</script>


Documentation

Logger initialization: In computer programming, logger initialization refers to the process of setting up and configuring a logging module in your software application. The purpose of a logger is to log messages from the application, such as errors, warnings, and informational messages, which can be used for debugging, performance analysis, and auditing purposes. During the logger initialization process, you typically specify the logging level, output destination (such as a file, the console, or a remote server), and the format of the log messages.

The logger initialization in logT is stated in the code block below:

JavaScript
 

import LogT from "logt";

let logger;
// Available log levels -  -1 | 0 | 1 | 2 | 3 | 4 | 5 | 'none' | 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';

// noneLogger will print nothing
noneLogger = new LogT(-1); // or
noneLogger = new LogT("none");

// if included via HTML script
noneLogger = createLogger(-1); // or
noneLogger = createLogger("none");

// errorLogger will only error messages
errorLogger = new LogT(0); // or
errorLogger = new LogT("error");

// if included via HTML script
errorLogger = createLogger(0); // or
errorLogger = createLogger("error");

// sillyLogger will print all messages
sillyLogger = new LogT(5); // or
sillyLogger = new LogT("silly");

// if included via HTML script
sillyLogger = createLogger(5); // or
sillyLogger = createLogger("silly");


If any other value is supplied to the constructor, a default value of none is used.

Conclusion

In creating or building your colorful logger, this is the best library to use for your framework.

Debug (command)

Opinions expressed by DZone contributors are their own.

Trending

  • What Is Test Pyramid: Getting Started With Test Automation Pyramid
  • Build a Simple Chat Server With gRPC in .Net Core
  • Apache Kafka vs. Message Queue: Trade-Offs, Integration, Migration
  • Working on an Unfamiliar Codebase

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: