replace console.log statements with logger

This commit is contained in:
Alex Holliday committed 2024-10-24 15:35:30 +08:00
1 parent 4601d46371
commit 268ad695bf
5 files changed
+30 -12

No files matched your search

+9 -5
View File
@@ -1,4 +1,5 @@
import mongoose from "mongoose";
import logger from "../../utils/logger.js";
const AuditSchema = mongoose.Schema({
id: { type: String, required: true },
title: { type: String, required: true },
@@ -90,19 +91,22 @@ PageSpeedCheck.pre("save", async function (next) {
const monitor = await mongoose.model("Monitor").findById(this.monitorId);
if (monitor && monitor.status !== this.status) {
if (monitor.status === true && this.status === false) {
// TODO issue alert
console.log("Monitor went down");
logger.info({ message: "Monitor went down", monitorId: monitor._id });
}
if (monitor.status === false && this.status === true) {
// TODO issue alert
console.log("Monitor went up");
logger.info({ message: "Monitor went up", monitorId: monitor._id });
}
monitor.status = this.status;
await monitor.save();
}
} catch (error) {
console.log(error);
logger.error({
message: error.message,
service: "PageSpeedCheck",
method: "pre-save",
stack: error.stack,
});
} finally {
next();
}
+4 -1
View File
@@ -1,5 +1,6 @@
import mongoose from "mongoose";
import bcrypt from "bcrypt";
import logger from "../../utils/logger.js";
const UserSchema = mongoose.Schema(
{
@@ -81,7 +82,9 @@ UserSchema.methods.comparePassword = async function (submittedPassword) {
const User = mongoose.model("User", UserSchema);
User.init().then(() => {
console.log("User model initialized");
logger.info({
message: "User model initialized",
});
});
export default mongoose.model("User", UserSchema);