diff --git a/CommonServer/Utils/Response.ts b/CommonServer/Utils/Response.ts index 36a1ae84fc..de13e75a9b 100644 --- a/CommonServer/Utils/Response.ts +++ b/CommonServer/Utils/Response.ts @@ -28,27 +28,35 @@ export default class Response { const requestEndedAt: Date = new Date(); const method: string = oneUptimeRequest.method; - const url: URL = URL.fromString(oneUptimeRequest.url); + const path: string = oneUptimeRequest.originalUrl.toString(); - const header_info: string = `Response ID: ${ - oneUptimeRequest.id - } -- POD NAME: ${ - process.env['POD_NAME'] || 'NONE' - } -- METHOD: ${method} -- URL: ${url.toString()} -- DURATION: ${( - requestEndedAt.getTime() - - (oneUptimeRequest.requestStartedAt as Date).getTime() - ).toString()}ms -- STATUS: ${oneUptimeResponse.statusCode}`; + const logLine: JSONObject = { + 'Request ID': `${oneUptimeRequest.id}`, - const body_info: string = `Response ID: ${ - oneUptimeRequest.id - } -- RESPONSE BODY: ${ - responsebody ? JSON.stringify(responsebody, null, 2) : 'EMPTY' - }`; + 'Pod Name': `${process.env['POD_NAME'] || 'NONE'}`, + + 'HTTP Method': `${method}`, + + 'Path': `${path.toString()}`, + + 'Request Duration': `${( + requestEndedAt.getTime() - + (oneUptimeRequest.requestStartedAt as Date).getTime() + ).toString()}ms`, + + 'Response Status': `${oneUptimeResponse.statusCode}`, + + 'Host': `${oneUptimeRequest.hostname}`, + + 'Response body': `${ + responsebody ? JSON.stringify(responsebody, null, 2) : 'EMPTY' + }`, + }; if (oneUptimeResponse.statusCode > 299) { - logger.error(header_info + '\n ' + body_info); + logger.error(logLine); } else { - logger.info(header_info + '\n ' + body_info); + logger.info(logLine); } } diff --git a/Notification/Services/CallService.ts b/Notification/Services/CallService.ts index 96d01323b7..ab3041beec 100644 --- a/Notification/Services/CallService.ts +++ b/Notification/Services/CallService.ts @@ -74,6 +74,7 @@ export default class CallService { if (!project) { callLog.status = CallStatus.Error; callLog.statusMessage = `Project ${options.projectId.toString()} not found.`; + logger.error(callLog.statusMessage); await CallLogService.create({ data: callLog, props: { @@ -86,7 +87,7 @@ export default class CallService { if (!project.enableCallNotifications) { callLog.status = CallStatus.Error; callLog.statusMessage = `Call notifications are not enabled for this project. Please enable Call notifications in Project Settings.`; - + logger.error(callLog.statusMessage); await CallLogService.create({ data: callLog, props: { @@ -132,6 +133,7 @@ export default class CallService { if (!project.smsOrCallCurrentBalanceInUSDCents) { callLog.status = CallStatus.LowBalance; callLog.statusMessage = `Project ${options.projectId.toString()} does not have enough Call balance.`; + logger.error(callLog.statusMessage); await CallLogService.create({ data: callLog, props: { @@ -175,6 +177,7 @@ export default class CallService { } USD. Required balance is ${ CallDefaultCostInCentsPerMinute / 100 } USD to make this call.`; + logger.error(callLog.statusMessage); await CallLogService.create({ data: callLog, props: { @@ -218,7 +221,8 @@ export default class CallService { callLog.status = CallStatus.Success; callLog.statusMessage = 'Call ID: ' + twillioCall.sid; - + logger.info('Call Request sent successfully.'); + logger.info(callLog.statusMessage); if (IsBillingEnabled && project) { callLog.callCostInUSDCents = CallDefaultCostInCentsPerMinute; @@ -251,6 +255,9 @@ export default class CallService { callLog.status = CallStatus.Error; callLog.statusMessage = e && e.message ? e.message.toString() : e.toString(); + + logger.error('Call Request failed.'); + logger.error(callLog.statusMessage); } if (options.projectId) { diff --git a/Notification/Services/SmsService.ts b/Notification/Services/SmsService.ts index e0fac14f08..7ff18d2227 100644 --- a/Notification/Services/SmsService.ts +++ b/Notification/Services/SmsService.ts @@ -71,6 +71,7 @@ export default class SmsService { if (!project) { smsLog.status = SmsStatus.Error; smsLog.statusMessage = `Project ${options.projectId.toString()} not found.`; + logger.error(smsLog.statusMessage); await SmsLogService.create({ data: smsLog, props: { @@ -83,7 +84,7 @@ export default class SmsService { if (!project.enableSmsNotifications) { smsLog.status = SmsStatus.Error; smsLog.statusMessage = `SMS notifications are not enabled for this project. Please enable SMS notifications in Project Settings.`; - + logger.error(smsLog.statusMessage); await SmsLogService.create({ data: smsLog, props: { @@ -128,6 +129,7 @@ export default class SmsService { if (!project.smsOrCallCurrentBalanceInUSDCents) { smsLog.status = SmsStatus.LowBalance; smsLog.statusMessage = `Project ${options.projectId.toString()} does not have enough SMS balance.`; + logger.error(smsLog.statusMessage); await SmsLogService.create({ data: smsLog, props: { @@ -171,6 +173,7 @@ export default class SmsService { } USD. Required balance is ${ SMSDefaultCostInCents / 100 } USD to send this SMS.`; + logger.error(smsLog.statusMessage); await SmsLogService.create({ data: smsLog, props: { @@ -216,6 +219,9 @@ export default class SmsService { smsLog.status = SmsStatus.Success; smsLog.statusMessage = 'Message ID: ' + twillioMessage.sid; + logger.info('SMS message sent successfully.'); + logger.info(smsLog.statusMessage); + if (IsBillingEnabled && project) { smsLog.smsCostInUSDCents = SMSDefaultCostInCents; @@ -241,6 +247,9 @@ export default class SmsService { smsLog.status = SmsStatus.Error; smsLog.statusMessage = e && e.message ? e.message.toString() : e.toString(); + + logger.error('SMS message failed to send.'); + logger.error(smsLog.statusMessage); } if (options.projectId) {