Socket
Book a DemoInstallSign in
Socket

@tobes31415/console-logger

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tobes31415/console-logger

Formats console logs while preserving stack trace info

Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

Console-Logger

A Javascript console log formatter that logs the correct line number. Also supports forking logs to other log reporters so that you can have the benefit of both

View API Docs

Installation

npm install --save @tobes31415/console-logger

Basic Useage

import { createLogFor } from "@tobes31415/console-logger";

const logger = createLogFor("My Module Name");

console.log(...logger("This is a test", 123, "abc"));
// "[My Module Name] 0.5s This is a test", 123, "abc"

Advanced Useage - Forking Log Events

import { onLogEvent } from "@tobes31415-console-logger";

onLogEvent.subscribe(log => {
  //log messages to a server or something
  myServerLogger.log(log.message, ...);
})

Advanced Useage - Customizing the loggers Globally

import { customizeDefaultLogFormatter } from "@tobes31415-console-logger";

customizeDefaultLogFormatter({
   format: {
     uptime: ms => Math.round(ms / 1000) + "s",
   },
   style: {
     uptime: "color:green"
   }
});

Advanced Useage - Customizing individual loggers

import { createLogFor } from "@tobes31415-console-logger";

const logger = createLogFor("My Module Name");

logger.config({
  logThreshold: "warn"
});

console.log(...logger("This does not get logged"));
console.warn(...logger.warn("This one does get logged"));

Thank you

Big thank you to Macadamian Technologies for donating time towards this open source project :-)

Keywords

console

FAQs

Package last updated on 10 Jun 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts