errsole

repository·master·Indexed 20 days ago

https://github.com/errsole/errsole.js

A comprehensive logging solution for Node.js (v2.18.2) that collects, stores, and visualizes logs via a built-in Web Dashboard. It supports multiple storage backends including SQLite, MySQL, PostgreSQL, and MongoDB, and provides integrations for Slack and Email notifications. The module includes specialized logging functions (log, alert, error, warn, debug) and a .meta() method for attaching contextual metadata to logs.

Tokens
16K
Snippets
47
Records
63
Agent score
68%

What's inside errsole

  1. Overview of Errsole

    master
    Errsole is an open-source logging module for Node.js applications designed to collect, store, and visualize logs. It provides a built-in Web Dashboard (Log Viewer) for filtering and searching logs, supports multiple storage backends (SQLite, MySQL, PostgreSQL, MongoDB), and includes features for critical error notifications and advanced metadata logging.
  2. Errsole Performance Benchmarks vs Elasticsearch and CloudWatch

    master

    Errsole is designed for high-performance logging and can be used with various storage backends including SQLite, MySQL, PostgreSQL, and MongoDB.

    Elasticsearch Comparison

    In benchmarks comparing Errsole against Elasticsearch-based logging (using Winston or Pino), Errsole demonstrated a significant performance advantage, handling approximately 70,000 - 90,000 more requests per minute.

    Amazon CloudWatch Comparison

    Errsole significantly outperforms direct Amazon CloudWatch configurations and Pino + CloudWatch setups. In tests, Errsole handled 280,000 - 300,000 more requests per minute than direct CloudWatch and 40,000 - 70,000 more requests per minute than Pino + CloudWatch. Notably, Winston + CloudWatch configurations failed in the tested scenarios.

    Average Requests Per Minute (Benchmark Results)

    ConfigurationAvg Requests/Min
    Errsole + SQLite~364,269
    Errsole + PostgreSQL~364,144
    Errsole + MySQL~350,758
    Errsole + MongoDB~339,128
    Pino + Elasticsearch~265,227
    Winston + Elasticsearch~271,761
    Pino + CloudWatch~295,133
    CloudWatch (Direct)~54,868
  3. Integrate the Errsole Web Dashboard using Proxy Middleware

    master
    If you want to host the Errsole Web Dashboard as a route within your existing application instead of running it as a separate service, you can use the Errsole Proxy Middleware. This middleware maps a specific route in your main application to the Errsole dashboard interface.
  4. Install Winston and Errsole dependencies

    master

    To set up the Winston integration, you need to install winston, winston-errsole, errsole, and a storage provider (e.g., errsole-sqlite).

    # Install Winston and the transport
    npm install winston winston-errsole
    
    # Install Errsole and a storage engine
    npm install errsole errsole-sqlite
  5. Integrate the Errsole Web Dashboard via Proxy Middleware

    master

    To host the Errsole Web Dashboard as a route within your existing application, use the Errsole Proxy Middleware. This allows you to access the dashboard using your application's domain (e.g., https://api.example.com/errsole).

    Critical Requirements:

    1. Mandatory Path: You must specify a path where the dashboard will be accessible.
    2. Middleware Order: The Errsole Proxy Middleware must be the first middleware in your application. All other middlewares (like body parsers or routers) must be placed after it.
    3. Custom Paths: If you have initialized Errsole with a custom path, you must append that custom path to the middleware path registration.
  6. Configure NGINX to proxy the Errsole Web Dashboard

    master

    If your application is behind an NGINX reverse proxy, add the following configuration to map a specific URL path to the Errsole Web Dashboard (defaulting to port 8001):

    location = /your-app-name/logs {
      return 301 /your-app-name/logs/;
    }
    location /your-app-name/logs/ {
      proxy_pass http://localhost:8001/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }

    Note: Replace /your-app-name/logs with your desired path. After updating, reload NGINX using sudo nginx -s reload.

  7. Configure NGINX for the Errsole Web Dashboard

    master

    If your application is behind an NGINX reverse proxy, add a location block to your NGINX configuration to proxy requests to the Errsole dashboard (default port 8001).

    Replace /your-app-name/logs with your preferred URL path.

    location = /your-app-name/logs {
      return 301 /your-app-name/logs/;
    }
    location /your-app-name/logs/ {
      proxy_pass http://localhost:8001/;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }

    After updating, reload NGINX using sudo nginx -s reload.

  8. Configure the Errsole logger with MongoDB

    master

    Initialize Errsole by creating a dedicated logger.js file. This ensures the logger is a singleton that can be easily imported throughout your application. The ErrsoleMongoDB constructor accepts a connection URL, an optional database name, and an optional object for MongoDB client options (such as collectionPrefix).

    // CommonJS
    const errsole = require('errsole');
    const ErrsoleMongoDB = require('errsole-mongodb');
    
    errsole.initialize({
      storage: new ErrsoleMongoDB(
        'mongodb-connection-url',
        'optional-database-name',
        { collectionPrefix: 'your-app-name' }
      ),
      appName: 'your-app-name'
    });
    
    module.exports = errsole;
  9. Initialize Errsole with ErrsolePostgres

    master

    Initialize Errsole by passing a new instance of ErrsolePostgres to the storage option within errsole.initialize(). You must provide connection details such as host, user, password, database, and tablePrefix.

    errsole-postgres uses the pg package, so it supports all standard PostgreSQL connection options provided by the node-postgres client.

    import errsole from 'errsole';
    import ErrsolePostgres from 'errsole-postgres';
    
    errsole.initialize({
      storage: new ErrsolePostgres({
        host: 'postgres-host',
        user: 'database-user',
        password: 'database-password',
        database: 'database-name',
        tablePrefix: 'app-name',
      }),
      appName: 'app-name'
    });
    
    export default errsole;
  10. Configure the Errsole MySQL logger

    master

    Initialize Errsole by providing a new ErrsoleMySQL() instance to the storage option. You must provide connection details such as host, user, password, database, and tablePrefix.

    errsole-mysql uses the mysql2 package, so it supports all standard MySQL connection options for advanced configuration.

    const errsole = require('errsole');
    const ErrsoleMySQL = require('errsole-mysql');
    
    errsole.initialize({
      storage: new ErrsoleMySQL({
        host: 'mysql-host',
        user: 'database-user',
        password: 'database-password',
        database: 'database-name',
        tablePrefix: 'app-name'
      }),
      appName: 'app-name'
    });
    
    module.exports = errsole;