Skip to content

Conversation

@abhi0324
Copy link

This PR introduces a structured logging utility for Firebase Cloud Functions to improve debugging, monitoring, and overall log consistency.

Key Changes:

  • New logger utility: A custom logging module (functions/src/utils/logger.js) has been created, providing info, warn, and error methods. These methods output logs in a consistent, structured JSON format, including level, message, timestamp, and additional context.
  • Replaced console.log/console.error: All instances of console.log and console.error within the functions/src/triggers/ and functions/src/https/ directories have been replaced with calls to the new structured logger.
  • Improved context: Logs now automatically include a timestamp and the log level, with the ability to easily add more contextual information.

Benefits:

  • Enhanced Debugging: Easier to parse and filter logs during development and troubleshooting.
  • Consistent Format: Ensures all function logs adhere to a standard structure.
  • Better Monitoring: Enables more effective integration with logging and monitoring tools (e.g., Google Cloud Logging, Stackdriver).

Affected Files/Directories:

  • functions/src/utils/logger.js (new file)
  • functions/src/triggers/onStorageUpdate.js
  • functions/src/triggers/onTestCreate.js
  • functions/src/triggers/onTestUpdate.js
  • functions/src/https/email.js
  • functions/src/https/eyeTracking.js
  • functions/src/https/users.js

Signed-off-by: Abhiswant Chaudhary <abhiswant0324@gmail.com>
@github-actions
Copy link

github-actions bot commented Jan 25, 2026

⚠️ PR Description Issues Detected

Please update the PR description to address these issues.

@github-actions github-actions bot added size/M and removed size/S labels Jan 25, 2026
@marcgc21
Copy link
Member

Can you add screenshots that holds your proposal?

@marcgc21 marcgc21 self-requested a review January 25, 2026 13:18
Signed-off-by: Abhiswant Chaudhary <abhiswant0324@gmail.com>
@sonarqubecloud
Copy link

@abhi0324
Copy link
Author

Hi @marcgc21,

Thank you for your feedback and for requesting screenshots!

You're right, visual proof is essential for demonstrating the impact of structured logging. I've prepared "before" and "after" log outputs from the Firebase Emulator terminal, specifically showcasing the behavior of the sendEmail function. This clearly illustrates the transition from unstructured console.error to a more robust, JSON-formatted logger.error output.


Before Changes (using console.error):

This log snippet shows the output from the sendEmail function before the structured logging utility was integrated. The error message and stack trace are outputted as plain text, making it harder to programmatically parse and analyze.

Screenshot 2026-01-26 at 2 17 06 PM

After Changes (using logger.error):

This log snippet shows the output from the sendEmail function after the structured logging utility was implemented. As you can see, the error is now encapsulated within a JSON object. This provides a structured format with clear fields for level, timestamp, severity, and the detailed error object. This structured output is significantly easier to parse, filter, and analyze in logging and monitoring systems.

Screenshot 2026-01-26 at 2 23 29 PM

@abhi0324
Copy link
Author

/cc @marcgc21

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.

2 participants