Skip to content

Conversation

@100NikhilBro
Copy link
Contributor

📝 Logging Setup - Winston + Morgan

Issue / Feature

Improvement: Winston + Morgan Logging Setup (#1285)

This setup provides a production-ready logging solution for Express apps, using Winston for application-level logging and Morgan for HTTP request logging.

🗂 Folder Structure

src/
├── logger/
│   ├── winston.js             # Winston configuration
│   ├── morgan.js              # Morgan HTTP logger
├── middlewares/
│   └── logging.middleware.js  # Attach req.logger and Morgan
├── middlewares/error.handler.js  # Global error handler using Winston - i updated this 
├── server.js        # Main server entry - used here  - loggingMiddleware(server)
  

Notes:

  • logs/ folder is auto-created on first run
  • error.log → contains only error-level logs
  • combined.log → contains all logs

⚡ Features

  • ✅ Automatic logs folder creation if missing
  • ✅ Request-level logging via Morgan + Winston
  • ✅ Error logging in both console and log files
  • ✅ Production-ready (different log levels for dev/prod)
  • ✅ Non-breaking modular middleware

🛠 Installation / Usage

  1. Install dependencies (if not installed yet):
    npm install winston morgan
          
  2. <li>
      <strong>Use request logger in routes</strong>:
      <pre>
    

    app.get('/', (req, res) => {
    req.logger.info('Home route accessed!')
    res.send('Logging system working perfectly 🚀')
    })

    ⚙️ Logging Behavior

    Log Type File Notes
    Console N/A Visible in terminal (colorized in dev)
    Error logs/error.log Only error-level logs
    Combined logs/combined.log All logs (info, warn, error, etc.)
    HTTP Requests Routed via Morgan Forwarded to Winston

@vercel
Copy link

vercel bot commented Oct 6, 2025

@100NikhilBro is attempting to deploy a commit to the avdheshvarshney's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link

github-actions bot commented Oct 6, 2025

Thank you for submitting your pull request! We'll review it as soon as possible. For further communication, join our discord server https://discord.gg/tSqtvHUJzE.

@100NikhilBro
Copy link
Contributor Author

Hi @Avdhesh-Varshney,

I just created a PR and wanted to share it with you. Please have a look when you get a chance, and let me know if any updates or improvements are needed.

Thanks!

@100NikhilBro
Copy link
Contributor Author

@Avdhesh-Varshney Hi bro 👋
The test check can be kept — I’ve added a comment explaining why it’s there. It doesn’t cause any issue and is just for future scalability.

Also, please review the PR whenever you get time. If you feel it’s valid, you can label it as level 2 (not necessary, only if feasible). Thanks! 🙌

Copy link
Member

@Avdhesh-Varshney Avdhesh-Varshney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice Work 🎉

@vercel
Copy link

vercel bot commented Oct 8, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
code-a2z-server Error Error Oct 20, 2025 8:50am

💡 Enable Vercel Agent with $100 free credit for automated AI reviews

@Avdhesh-Varshney
Copy link
Member

Nikhil, Could you check why the preview not working?
https://code-a2z-server.vercel.app/monitor/health PROD is working fine

@100NikhilBro
Copy link
Contributor Author

Hi @Avdhesh-Varshney,
I just checked the monitor and it’s working perfectly. Got this response:
{
"status": "OK",
"timestamp": "2025-10-08T17:16:37.626Z"
}

@Avdhesh-Varshney
Copy link
Member

@100NikhilBro
Copy link
Contributor Author

Hi @Avdhesh-Varshney 👋, bro just checking — is there any issue from my side or with my PR that I might have missed? If yes, please let me know and I’ll update it. Otherwise, you can review and merge it. 😊

@100NikhilBro
Copy link
Contributor Author

https://code-a2z-server-git-fork-100ni-9764f4-avdheshvarshneys-projects.vercel.app/monitor/health

Bro, this link requires authorization — I’m not able to access it directly. Could you please confirm if it’s meant to be private or if I need some credentials/token to view it?

@Avdhesh-Varshney
Copy link
Member

image

I'm not sure, But I'll check it later. You can start your work on other issues 👍

@100NikhilBro
Copy link
Contributor Author

@Avdhesh-Varshney okk bro i will check the other issues

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a production-ready logging solution using Winston for application-level logging and Morgan for HTTP request logging. The setup provides structured logging with automatic log file management and request-level logger attachment.

  • Added Winston logger configuration with file and console transports
  • Integrated Morgan middleware for HTTP request logging
  • Updated error handler to use the new logging system

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
server/src/server.js Imports and applies the logging middleware to the Express app
server/src/middlewares/logging.middleware.js Creates middleware that sets up Morgan and attaches logger to requests
server/src/middlewares/error.handler.js Updates error handling to use Winston logger instead of console.error
server/src/logger/winston.js Configures Winston logger with file transports and formatting
server/src/logger/morgan.js Sets up Morgan HTTP logging middleware with Winston integration
server/package.json Adds winston and morgan dependencies
Files not reviewed (1)
  • server/package-lock.json: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@100NikhilBro
Copy link
Contributor Author

Hi @Avdhesh-Varshney,

Is our backend ready or already deployed? If yes, please merge this PR.
If not, could you please let me know what the current issue is?

Just a reminder — tomorrow is the last date for this program, so it would be great to get this resolved as soon as possible.

Thanks!

@Avdhesh-Varshney Avdhesh-Varshney merged commit 6eea586 into Code-A2Z:main Oct 21, 2025
1 of 4 checks passed
@Avdhesh-Varshney Avdhesh-Varshney linked an issue Oct 21, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improvement : Winston + Morgan Logging Setup

2 participants