I am currently working on enhancing the functionality of my custom logging system for DB operations. My goal is to generate a more visually appealing and organized format in the console by adding an additional variable called operationName
to the log messages upon completion of a DB operation.
// Customized Logger (Simplified)
const dbLogger = (error, data, operationName) => {
if (error) {
console.log(`${operationName} failed`, error)
}
console.log(`${operationName} success`, data)
}
// MongoDB Operations
import ChatModel from 'somewhere';
function createMessage() {
const newChatAdded = new ChatModel({
message: 'Hi'
})
ChatModel.save(newChatAdded, dbLogger);
}
In this setup, the callback parameters error and data are passed by the ChatModel.save
method. However, my intention is to introduce a third parameter operationName (e.g., 'save' or 'delete') to further customize the log messages.