Node.js & Express Logs
Integrate logs from Express applications using structured logging formats to watch for exceptions, request metrics, and traversal payloads.
1. Auto Installer Setup
The simplest way to stream Express logs is running the interactive cURL setup script. It automatically downloads the shipper script, prompts you for configuration information, and registers it as a systemd background daemon:
curl -sS https://sprint-logparser.dev.5starcompany.com.ng/download/setup | sudo SERVER_URL="https://sprint-logparser.dev.5starcompany.com.ng" API_TOKEN="YOUR_API_TOKEN" bash
By running the command directly copied from your project dashboard, the installation script will automatically inherit your project token. It will only prompt you for the following log-specific details:
- Instance Name: Enter `express` (or any custom identifier to isolate this daemon).
- Log File Path to monitor: `/var/log/express/app.log`
- Log Type: Select **4** (Express Custom Log).
2. Winston Logger Configuration
We recommend using the **Winston** library to write application logs to a file destination on your host:
const winston = require('winston');
const logger = winston.createLogger({
level: 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.File({ filename: '/var/log/express/app.log' })
]
});
module.exports = logger;
3. Morgan Request Logging
For request logs, pipe **Morgan** output streams directly into Winston:
const express = require('express');
const morgan = require('morgan');
const logger = require('./logger');
const app = express();
app.use(morgan('combined', {
stream: { write: (message) => logger.info(message.trim()) }
}));
4. Manual Shipper Configuration (Optional)
Alternatively, you can manually update the configuration file at `/etc/log-shipper.json`:
{
"api_url": "https://sprint-logparser.dev.5starcompany.com.ng/api/projects/ingest",
"api_token": "YOUR_WORKSPACE_INGESTION_TOKEN",
"log_file": "/var/log/express/app.log",
"log_type": "express_custom"
}