Git Product home page Git Product logo

logger's Introduction

About

An informative console logger for Node.js.

Installation

npm i @wizo06/logger

Quick start

Filename test.js with content:

const { Logger } = require("@wizo06/logger");
const logger = new Logger();

logger.info(`Hello, World!`);
logger.success("Hello, World!");
logger.debug("Hello, World!");
logger.warn("Hello, World!");
logger.error("Hello, World!");
logger.info({ foo: "bar" });

Output:

$ node test.js
[2022.04.19|23:54:07|UTC-04:00] [INFO] Hello, World!
[2022.04.19|23:54:07|UTC-04:00] [SUCCESS] Hello, World!
[2022.04.19|23:54:07|UTC-04:00] [DEBUG] Hello, World!
[2022.04.19|23:54:07|UTC-04:00] [WARN] Hello, World!
[2022.04.19|23:54:07|UTC-04:00] [ERROR] Hello, World!
[2022.04.19|23:54:07|UTC-04:00] [INFO] { foo: 'bar' }

Configuration

By default, the constructor initializes the properties with these values:

const { Logger } = require("@wizo06/logger");
const logger = new Logger({
  printHostname = false, 
  printUNIXTimestamp = false, 
  printHumanReadableTimestamp = true, 
  stackDepth = 4, 
  printFileName = false, 
  printFunctionName = true,
  printLineNumber = true, 
  printLogLevel = true 
});

logger.info(`Hello, World!`);
logger.success("Hello, World!");
logger.debug("Hello, World!");
logger.warn("Hello, World!");
logger.error("Hello, World!");
logger.info({ foo: "bar" });

Output:

$ node test.js
[hanabira] [1650427853790|2022.04.20|00:10:53|UTC-04:00] [test.js:12] [INFO] Hello, World!
[hanabira] [1650427853793|2022.04.20|00:10:53|UTC-04:00] [test.js:13] [SUCCESS] Hello, World!
[hanabira] [1650427853794|2022.04.20|00:10:53|UTC-04:00] [test.js:14] [DEBUG] Hello, World!
[hanabira] [1650427853794|2022.04.20|00:10:53|UTC-04:00] [test.js:15] [WARN] Hello, World!
[hanabira] [1650427853794|2022.04.20|00:10:53|UTC-04:00] [test.js:16] [ERROR] Hello, World!
[hanabira] [1650427853794|2022.04.20|00:10:53|UTC-04:00] [test.js:17] [INFO] { foo: 'bar' }

Full Output Format

[<hostname>] [<unix timestamp>|<human readable timestamp>] [<file name>:<function_name>:<line number>] [<log level>]

Available styling

const { colors, formats } = require("@wizo06/logger");

colors.BLACK;
colors.RED;
colors.GREEN;
colors.YELLOW;
colors.BLUE;
colors.MAGENTA;
colors.CYAN;
colors.WHITE;

formats.RESET;
formats.BRIGHT;
formats.DIM;
formats.UNDERSCORE;
formats.BLINK;
formats.REVERSE;
formats.HIDDEN;

Example

logger.info(`Downloading ${formats.UNDERSCORE}${filename}${formats.RESET}`);

logger's People

Contributors

wizo06 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.