Skip to content

Commit

Permalink
replace console.log statements with logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhollid committed Oct 24, 2024
1 parent 4601d46 commit 268ad69
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
14 changes: 9 additions & 5 deletions Server/db/models/PageSpeedCheck.js
Original file line number Diff line number Diff line change
@@ -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 },
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 4 additions & 1 deletion Server/db/models/User.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import mongoose from "mongoose";
import bcrypt from "bcrypt";
import logger from "../../utils/logger.js";

const UserSchema = mongoose.Schema(
{
Expand Down Expand Up @@ -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);
20 changes: 16 additions & 4 deletions Server/db/mongo/modules/checkModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ const getChecksCount = async (req) => {
checksQuery.statusCode = 5000;
break;
default:
console.log("default");
logger.warn({
message: "invalid filter",
service: SERVICE_NAME,
method: "getChecksCount",
});
break;
}
}
Expand Down Expand Up @@ -112,7 +116,7 @@ const getChecks = async (req) => {
if (dateRange !== undefined) {
checksQuery.createdAt = { $gte: dateRangeLookup[dateRange] };
}
// Fitler checks by status
// Filter checks by status
if (filter !== undefined) {
checksQuery.status = false;
switch (filter) {
Expand All @@ -124,7 +128,11 @@ const getChecks = async (req) => {
checksQuery.statusCode = 5000;
break;
default:
console.log("default");
logger.warn({
message: "invalid filter",
service: SERVICE_NAME,
method: "getChecks",
});
break;
}
}
Expand Down Expand Up @@ -172,7 +180,11 @@ const getTeamChecks = async (req) => {
checksQuery.statusCode = 5000;
break;
default:
console.log("default");
logger.warn({
message: "invalid filter",
service: SERVICE_NAME,
method: "getTeamChecks",
});
break;
}
}
Expand Down
1 change: 0 additions & 1 deletion Server/db/mongo/modules/maintenanceWindowModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ const deleteMaintenanceWindowByUserId = async (userId) => {
};

const editMaintenanceWindowById = async (maintenanceWindowId, maintenanceWindowData) => {
console.log(maintenanceWindowData);
try {
const editedMaintenanceWindow = MaintenanceWindow.findByIdAndUpdate(
maintenanceWindowId,
Expand Down
2 changes: 1 addition & 1 deletion Server/service/jobQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class JobQueue {
*/
async addJob(jobName, payload) {
try {
console.log("Adding job", payload?.url ?? "No URL");
this.logger.info({ message: `Adding job ${payload?.url ?? "No URL"}` });
// Execute job immediately
await this.queue.add(jobName, payload);
await this.queue.add(jobName, payload, {
Expand Down

0 comments on commit 268ad69

Please sign in to comment.