Log-vwer – A UI for your Node.js logs so you can stop using console.log

4 months ago 8

log-vwer

1.0.0 • Public • Published a few seconds ago

The ultimate plug-n-play log viewer for Node.js. Go from zero to a production-ready log dashboard in under 2 minutes.

NPM Version License Downloads


log-vwer Dashboard Preview
A beautiful, real-time UI for your application logs. No configuration needed.

log-vwer is a no-bs, developer-first logging toolkit. It provides a beautiful, responsive, and real-time UI for your application logs with out-of-the-box support for MongoDB, File, and In-Memory storage.

Stop console.log-ing into the void. Give your logs a home.


  • 🖥️ Powerful UI: A gorgeous and intuitive interface with:
    • Real-time log streaming
    • Powerful filtering and searching
    • Dark & Light modes
    • JSON metadata viewer
    • Fully responsive for desktop and mobile
  • 🚀 Blazing Fast Setup: Integrate into any Express app with just two lines of code.
  • 💾 Flexible Storage:
    • MongoDB: Scalable, persistent logs for production.
    • File: Simple, file-based persistence.
    • Memory: Ephemeral logs for development and testing.
  • 🔐 Secure by Design: Easily place the log viewer behind your existing authentication middleware to protect your data.
  • 🕊️ Zero Dependencies: The frontend is pure, dependency-free HTML, CSS, and JavaScript. It just works.
  • 🛠️ Developer-First: Built by a developer, for developers, to solve a real-world problem with minimal fuss.

Step 1: Install the Package

Step 2: Integrate with Express

In your app.js or server.js, set up the logger and mount the viewer middleware.

const express = require('express'); const { setupLogger, viewerMiddleware } = require('log-vwer'); // 1. Initialize the logger with your preferred storage // See the "Configuration" section below for all options. const logger = setupLogger({ serviceName: 'my-awesome-app', store: 'mongodb', // or 'file', 'memory' mongoUrl: 'mongodb://localhost:27017/my_app_logs', // Required if store is 'mongodb' }); const app = express(); const PORT = process.env.PORT || 3000; // 2. (Recommended) Create a middleware to secure the log viewer const myAuthMiddleware = (req, res, next) => { // IMPORTANT: Add your own authentication and authorization logic here. // This is just a basic example. if (req.headers.authorization === 'Bearer my-secret-token') { return next(); } res.status(401).send('Authentication Required'); }; // 3. Mount the viewer UI on a protected route // The viewerMiddleware takes the logger instance as an argument. app.use('/_logs', myAuthMiddleware, viewerMiddleware(logger)); // 4. Use the logger anywhere in your application! app.get('/', (req, res) => { logger.info('Root endpoint hit successfully', { ip: req.ip, userAgent: req.get('User-Agent'), query: req.query }); res.send('Hello World! Check your logs at /_logs'); }); app.get('/error-test', (req, res) => { try { throw new Error('This is a test error!'); } catch (error) { logger.error('An error occurred in /error-test', { error: error.message, stack: error.stack }); res.status(500).send('An error was logged.'); } }); app.listen(PORT, () => { logger.warn(`Server started on port ${PORT}.`); console.log(`Server is running! Access your log viewer at http://localhost:${PORT}/_logs`); });

Start your application and navigate to http://localhost:3000/_logs in your browser. Use the credentials from your auth middleware to log in.


This function initializes and returns a logger instance. It takes a single options object.

Option Type Required Default Description
serviceName string Yes - A unique name for your application (e.g., 'user-service', 'api-gateway').
store string No 'memory' Storage type. Can be 'mongodb', 'file', or 'memory'.
mongoUrl string If store is mongodb - The connection string for your MongoDB database.
filePath string If store is file - The absolute or relative path to the log file (e.g., ./logs/app.log).
telemetry object No null An optional object for providing anonymous usage analytics. See details.

An Express middleware that serves the log viewer UI. It requires the logger instance returned by setupLogger.

The logger object returned by setupLogger has the following methods for logging:

  • logger.info(message, [metadata])

  • logger.warn(message, [metadata])

  • logger.error(message, [metadata])

  • logger.debug(message, [metadata])

  • message (string): The primary log message.

  • metadata (object, optional): A JSON-serializable object containing additional context.


Choose the right storage backend for your needs.

Backend Use Case Pros Cons
mongodb Production environments. Scalable applications needing persistent logs. Highly scalable, powerful querying, persistent. Requires a separate MongoDB instance.
file Development & Small Apps. When you need simple, persistent logs. Easy to set up, human-readable file, portable. Can be slow at scale, requires log rotation management.
memory Development & Testing. When you don't need logs to persist. Blazing fast, zero configuration, no cleanup. Logs are lost when the application restarts.

Your application logs can contain sensitive information. It is highly recommended to protect the log viewer endpoint with authentication and authorization middleware.

log-vwer is designed to integrate seamlessly with your existing security setup. Simply add your middleware before viewerMiddleware.

// Example using Passport.js or any other auth strategy const passport = require('passport'); // Assuming you have passport configured // Protect the route with your preferred strategy app.use( '/_logs', passport.authenticate('jwt', { session: false }), viewerMiddleware(logger) );

This library was built with passion by Qitmeer Raza.


Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Distributed under the MIT License. See LICENSE for more information.

Package Sidebar

Install

Last publish

a few seconds ago

Collaborators

  • iamqitmeer

Read Entire Article