diff --git a/backend/routes/forum.js b/backend/routes/forum.js index dec14d1..e885b70 100644 --- a/backend/routes/forum.js +++ b/backend/routes/forum.js @@ -729,7 +729,7 @@ router.patch('/posts/:id/status', authenticateToken, async (req, res, next) => { stack: emailError.stack, postId: req.params.id }); - console.error("Email notification error:", emailError); + logger.error("Email notification error", { error: emailError }); } })(); } @@ -909,7 +909,7 @@ router.patch('/posts/:id/accept-answer', authenticateToken, async (req, res, nex commentId: commentId, postId: req.params.id }); - console.error("Email notification error:", emailError); + logger.error("Email notification error", { error: emailError }); } })(); } @@ -1109,7 +1109,7 @@ router.post('/posts/:id/comments', authenticateToken, async (req, res, next) => commentId: comment.id, postId: req.params.id }); - console.error("Email notification error:", emailError); + logger.error("Email notification error", { error: emailError }); } })(); @@ -1689,7 +1689,7 @@ router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (r stack: emailError.stack, postId: req.params.id }); - console.error("Email notification error:", emailError); + logger.error("Email notification error", { error: emailError }); } })(); diff --git a/backend/routes/users.js b/backend/routes/users.js index 1d76777..2d1ec25 100644 --- a/backend/routes/users.js +++ b/backend/routes/users.js @@ -269,7 +269,7 @@ router.put('/profile', authenticateToken, async (req, res, next) => { res.json(updatedUser); } catch (error) { - console.error('Profile update error:', error); + logger.error('Profile update error', { error }); next(error); } }); diff --git a/backend/services/email/core/EmailClient.js b/backend/services/email/core/EmailClient.js index e48c5e4..db91d4e 100644 --- a/backend/services/email/core/EmailClient.js +++ b/backend/services/email/core/EmailClient.js @@ -1,6 +1,7 @@ const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses"); const { getAWSConfig } = require("../../../config/aws"); const { htmlToPlainText } = require("./emailUtils"); +const logger = require("../../../utils/logger"); /** * EmailClient handles AWS SES configuration and core email sending functionality @@ -44,9 +45,9 @@ class EmailClient { this.sesClient = new SESClient(awsConfig); this.initialized = true; - console.log("AWS SES Email Client initialized successfully"); + logger.info("AWS SES Email Client initialized successfully"); } catch (error) { - console.error("Failed to initialize AWS SES Email Client:", error); + logger.error("Failed to initialize AWS SES Email Client", { error }); throw error; } })(); @@ -69,7 +70,7 @@ class EmailClient { // Check if email sending is enabled in the environment if (!process.env.EMAIL_ENABLED || process.env.EMAIL_ENABLED !== "true") { - console.log("Email sending disabled in environment"); + logger.debug("Email sending disabled in environment"); return { success: true, messageId: "disabled" }; } @@ -115,12 +116,10 @@ class EmailClient { const command = new SendEmailCommand(params); const result = await this.sesClient.send(command); - console.log( - `Email sent successfully to ${to}, MessageId: ${result.MessageId}` - ); + logger.info("Email sent successfully", { to, messageId: result.MessageId }); return { success: true, messageId: result.MessageId }; } catch (error) { - console.error("Failed to send email:", error); + logger.error("Failed to send email", { error, to }); return { success: false, error: error.message }; } } diff --git a/backend/services/email/core/TemplateManager.js b/backend/services/email/core/TemplateManager.js index 5bf2e3c..f76440a 100644 --- a/backend/services/email/core/TemplateManager.js +++ b/backend/services/email/core/TemplateManager.js @@ -1,5 +1,6 @@ const fs = require("fs").promises; const path = require("path"); +const logger = require("../../../utils/logger"); /** * TemplateManager handles loading, caching, and rendering email templates @@ -40,7 +41,7 @@ class TemplateManager { this.initializationPromise = (async () => { await this.loadEmailTemplates(); this.initialized = true; - console.log("Email Template Manager initialized successfully"); + logger.info("Email Template Manager initialized successfully"); })(); return this.initializationPromise; @@ -118,22 +119,21 @@ class TemplateManager { const templateContent = await fs.readFile(templatePath, "utf-8"); const templateName = path.basename(templateFile, ".html"); this.templates.set(templateName, templateContent); - console.log(`✓ Loaded template: ${templateName}`); + logger.debug("Loaded template", { templateName }); } catch (error) { - console.error( - `✗ Failed to load template ${templateFile}:`, - error.message - ); - console.error( - ` Template path: ${path.join(templatesDir, templateFile)}` - ); + logger.error("Failed to load template", { + templateFile, + templatePath: path.join(templatesDir, templateFile), + error, + }); failedTemplates.push(templateFile); } } - console.log( - `Loaded ${this.templates.size} of ${templateFiles.length} email templates` - ); + logger.info("Loaded email templates", { + loaded: this.templates.size, + total: templateFiles.length, + }); // Check if critical templates are missing const missingCriticalTemplates = criticalTemplates.filter( @@ -152,17 +152,15 @@ class TemplateManager { // Warn if non-critical templates failed if (failedTemplates.length > 0) { - console.warn( - `⚠️ Non-critical templates failed to load: ${failedTemplates.join( - ", " - )}` - ); - console.warn("These templates will use fallback versions"); + logger.warn("Non-critical templates failed to load, using fallback versions", { + failedTemplates, + }); } } catch (error) { - console.error("Failed to load email templates:", error); - console.error("Templates directory:", templatesDir); - console.error("Error stack:", error.stack); + logger.error("Failed to load email templates", { + templatesDir, + error, + }); throw error; // Re-throw to fail server startup } } @@ -176,22 +174,20 @@ class TemplateManager { async renderTemplate(templateName, variables = {}) { // Ensure service is initialized before rendering if (!this.initialized) { - console.log(`Template manager not initialized yet, initializing now...`); + logger.debug("Template manager not initialized yet, initializing now..."); await this.initialize(); } let template = this.templates.get(templateName); if (!template) { - console.error(`Template not found: ${templateName}`); - console.error( - `Available templates: ${Array.from(this.templates.keys()).join(", ")}` - ); - console.error(`Stack trace:`, new Error().stack); - console.log(`Using fallback template for: ${templateName}`); + logger.error("Template not found, using fallback", { + templateName, + availableTemplates: Array.from(this.templates.keys()), + }); template = this.getFallbackTemplate(templateName); } else { - console.log(`✓ Template found: ${templateName}`); + logger.debug("Template found", { templateName }); } let rendered = template; @@ -202,9 +198,11 @@ class TemplateManager { rendered = rendered.replace(regex, variables[key] || ""); }); } catch (error) { - console.error(`Error rendering template ${templateName}:`, error); - console.error(`Stack trace:`, error.stack); - console.error(`Variables provided:`, Object.keys(variables)); + logger.error("Error rendering template", { + templateName, + variableKeys: Object.keys(variables), + error, + }); } return rendered; diff --git a/backend/services/email/domain/AlphaInvitationEmailService.js b/backend/services/email/domain/AlphaInvitationEmailService.js index ee79aaa..ed18b62 100644 --- a/backend/services/email/domain/AlphaInvitationEmailService.js +++ b/backend/services/email/domain/AlphaInvitationEmailService.js @@ -1,5 +1,6 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); +const logger = require("../../../utils/logger"); /** * AlphaInvitationEmailService handles alpha program invitation emails @@ -26,7 +27,7 @@ class AlphaInvitationEmailService { ]); this.initialized = true; - console.log("Alpha Invitation Email Service initialized successfully"); + logger.info("Alpha Invitation Email Service initialized successfully"); } /** @@ -62,7 +63,7 @@ class AlphaInvitationEmailService { htmlContent ); } catch (error) { - console.error("Failed to send alpha invitation email:", error); + logger.error("Failed to send alpha invitation email", { error }); return { success: false, error: error.message }; } } diff --git a/backend/services/email/domain/CustomerServiceEmailService.js b/backend/services/email/domain/CustomerServiceEmailService.js index 333655e..aa1d16c 100644 --- a/backend/services/email/domain/CustomerServiceEmailService.js +++ b/backend/services/email/domain/CustomerServiceEmailService.js @@ -1,5 +1,6 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); +const logger = require("../../../utils/logger"); /** * CustomerServiceEmailService handles all customer service alert emails @@ -28,7 +29,7 @@ class CustomerServiceEmailService { ]); this.initialized = true; - console.log("Customer Service Email Service initialized successfully"); + logger.info("Customer Service Email Service initialized successfully"); } /** @@ -59,7 +60,7 @@ class CustomerServiceEmailService { try { const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL; if (!csEmail) { - console.warn("No customer service email configured"); + logger.warn("No customer service email configured"); return { success: false, error: "No customer service email configured" }; } @@ -92,14 +93,14 @@ class CustomerServiceEmailService { ); if (result.success) { - console.log( + logger.info( `Late return notification sent to customer service for rental ${rental.id}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send late return notification to customer service:", error ); @@ -148,7 +149,7 @@ class CustomerServiceEmailService { try { const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL; if (!csEmail) { - console.warn("No customer service email configured"); + logger.warn("No customer service email configured"); return { success: false, error: "No customer service email configured" }; } @@ -206,14 +207,14 @@ class CustomerServiceEmailService { ); if (result.success) { - console.log( + logger.info( `Damage report notification sent to customer service for rental ${rental.id}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send damage report notification to customer service:", error ); @@ -248,7 +249,7 @@ class CustomerServiceEmailService { try { const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL; if (!csEmail) { - console.warn("No customer service email configured"); + logger.warn("No customer service email configured"); return { success: false, error: "No customer service email configured" }; } @@ -280,14 +281,14 @@ class CustomerServiceEmailService { ); if (result.success) { - console.log( + logger.info( `Lost item notification sent to customer service for rental ${rental.id}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send lost item notification to customer service:", error ); diff --git a/backend/services/email/domain/ForumEmailService.js b/backend/services/email/domain/ForumEmailService.js index 0b791be..cce1f8e 100644 --- a/backend/services/email/domain/ForumEmailService.js +++ b/backend/services/email/domain/ForumEmailService.js @@ -1,5 +1,6 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); +const logger = require("../../../utils/logger"); /** * ForumEmailService handles all forum-related email notifications @@ -31,7 +32,7 @@ class ForumEmailService { ]); this.initialized = true; - console.log("Forum Email Service initialized successfully"); + logger.info("Forum Email Service initialized successfully"); } /** @@ -88,14 +89,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum comment notification email sent to ${postAuthor.email}` ); } return result; } catch (error) { - console.error("Failed to send forum comment notification email:", error); + logger.error("Failed to send forum comment notification email:", error); return { success: false, error: error.message }; } } @@ -163,14 +164,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum reply notification email sent to ${commentAuthor.email}` ); } return result; } catch (error) { - console.error("Failed to send forum reply notification email:", error); + logger.error("Failed to send forum reply notification email:", error); return { success: false, error: error.message }; } } @@ -227,14 +228,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum answer accepted notification email sent to ${commentAuthor.email}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send forum answer accepted notification email:", error ); @@ -301,14 +302,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum thread activity notification email sent to ${participant.email}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send forum thread activity notification email:", error ); @@ -372,14 +373,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum post closed notification email sent to ${recipient.email}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send forum post closed notification email:", error ); @@ -432,14 +433,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum post deletion notification email sent to ${postAuthor.email}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send forum post deletion notification email:", error ); @@ -494,14 +495,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Forum comment deletion notification email sent to ${commentAuthor.email}` ); } return result; } catch (error) { - console.error( + logger.error( "Failed to send forum comment deletion notification email:", error ); @@ -557,14 +558,14 @@ class ForumEmailService { ); if (result.success) { - console.log( + logger.info( `Item request notification email sent to ${recipient.email}` ); } return result; } catch (error) { - console.error("Failed to send item request notification email:", error); + logger.error("Failed to send item request notification email:", error); return { success: false, error: error.message }; } } diff --git a/backend/services/email/domain/MessagingEmailService.js b/backend/services/email/domain/MessagingEmailService.js index 8f7c5bd..b259719 100644 --- a/backend/services/email/domain/MessagingEmailService.js +++ b/backend/services/email/domain/MessagingEmailService.js @@ -1,5 +1,6 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); +const logger = require("../../../utils/logger"); /** * MessagingEmailService handles all messaging-related email notifications @@ -26,7 +27,7 @@ class MessagingEmailService { ]); this.initialized = true; - console.log("Messaging Email Service initialized successfully"); + logger.info("Messaging Email Service initialized successfully"); } /** @@ -79,14 +80,14 @@ class MessagingEmailService { ); if (result.success) { - console.log( + logger.info( `Message notification email sent to ${receiver.email} from ${sender.firstName} ${sender.lastName}` ); } return result; } catch (error) { - console.error("Failed to send message notification email:", error); + logger.error("Failed to send message notification email:", error); return { success: false, error: error.message }; } } diff --git a/backend/services/email/domain/PaymentEmailService.js b/backend/services/email/domain/PaymentEmailService.js index 416a05c..4e5e474 100644 --- a/backend/services/email/domain/PaymentEmailService.js +++ b/backend/services/email/domain/PaymentEmailService.js @@ -1,6 +1,7 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); const { formatEmailDate } = require("../core/emailUtils"); +const logger = require("../../../utils/logger"); /** * PaymentEmailService handles payment-related emails @@ -28,7 +29,7 @@ class PaymentEmailService { ]); this.initialized = true; - console.log("Payment Email Service initialized successfully"); + logger.info("Payment Email Service initialized successfully"); } /** @@ -73,7 +74,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send payment declined notification:", error); + logger.error("Failed to send payment declined notification", { error }); return { success: false, error: error.message }; } } @@ -113,7 +114,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send payment method updated notification:", error); + logger.error("Failed to send payment method updated notification", { error }); return { success: false, error: error.message }; } } @@ -168,7 +169,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send payout failed notification:", error); + logger.error("Failed to send payout failed notification", { error }); return { success: false, error: error.message }; } } @@ -208,7 +209,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send account disconnected email:", error); + logger.error("Failed to send account disconnected email", { error }); return { success: false, error: error.message }; } } @@ -248,7 +249,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send payouts disabled email:", error); + logger.error("Failed to send payouts disabled email", { error }); return { success: false, error: error.message }; } } @@ -300,7 +301,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send dispute alert email:", error); + logger.error("Failed to send dispute alert email", { error }); return { success: false, error: error.message }; } } @@ -343,7 +344,7 @@ class PaymentEmailService { htmlContent ); } catch (error) { - console.error("Failed to send dispute lost alert email:", error); + logger.error("Failed to send dispute lost alert email", { error }); return { success: false, error: error.message }; } } diff --git a/backend/services/email/domain/RentalFlowEmailService.js b/backend/services/email/domain/RentalFlowEmailService.js index 7834df0..8eb2735 100644 --- a/backend/services/email/domain/RentalFlowEmailService.js +++ b/backend/services/email/domain/RentalFlowEmailService.js @@ -34,7 +34,7 @@ class RentalFlowEmailService { ]); this.initialized = true; - console.log("Rental Flow Email Service initialized successfully"); + logger.info("Rental Flow Email Service initialized successfully"); } /** @@ -104,7 +104,7 @@ class RentalFlowEmailService { htmlContent ); } catch (error) { - console.error("Failed to send rental request email:", error); + logger.error("Failed to send rental request email", { error }); return { success: false, error: error.message }; } } @@ -171,7 +171,7 @@ class RentalFlowEmailService { htmlContent ); } catch (error) { - console.error("Failed to send rental request confirmation email:", error); + logger.error("Failed to send rental request confirmation email", { error }); return { success: false, error: error.message }; } } @@ -324,10 +324,7 @@ class RentalFlowEmailService { htmlContent ); } catch (error) { - console.error( - "Failed to send rental approval confirmation email:", - error - ); + logger.error("Failed to send rental approval confirmation email", { error }); return { success: false, error: error.message }; } } @@ -410,7 +407,7 @@ class RentalFlowEmailService { htmlContent ); } catch (error) { - console.error("Failed to send rental declined email:", error); + logger.error("Failed to send rental declined email", { error }); return { success: false, error: error.message }; } } @@ -544,7 +541,7 @@ class RentalFlowEmailService { return await this.emailClient.sendEmail(userEmail, subject, htmlContent); } catch (error) { - console.error("Failed to send rental confirmation:", error); + logger.error("Failed to send rental confirmation", { error }); return { success: false, error: error.message }; } } @@ -608,21 +605,19 @@ class RentalFlowEmailService { false // isRenter = false for owner ); if (ownerResult.success) { - console.log( - `Rental confirmation email sent to owner: ${owner.email}` - ); + logger.info("Rental confirmation email sent to owner", { email: owner.email }); results.ownerEmailSent = true; } else { - console.error( - `Failed to send rental confirmation email to owner (${owner.email}):`, - ownerResult.error - ); + logger.error("Failed to send rental confirmation email to owner", { + email: owner.email, + error: ownerResult.error, + }); } } catch (error) { - console.error( - `Failed to send rental confirmation email to owner (${owner.email}):`, - error.message - ); + logger.error("Failed to send rental confirmation email to owner", { + email: owner.email, + error, + }); } } @@ -637,28 +632,23 @@ class RentalFlowEmailService { true // isRenter = true for renter (enables payment receipt) ); if (renterResult.success) { - console.log( - `Rental confirmation email sent to renter: ${renter.email}` - ); + logger.info("Rental confirmation email sent to renter", { email: renter.email }); results.renterEmailSent = true; } else { - console.error( - `Failed to send rental confirmation email to renter (${renter.email}):`, - renterResult.error - ); + logger.error("Failed to send rental confirmation email to renter", { + email: renter.email, + error: renterResult.error, + }); } } catch (error) { - console.error( - `Failed to send rental confirmation email to renter (${renter.email}):`, - error.message - ); + logger.error("Failed to send rental confirmation email to renter", { + email: renter.email, + error, + }); } } } catch (error) { - console.error( - "Error fetching user data for rental confirmation emails:", - error - ); + logger.error("Error fetching user data for rental confirmation emails", { error }); } return results; @@ -824,16 +814,17 @@ class RentalFlowEmailService { ); if (confirmationResult.success) { - console.log( - `Cancellation confirmation email sent to ${cancelledBy}: ${confirmationRecipient}` - ); + logger.info("Cancellation confirmation email sent", { + cancelledBy, + email: confirmationRecipient, + }); results.confirmationEmailSent = true; } } catch (error) { - console.error( - `Failed to send cancellation confirmation email to ${cancelledBy}:`, - error.message - ); + logger.error("Failed to send cancellation confirmation email", { + cancelledBy, + error, + }); } // Send notification email to other party @@ -860,21 +851,17 @@ class RentalFlowEmailService { ); if (notificationResult.success) { - console.log( - `Cancellation notification email sent to ${ - cancelledBy === "owner" ? "renter" : "owner" - }: ${notificationRecipient}` - ); + logger.info("Cancellation notification email sent", { + recipientType: cancelledBy === "owner" ? "renter" : "owner", + email: notificationRecipient, + }); results.notificationEmailSent = true; } } catch (error) { - console.error( - `Failed to send cancellation notification email:`, - error.message - ); + logger.error("Failed to send cancellation notification email", { error }); } } catch (error) { - console.error("Error sending cancellation emails:", error); + logger.error("Error sending cancellation emails", { error }); } return results; @@ -991,15 +978,13 @@ class RentalFlowEmailService { ); if (renterResult.success) { - console.log( - `Rental completion thank you email sent to renter: ${renter.email}` - ); + logger.info("Rental completion thank you email sent to renter", { email: renter.email }); results.renterEmailSent = true; } else { - console.error( - `Failed to send rental completion email to renter (${renter.email}):`, - renterResult.error - ); + logger.error("Failed to send rental completion email to renter", { + email: renter.email, + error: renterResult.error, + }); } } catch (emailError) { logger.error("Failed to send rental completion email to renter", { @@ -1111,15 +1096,13 @@ class RentalFlowEmailService { ); if (ownerResult.success) { - console.log( - `Rental completion congratulations email sent to owner: ${owner.email}` - ); + logger.info("Rental completion congratulations email sent to owner", { email: owner.email }); results.ownerEmailSent = true; } else { - console.error( - `Failed to send rental completion email to owner (${owner.email}):`, - ownerResult.error - ); + logger.error("Failed to send rental completion email to owner", { + email: owner.email, + error: ownerResult.error, + }); } } catch (emailError) { logger.error("Failed to send rental completion email to owner", { @@ -1205,7 +1188,7 @@ class RentalFlowEmailService { htmlContent ); } catch (error) { - console.error("Failed to send payout received email:", error); + logger.error("Failed to send payout received email", { error }); return { success: false, error: error.message }; } } @@ -1249,7 +1232,7 @@ class RentalFlowEmailService { htmlContent ); } catch (error) { - console.error("Failed to send authentication required email:", error); + logger.error("Failed to send authentication required email", { error }); return { success: false, error: error.message }; } } diff --git a/backend/services/email/domain/RentalReminderEmailService.js b/backend/services/email/domain/RentalReminderEmailService.js index af69c58..483967a 100644 --- a/backend/services/email/domain/RentalReminderEmailService.js +++ b/backend/services/email/domain/RentalReminderEmailService.js @@ -1,5 +1,6 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); +const logger = require("../../../utils/logger"); /** * RentalReminderEmailService handles rental reminder emails @@ -26,7 +27,7 @@ class RentalReminderEmailService { ]); this.initialized = true; - console.log("Rental Reminder Email Service initialized successfully"); + logger.info("Rental Reminder Email Service initialized successfully"); } /** @@ -68,7 +69,7 @@ class RentalReminderEmailService { htmlContent ); } catch (error) { - console.error("Failed to send condition check reminder:", error); + logger.error("Failed to send condition check reminder:", error); return { success: false, error: error.message }; } } diff --git a/backend/services/email/domain/UserEngagementEmailService.js b/backend/services/email/domain/UserEngagementEmailService.js index 2deb4b9..1ce30f9 100644 --- a/backend/services/email/domain/UserEngagementEmailService.js +++ b/backend/services/email/domain/UserEngagementEmailService.js @@ -1,5 +1,6 @@ const EmailClient = require("../core/EmailClient"); const TemplateManager = require("../core/TemplateManager"); +const logger = require("../../../utils/logger"); /** * UserEngagementEmailService handles user engagement emails @@ -27,7 +28,7 @@ class UserEngagementEmailService { ]); this.initialized = true; - console.log("User Engagement Email Service initialized successfully"); + logger.info("User Engagement Email Service initialized successfully"); } /** @@ -68,7 +69,7 @@ class UserEngagementEmailService { htmlContent ); } catch (error) { - console.error("Failed to send first listing celebration email:", error); + logger.error("Failed to send first listing celebration email", { error }); return { success: false, error: error.message }; } } @@ -114,7 +115,7 @@ class UserEngagementEmailService { htmlContent ); } catch (error) { - console.error("Failed to send item deletion notification email:", error); + logger.error("Failed to send item deletion notification email", { error }); return { success: false, error: error.message }; } } @@ -158,14 +159,14 @@ class UserEngagementEmailService { ); if (result.success) { - console.log( - `User banned notification email sent to ${bannedUser.email}` - ); + logger.info("User banned notification email sent", { + email: bannedUser.email, + }); } return result; } catch (error) { - console.error("Failed to send user banned notification email:", error); + logger.error("Failed to send user banned notification email", { error }); return { success: false, error: error.message }; } } diff --git a/backend/services/googleMapsService.js b/backend/services/googleMapsService.js index ae4a9b1..1378bd3 100644 --- a/backend/services/googleMapsService.js +++ b/backend/services/googleMapsService.js @@ -1,4 +1,5 @@ const { Client } = require('@googlemaps/google-maps-services-js'); +const logger = require('../utils/logger'); class GoogleMapsService { constructor() { @@ -6,9 +7,9 @@ class GoogleMapsService { this.apiKey = process.env.GOOGLE_MAPS_API_KEY; if (!this.apiKey) { - console.error('❌ Google Maps API key not configured in environment variables'); + logger.error('Google Maps API key not configured in environment variables'); } else { - console.log('✅ Google Maps service initialized'); + logger.info('Google Maps service initialized'); } } @@ -61,15 +62,15 @@ class GoogleMapsService { })) }; } else { - console.error('Places Autocomplete API error:', response.data.status, response.data.error_message); - return { + logger.error('Places Autocomplete API error', { status: response.data.status, errorMessage: response.data.error_message }); + return { predictions: [], error: this.getErrorMessage(response.data.status), status: response.data.status }; } } catch (error) { - console.error('Places Autocomplete service error:', error.message); + logger.error('Places Autocomplete service error', { error }); throw new Error('Failed to fetch place predictions'); } } @@ -145,11 +146,11 @@ class GoogleMapsService { } }; } else { - console.error('Place Details API error:', response.data.status, response.data.error_message); + logger.error('Place Details API error', { status: response.data.status, errorMessage: response.data.error_message }); throw new Error(this.getErrorMessage(response.data.status)); } } catch (error) { - console.error('Place Details service error:', error.message); + logger.error('Place Details service error', { error }); throw error; } } @@ -200,14 +201,14 @@ class GoogleMapsService { placeId: result.place_id }; } else { - console.error('Geocoding API error:', response.data.status, response.data.error_message); + logger.error('Geocoding API error', { status: response.data.status, errorMessage: response.data.error_message }); return { error: this.getErrorMessage(response.data.status), status: response.data.status }; } } catch (error) { - console.error('Geocoding service error:', error.message); + logger.error('Geocoding service error', { error }); throw new Error('Failed to geocode address'); } } diff --git a/backend/services/locationService.js b/backend/services/locationService.js index 63f37cc..8821935 100644 --- a/backend/services/locationService.js +++ b/backend/services/locationService.js @@ -1,5 +1,6 @@ const { sequelize } = require("../models"); const { QueryTypes } = require("sequelize"); +const logger = require("../utils/logger"); class LocationService { /** @@ -71,7 +72,7 @@ class LocationService { distance: parseFloat(user.distance).toFixed(2), // Round to 2 decimal places })); } catch (error) { - console.error("Error finding users in radius:", error); + logger.error("Error finding users in radius", { error }); throw new Error(`Failed to find users in radius: ${error.message}`); } } diff --git a/backend/services/refundService.js b/backend/services/refundService.js index 1198544..aa22019 100644 --- a/backend/services/refundService.js +++ b/backend/services/refundService.js @@ -1,6 +1,7 @@ const { Rental } = require("../models"); const StripeService = require("./stripeService"); const { isActive } = require("../utils/rentalStatus"); +const logger = require("../utils/logger"); class RefundService { /** @@ -161,13 +162,14 @@ class RefundService { stripeRefundId = refund.id; refundProcessedAt = new Date(); } catch (error) { - console.error("Error processing Stripe refund:", error); + logger.error("Error processing Stripe refund", { error }); throw new Error(`Failed to process refund: ${error.message}`); } } else if (refundCalculation.refundAmount > 0) { // Log warning if we should refund but don't have payment intent - console.warn( - `Refund amount calculated but no payment intent ID for rental ${rentalId}` + logger.warn( + "Refund amount calculated but no payment intent ID for rental", + { rentalId } ); }