Uncategorized

Log Viewer for Node.js applications

Errsole is an open-source logger for Node.js applications. It comes with a built-in log viewer to view, filter, and search your application logs. If you are SSHing into servers or scrolling through raw log files to find errors or debug logs, Errsole simplifies the process for you.

Errsole Setup

1. Install the modules

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

npm install errsole errsole-sqlite

SQLite stores databases as files. So, your application logs will be stored as a file on your server.

2. Configure your logger

Create a logger.js file to configure Errsole for your application:

// logger.js
const errsole = require('errsole');
const ErrsoleSQLite = require('errsole-sqlite');
const os = require('os');
const path = require('path');

const logsFile = path.join(os.tmpdir(), `YourAppName.log.sqlite`);
errsole.initialize({
  storage: new ErrsoleSQLite(logsFile)
});

module.exports = errsole;
3. Include the logger in your application code

To start logging, include the logger in your application code. Here is an example using Express:

// server.js File
const express = require('express');
const errsole = require('./logger');

const app = express();

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

const port = 3000;
app.listen(port, () => {
  errsole.log(`Hello World app is listening on port ${port}`);
});

Accessing the Log Viewer

Once the setup is complete, you can access the Errsole Web Dashboard to view and manage your logs:

For Local Development

Open your web browser and go to http://localhost:8001/

For Remote Deployment

Use the server’s IP address or domain followed by the port number. For example:

http://YourServerIP:8001/
http://YourDomain:8001/

NGINX Configuration

If your application is behind an NGINX reverse proxy, you can configure it to access your logs. Add the following to your NGINX configuration:

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

After completing the NGINX configuration, reload NGINX and access the Errsole Web Dashboard using the configured URL paths:

  • For server IP access: http://YourServerIP/helloworld/logs/
  • For domain access (HTTP): http://YourDomain/helloworld/logs/
  • For domain access (HTTPS): https://YourDomain/helloworld/logs/

Note: Replace /helloworld/logs with your desired log path.

Building Errsole. Worked in startups. Built products from scratch. Passionate about coding and innovation.

Write A Comment