diff --git a/src/device-registry/utils/create-event.js b/src/device-registry/utils/create-event.js index 4e7d654141..6715419182 100644 --- a/src/device-registry/utils/create-event.js +++ b/src/device-registry/utils/create-event.js @@ -2,7 +2,12 @@ const EventModel = require("@models/Event"); const ReadingModel = require("@models/Reading"); const SignalModel = require("@models/Signal"); const DeviceModel = require("@models/Device"); -const { logObject, logElement, logText } = require("./log"); +const { + logObject, + logElement, + logText, + logTextWithTimestamp, +} = require("./log"); const constants = require("@config/constants"); const generateFilter = require("./generate-filter"); const isEmpty = require("is-empty"); @@ -2624,7 +2629,7 @@ const createEvent = { } if (errors.length > 0 && isEmpty(eventsAdded)) { - console.log( + logTextWithTimestamp( "API: failed to store measurements, most likely DB cast errors or duplicate records" ); return { @@ -2634,7 +2639,7 @@ const createEvent = { status: httpStatus.INTERNAL_SERVER_ERROR, }; } else { - console.log("API: successfully added the events"); + logTextWithTimestamp("API: successfully added the events"); return { success: true, message: "successfully added the events", @@ -2643,6 +2648,7 @@ const createEvent = { }; } } catch (error) { + logTextWithTimestamp(`API: Internal Server Error ${error.message}`); logger.error(`🐛🐛 Internal Server Error ${error.message}`); next( new HttpError( diff --git a/src/device-registry/utils/log.js b/src/device-registry/utils/log.js index d9e797b297..4fe2129e9d 100644 --- a/src/device-registry/utils/log.js +++ b/src/device-registry/utils/log.js @@ -1,3 +1,5 @@ +const moment = require("moment"); + const logText = (message) => { if (process.env.NODE_ENV !== "production") { console.log(message); @@ -28,4 +30,14 @@ const logError = (error) => { return "log deactivated in prod and stage"; }; -module.exports = { logText, logElement, logObject, logError }; +const logTextWithTimestamp = (message) => { + console.log(`[${moment().format("YYYY-MM-DD HH:mm:ss")}] ${message}`); +}; + +module.exports = { + logText, + logTextWithTimestamp, + logElement, + logObject, + logError, +};