Comparing version 2.11.2 to 2.11.3
@@ -71,7 +71,8 @@ 'use strict'; | ||
}; | ||
Logs.logCustomMessage(level, message, metadata, errsoleLogId); | ||
const timestamp = new Date().toISOString(); | ||
Logs.logCustomMessage(level, message, metadata, errsoleLogId, timestamp); | ||
if (this.isInitializated) { | ||
await Alerts.customLoggerAlert(message, messageExtraInfo, errsoleLogId); | ||
await Alerts.customLoggerAlert(message, messageExtraInfo, errsoleLogId, timestamp); | ||
} else { | ||
this.pendingAlerts.push({ message, messageExtraInfo, errsoleLogId }); | ||
this.pendingAlerts.push({ message, messageExtraInfo, errsoleLogId, timestamp }); | ||
} | ||
@@ -95,6 +96,7 @@ } else { | ||
if (this.isInitializated) { | ||
const timestamp = new Date().toISOString(); | ||
const errsoleLogId = this.generateUniqueId(); | ||
Logs.logCustomMessage('alert', `${errorOrigin}\n${errorMessage}`, '{}', errsoleLogId); | ||
Logs.logCustomMessage('alert', `${errorOrigin}\n${errorMessage}`, '{}', errsoleLogId, timestamp); | ||
await Logs.flushLogs(); | ||
await Alerts.handleUncaughtExceptions(`${errorOrigin}\n${errorMessage}`, messageExtraInfo, errsoleLogId); | ||
await Alerts.handleUncaughtExceptions(`${errorOrigin}\n${errorMessage}`, messageExtraInfo, errsoleLogId, timestamp); | ||
} | ||
@@ -123,5 +125,6 @@ if (exitOnException) process.exit(1); | ||
const errsoleLogId = self.generateUniqueId(); | ||
Logs.logCustomMessage('alert', `The app has stopped with the signal ${signalEvent.key} - ${signalEvent.value}`, '{}', errsoleLogId); | ||
const timestamp = new Date().toISOString(); | ||
Logs.logCustomMessage('alert', `The app has stopped with the signal ${signalEvent.key} - ${signalEvent.value}`, '{}', errsoleLogId, timestamp); | ||
await Logs.flushLogs(); | ||
await Alerts.customLoggerAlert(`The app has stopped with the signal ${signalEvent.key} - ${signalEvent.value}`, messageExtraInfo, errsoleLogId); | ||
await Alerts.customLoggerAlert(`The app has stopped with the signal ${signalEvent.key} - ${signalEvent.value}`, messageExtraInfo, errsoleLogId, timestamp); | ||
} | ||
@@ -139,4 +142,4 @@ process.exit(0); | ||
for (let i = 0; i < alertsToFlush.length; i++) { | ||
const { message, messageExtraInfo, errsoleLogId } = alertsToFlush[i]; | ||
await Alerts.customLoggerAlert(message, messageExtraInfo, errsoleLogId); | ||
const { message, messageExtraInfo, errsoleLogId, timestamp } = alertsToFlush[i]; | ||
await Alerts.customLoggerAlert(message, messageExtraInfo, errsoleLogId, timestamp); | ||
} | ||
@@ -143,0 +146,0 @@ } catch (err) { |
@@ -141,5 +141,5 @@ const stream = require('stream'); | ||
logCustomMessage (level, message, metadata, errsoleId) { | ||
logCustomMessage (level, message, metadata, errsoleId, timestamp) { | ||
const logEntry = { | ||
timestamp: new Date().toISOString(), | ||
timestamp: timestamp || new Date().toISOString(), | ||
message, | ||
@@ -146,0 +146,0 @@ meta: metadata || '{}', |
@@ -7,3 +7,3 @@ const { getStorageConnection } = require('../storageConnection'); | ||
// Improved handling by adding return statements and catching exceptions | ||
exports.customLoggerAlert = async function (message, messageExtraInfo, errsoleLogId) { | ||
exports.customLoggerAlert = async function (message, messageExtraInfo, errsoleLogId, timestamp) { | ||
try { | ||
@@ -15,4 +15,4 @@ // check for duplicate notifications | ||
} | ||
await SlackService.sendAlert(message, 'Alert', messageExtraInfo, errsoleLogId, todayCount); | ||
await EmailService.sendAlert(message, 'Alert', messageExtraInfo, errsoleLogId, todayCount); | ||
await SlackService.sendAlert(message, 'Alert', messageExtraInfo, errsoleLogId, todayCount, timestamp); | ||
await EmailService.sendAlert(message, 'Alert', messageExtraInfo, errsoleLogId, todayCount, timestamp); | ||
return true; | ||
@@ -25,3 +25,3 @@ } catch (error) { | ||
exports.handleUncaughtExceptions = async function (message, messageExtraInfo, errsoleLogId) { | ||
exports.handleUncaughtExceptions = async function (message, messageExtraInfo, errsoleLogId, timestamp) { | ||
try { | ||
@@ -33,4 +33,4 @@ // check for duplicate notifications | ||
} | ||
await SlackService.sendAlert(message, 'Uncaught Exception', messageExtraInfo, errsoleLogId, todayCount); | ||
await EmailService.sendAlert(message, 'Uncaught Exception', messageExtraInfo, errsoleLogId, todayCount); | ||
await SlackService.sendAlert(message, 'Uncaught Exception', messageExtraInfo, errsoleLogId, todayCount, timestamp); | ||
await EmailService.sendAlert(message, 'Uncaught Exception', messageExtraInfo, errsoleLogId, todayCount, timestamp); | ||
return true; // Successfully handled exception | ||
@@ -65,3 +65,3 @@ } catch (error) { | ||
SlackService.sendAlert = async function (message, type, messageExtraInfo, errsoleLogId, todayCount) { | ||
SlackService.sendAlert = async function (message, type, messageExtraInfo, errsoleLogId, todayCount, timestamp) { | ||
try { | ||
@@ -80,3 +80,9 @@ const storageConnection = getStorageConnection(); | ||
const parsedAlertUrlValue = JSON.parse(alertUrlData.item.value); | ||
alertUrl = parsedAlertUrlValue.url + '#/logs?errsole_log_id=' + errsoleLogId + '×tamp=' + new Date(new Date().getTime() + 2000).toISOString(); | ||
let alertTimestap; | ||
if (!timestamp) { | ||
alertTimestap = new Date(new Date().getTime() + 2000).toISOString(); | ||
} else { | ||
alertTimestap = roundUpToNextSecond(timestamp); | ||
} | ||
alertUrl = parsedAlertUrlValue.url + '#/logs?errsole_log_id=' + errsoleLogId + '×tamp=' + alertTimestap; | ||
} | ||
@@ -189,3 +195,3 @@ const webhookUrl = parsedValue.url; | ||
EmailService.sendAlert = async function (message, type, messageExtraInfo, errsoleLogId, todayCount) { | ||
EmailService.sendAlert = async function (message, type, messageExtraInfo, errsoleLogId, todayCount, timestamp) { | ||
try { | ||
@@ -206,3 +212,9 @@ await EmailService.emailTransport(); // Ensure transporter is ready | ||
const parsedAlertUrlValue = JSON.parse(alertUrlData.item.value); | ||
alertUrl = parsedAlertUrlValue.url + '#/logs?errsole_log_id=' + errsoleLogId + '×tamp=' + new Date(new Date().getTime() + 2000).toISOString(); | ||
let alertTimestap; | ||
if (!timestamp) { | ||
alertTimestap = new Date(new Date().getTime() + 2000).toISOString(); | ||
} else { | ||
alertTimestap = roundUpToNextSecond(timestamp); | ||
} | ||
alertUrl = parsedAlertUrlValue.url + '#/logs?errsole_log_id=' + errsoleLogId + '×tamp=' + alertTimestap; | ||
} | ||
@@ -333,3 +345,13 @@ // Construct the email subject and message | ||
// Function to round up to the next whole second | ||
function roundUpToNextSecond (date) { | ||
const roundedDate = new Date(date); // Clone to avoid mutating the original date | ||
if (roundedDate.getMilliseconds() > 0) { | ||
roundedDate.setSeconds(roundedDate.getSeconds() + 1); | ||
roundedDate.setMilliseconds(0); | ||
} | ||
return roundedDate; | ||
} | ||
exports.SlackService = SlackService; | ||
exports.EmailService = EmailService; |
{ | ||
"name": "errsole", | ||
"version": "2.11.2", | ||
"version": "2.11.3", | ||
"description": "Collect, Store, and Visualize Logs with a Single Module", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -60,2 +60,5 @@ <p align="center"> | ||
#### AWS | ||
* Errsole with CloudWatch (Upcoming) | ||
#### Advanced Configuration | ||
@@ -77,6 +80,11 @@ | ||
#### Pino with Errsole (Upcoming) | ||
## FAQs | ||
* [How can I resolve the "Error: listen EADDRINUSE: address already in use :::8001" error?](https://github.com/errsole/errsole.js/discussions/91) | ||
* [How can I run the Errsole Dashboard on a separate server from my app?](https://github.com/errsole/errsole.js/discussions/113) | ||
## Useful Links | ||
* [FAQs](https://github.com/errsole/errsole.js/discussions/categories/faqs) | ||
* **Encountering issues?** [Open an issue](https://github.com/errsole/errsole.js/issues/new) on our GitHub repository. | ||
@@ -83,0 +91,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2419729
2849
99