npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

console-watcher

v0.1.0

Published

console-watcher is a utility library designed to monitor and handle console outputs in a Node.js environment. By using `console-watcher`, developers can easily save console logs, errors, and info messages to a .log, .txt or .json file while retaining the

Downloads

1

Readme

console-watcher

Publish Package to npmjs npm version License: MIT PRs Welcome Downloads

console-watcher is a utility library that provides extended logging capabilities for Node.js applications. It overrides the native console methods, allowing developers to customize how logs are handled. Logs can be saved to a file, or even synced to a dedicated cloud while retaining the ability to display or hide them in the console for security reasons.

Features

  • Override native console logging methods (console.log, console.info, console.error).
  • Configurable behavior to print in console or save to a file.
  • Supports both JSON and non-JSON file types for logs saving.
  • Encrypt and sync logs to a dedicated cloud for better visualization and management.
  • Register your custom error handling function which will be called whenever an error occurs within the library.

Installation

npm install console-watcher

Usage

To use console-watcher, first import the class in your app's entry file and create a new instance.

import ConsoleWatcher from 'console-watcher'

const watcher = new ConsoleWatcher(config)

Configuration

When initializing console-watcher, you can pass in a configuration object with the following properties:

  • printInConsole: Determines if the log should be displayed in the console. Default is true.
  • saveToFile: Determines if the log should be saved to a file. Default is true.
  • logFilePath: Specifies the path of the log file. The utility checks for the file type to determine if it's JSON or non-JSON. Default file path is console-watcher.log.
const config = {
  printInConsole: true,
  saveToFile: true,
  logFilePath: 'consoleWatcher.json',
}

Global Error Handling

Console Watcher supports a global error handler. You can register your custom error handling function which will be called whenever an error occurs within the library.

watcher.registerGlobalErrorHandler((error) => {
  console.error(
    'An error occurred in Console Watcher:',
    error.message ?? error?.response?.statusText ?? 'Unknown'
  )
})

By registering a global error handler, you have the flexibility to handle errors in a way that best suits your application, whether it’s logging, alerting the user, or other custom behaviors.

Syncing to ConsoleWatcher Cloud

ConsoleWatcher provides the flexibility to sync your logs to a dedicated cloud, either manually or at regular intervals. This feature enhances log visualization and management.

To manually sync logs:

watcher.syncToConsoleWatcherCloud({
  apiKey: 'YOUR_API_KEY',
  applicationKey: 'YOUR_APPLICATION_KEY',
  encryptionKey: 'YOUR_ENCRYPTION_KEY',
})

For automated intervals, you can set up a routine using JavaScript's setInterval:

setInterval(() => {
  watcher.syncToConsoleWatcherCloud({
    apiKey: 'YOUR_API_KEY',
    applicationKey: 'YOUR_APPLICATION_KEY',
    encryptionKey: 'YOUR_ENCRYPTION_KEY',
  })
}, YOUR_DESIRED_INTERVAL_IN_MILLISECONDS)

Replace YOUR_DESIRED_INTERVAL_IN_MILLISECONDS with the frequency you want the sync operation to occur (e.g., 60000 for every minute). Adjust as needed to suit your application's requirements.

Sync Configuration:

  • apiKey: Your dedicated API key for the ConsoleWatcher platform.
  • applicationKey: Your application’s unique key on the ConsoleWatcher platform.
  • encryptionKey: A private key unique to you. Ensure you keep this key safe and don’t lose it to prevent data loss. This key must be exactly 16 characters in length.

Note: The encryption key is used to encrypt logs before they’re sent to the cloud. This ensures data privacy and security. It’s vital not to lose or change this key to avoid losing already encrypted data.

Contributing

First and foremost, thank you for your interest in contributing to ConsoleWatcher! Open source projects like this thrive because of contributors like you. Here's how you can help:

Getting Started

  1. Fork the Repository: Start by forking the console-watcher repository to your own GitHub account.

  2. Clone the Repository: Once you have forked the repo, clone it to your local machine:

    git clone https://github.com/YOUR_USERNAME/console-watcher.git
  3. Install Dependencies: After cloning, navigate to the project directory and install the necessary dependencies:

    cd console-watcher
    npm install

Making Changes

  1. Create a New Branch: Always create a new branch for your changes:

    git checkout -b feature/your-feature-name
  2. Make Your Changes: Implement your feature or bug fix.

  3. Run Tests: Ensure that your changes do not break any existing functionality. Add new tests if necessary.

  4. Commit Your Changes: Once you're satisfied with your changes, stage and commit them:

    git add .
    git commit -m "Add some feature or fix some bug"
  5. Push to Your Fork: Push your changes to your forked repository:

    git push origin feature/your-feature-name

Submitting a Pull Request

  1. Open a Pull Request: Navigate to the ConsoleWatcher repository and click on "Pull Requests". Click the "New Pull Request" button and select your fork and branch.

  2. Describe Your Changes: In the pull request description, explain your changes, why you made them, and any additional context if necessary.

  3. Wait for Review: The maintainers will review your pull request, provide feedback, and merge it once it's approved.

Additional Notes

  • Respect the Code of Conduct: Please ensure that you follow the project's code of conduct in all interactions.

  • Ask for Help: If you're stuck or unsure about something, don't hesitate to ask for help. The community is here to assist.

  • Stay Updated: Make sure to pull the latest changes from the master branch before creating a new pull request.

Thank you for your contribution! Your efforts help make ConsoleWatcher better for everyone.

License

MIT


This README provides a basic introduction and guide to using the console-watcher utility. Additional sections, such as a more detailed installation guide, examples, and information about dependencies, can be added as required.