0.0.5 • Published 5 months ago

log-to-kafka v0.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

GrayLog Middleware for Express

This middleware integrates GrayLog logging with an Express application, allowing you to capture and log detailed information about incoming HTTP requests and their corresponding responses.

Installation

To use this middleware, you need to have a Kafka producer for GrayLog set up. Install the required npm packages:

npm install express kafkajs

npm install express kafkajs Usage Import the Middleware javascript Copy code

const express = require('express');
const grayLogMiddleware  = require('log-to-kafka');// Your Kafka producer setup
const kafka = require('kafkajs');const app = express();// Use GrayLog Middleware
app.use(grayLogMiddleware({kafka,topic:"log",key:"notification"}));// Your routes and other middleware
app.get('/', (req, res) => {
  res.send('Hello, world!');
});// Start the server
const PORT = 3000;
app.listen(PORT, () => {
  console.log(Server is running on port ${PORT});
});

Middleware Configuration The grayLogMiddleware function takes a Kafka producer as an argument and returns an Express middleware. It logs information about incoming HTTP requests and their responses to a Kafka topic named "log."

Adjust the Kafka producer setup according to your project's configuration.

Log Format The middleware logs messages in JSON format with various details about the request and response, including request method, URL, query parameters, headers, request and response bodies, response time, and more.

Kafka Topic Ensure that the Kafka topic named "log" is created and configured in your Kafka setup. The middleware sends log messages to this topic.

License This middleware is provided under the MIT License.

0.0.5

5 months ago

0.0.4

5 months ago

0.0.3

5 months ago

0.0.2

5 months ago

0.0.1

5 months ago