console-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

Console Hooks

by the #sathoshiengineeringcrew

MIT License Badge

Console Hooks is a helper script that enhances standard console methods like console.debug, console.log, console.info, console.warn and console.error. It allows you to hook into these methods to add custom behavior, such as sending error messages to a remote logging service.

Features

  • Intercepts and modifies console method outputs
  • Customizable hooks for each console method
  • Easy integration with other services like Telegram

Installation

npm i console-hooks

Example usage

This example uses TelegramSender. Install with npm i telegram-sender

import consoleHooks from 'console-hooks'
import TelegramSender from 'telegram-sender'

const telegramSender = new TelegramSender({
  token: 'TOKEN_OF_YOUR_BOT',
  defaultChatId: 'ID_OF_THE_TARGET_CHAT',
  messagePrefix: 'Website backend error'
})

consoleHooks({
  onError: async (message) => {
    await telegramSender.sendMessage({ message })
  }
})

// In your code somewhere else:
console.error('Something bad happened')


// You will receive a Telegram message similar to this:
[Website backend error]
[2024-06-26 15:26:12] Something bad happened

Tip Us

If you like this project, give it a star! If you love it, fork it and take it out for dinner. 🌟🍽️
And hey, why not send some tip love?

Readme

Keywords

none

Package Sidebar

Install

npm i console-hooks

Weekly Downloads

24

Version

1.0.2

License

MIT

Unpacked Size

9.72 kB

Total Files

13

Last publish

Collaborators

  • dr-erych
  • thespielplatz-org
  • sate_tom