Deno.js Logger Utility Module to Print Log Messages and Write Logs Messages to a Text File Using TypeScript Full Project For Beginners




A service to help log messages in the console or write logs to a file.

Table of Contents

API Documentation

You can find the API documentation here

Creating a Logger

To use a logger, you must first create one:

import { ConsoleLogger } from "";
import { FileLogger } from "";

const consoleLogger = new ConsoleLogger();
const fileLogger = new FileLogger({ file: "file.log" }); // NOTE: `file` is request here, it's the filename which logging will be sent to

Using a Logger

Both logger types provide the same API methods. The only difference is, one logs to the console, one logs to a file.

Within the constructor, you can pass in tag_string and tag_string_fns. Both of these allow you to pass in custom data to the message if you wish to:

const logger = new ConsoleLogger({ // or FileLogger
  tag_string: "{name} | {location} |",
  tag_string_fns: {
    name() {
      return "Drashland";
    location() {
      return "The Moon";

Then calling"Hello") (or any other method) will display [INFO] Drashland | The Moon | Hello

Leave a Reply