Skip to content

Commit

Permalink
[feat]: added winston logger
Browse files Browse the repository at this point in the history
  • Loading branch information
VineeTagarwaL-code committed Oct 19, 2024
1 parent 3965940 commit 99c8a35
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
10 changes: 10 additions & 0 deletions packages/order-queue/logs/server.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ 2024-10-19 19:59:55 ] - info - WORKER | Starting order worker
[ 2024-10-19 20:00:56 ] - info - WORKER | Starting order worker
[ 2024-10-19 20:00:56 ] - info - SERVER | REDIS: Connected to Redis
[ 2024-10-19 20:00:56 ] - info - SERVER | REDIS: Redis connection is ready
[ 2024-10-19 20:01:12 ] - info - WORKER | Starting order worker
[ 2024-10-19 20:01:12 ] - info - SERVER | REDIS: Connected to Redis
[ 2024-10-19 20:01:12 ] - info - SERVER | REDIS: Redis connection is ready
[ 2024-10-19 20:02:18 ] - info - WORKER | Starting order worker
[ 2024-10-19 20:02:18 ] - info - SERVER | REDIS: Connected to Redis
[ 2024-10-19 20:02:18 ] - info - SERVER | REDIS: Redis connection is ready to start execution
1 change: 1 addition & 0 deletions packages/order-queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@opinix/logger": "*",
"dotenv": "^16.4.5",
"nodemon": "^3.1.7",
"redis": "^4.7.0"
Expand Down
13 changes: 8 additions & 5 deletions packages/order-queue/src/config/redisClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import IORedis, { Redis } from "ioredis";
import "dotenv/config";
import { logger } from "@opinix/logger";
const redisUri = process.env.REDIS_URI || "redis://localhost:6379";
let redisParams = {
maxRetriesPerRequest: null,
Expand All @@ -11,23 +12,25 @@ const getRedisClient = () => {
...redisParams,
});
redisClient.on("connect", () => {
console.info("SERVER | REDIS: Connected to Redis");
logger.info("SERVER | REDIS: Connected to Redis");
});

redisClient.on("ready", () => {
console.info("SERVER | REDIS: Redis connection is ready");
logger.info(
"SERVER | REDIS: Redis connection is ready to start execution"
);
});

redisClient.on("error", (err) => {
console.error("SERVER: ERROR Connecting to Redis", err);
logger.error("SERVER: ERROR Connecting to Redis", err);
});

redisClient.on("close", () => {
console.warn("SERVER | REDIS: Connection closed");
logger.warn("SERVER | REDIS: Connection closed");
});

redisClient.on("reconnecting", () => {
console.info("SERVER | REDIS: Reconnecting...");
logger.info("SERVER | REDIS: Reconnecting...");
});
}
return redisClient;
Expand Down
3 changes: 2 additions & 1 deletion packages/order-queue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { addToOrderQueue } from "./queues/orderQueue";
import orderWorker from "./queues/orderProcessor";
import { logger } from "@opinix/logger";
const startWorker = async () => {
console.log("Starting Order Queue Worker...");
logger.info("WORKER | Starting order worker");
orderWorker;
};

Expand Down

0 comments on commit 99c8a35

Please sign in to comment.