Skip to content

Latest commit

 

History

History
85 lines (59 loc) · 6.25 KB

mongodb-storage.md

File metadata and controls

85 lines (59 loc) · 6.25 KB

Errsole with MongoDB

Install

Install the errsole and errsole-mongodb modules using the npm install command:

npm install errsole errsole-mongodb

Configure

const errsole = require('errsole');
const ErrsoleMongoDB = require('errsole-mongodb');

// Alternatively, if you are using ECMAScript modules (ESM), you can import the modules as follows:
// import errsole from 'errsole';
// import ErrsoleMongoDB from 'errsole-mongodb';

// Insert the Errsole code snippet at the beginning of your app's main file
errsole.initialize({
  storage: new ErrsoleMongoDB('<MongoDB Connection URL>', '<Optional: Database Name>', '<Optional: MongoDB Client Options>')
});

Example

const express = require('express');
const errsole = require('errsole');
const ErrsoleMongoDB = require('errsole-mongodb');

// Insert the Errsole code snippet at the beginning of your app's main file
errsole.initialize({
  storage: new ErrsoleMongoDB('mongodb://localhost:27017/', 'logs')
});

const app = express();

app.get('/', function (req, res) {
  res.send('Hello World');
});

app.listen(3000);

Advanced Configuration

Option Type Description
storage ErrsoleMongoDB Required.
Setup MongoDB as the storage backend with connection details.
collectLogs Array of Strings Optional. The default value is ['error', 'info'].
By default, Errsole collects both error and info logs. If you wish to limit Errsole to collecting only error logs, you can set this option to ['error']. If you prefer Errsole not to collect any logs, simply set this option to an empty array, [].
enableConsoleOutput Boolean Optional. The default value is true.
Control whether log output is also shown in the console.
exitOnException Boolean Optional. The default value is true.
By default, Errsole will exit the process after capturing an uncaught exception. If this is not the behavior you want, you can disable it by setting exitOnException to false.
enableDashboard Boolean Optional. The default value is true.
Enable or disable the web dashboard feature.
port Number Optional. The default value is 8001.
Specify the network port for the web dashboard.
path String Optional. The default value is '/'.
Define the base path for accessing the web dashboard.
appName String Optional. The default value is the name from package.json.
Specify the name of the app.
environmentName String Optional. The default value is process.env.NODE_ENV.
Specify the deployment environment.
serverName String Optional. The default value is the hostname of the machine.
Specify the name of the server.

Web Dashboard Access

After completing the setup, you can access the Errsole Web Dashboard through the following methods:

  1. Local Environment: Open your web browser and visit http://localhost:8001/.
  2. Remote Server: If you have deployed Errsole on a remote server, use the server's IP address or domain name followed by the port number (e.g., YourServerIP:8001 or YourDomain:8001).

Note

If you initialized Errsole with a different port or specified a custom path, adjust the URL as follows:

  1. Replace 8001 with your chosen port number.
  2. Append your custom path to the end of the URL.

http(s)://YourServerIP:CustomPort/YourCustomPath

Proxy Middleware Configuration

If you encounter issues accessing port 8001 due to firewall restrictions, or if you prefer to host the Errsole Web Dashboard on your primary domain/port, you can configure the Errsole Proxy Middleware in your app. Here is a step-by-step guide: Proxy Middleware Configuration

Main Documentation

Main Documentation