gemercheung 3 rokov pred
rodič
commit
f53e1e88f3

+ 0 - 7
combined.log

@@ -1,7 +0,0 @@
-2022-01-23 12:57:15 info: urlredis://:redis9394@localhost:6379 
-2022-01-23 12:57:15 debug: Total Number of Cores: %o 
-2022-01-23 12:57:15 debug: Master 14785 is running 
-2022-01-23 12:57:18 info: 房主自动创建房间:{"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001"} 
-2022-01-23 12:57:19 info: 房主自动创建房间:{"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001"} 
-2022-01-23 12:57:32 info: 房主自动创建房间:{"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001"} 
-2022-01-23 12:57:34 info: 房主自动创建房间:{"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001"} 

+ 153 - 0
logs/combined.log

@@ -0,0 +1,153 @@
+[Jan 24, 2022 11:30] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:30] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:30] debug  Master 8419 is running 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA8hxQ","isLogin":true}}
+[Jan 24, 2022 11:30] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:30] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:30] debug  Master 8465 is running 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  redis is conetcted 
+[Jan 24, 2022 11:30] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA8lZr","isLogin":true}}
+[Jan 24, 2022 11:31] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA8ocD","isLogin":true}}
+[Jan 24, 2022 11:31] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:31] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:31] debug  Master 8505 is running 
+[Jan 24, 2022 11:31] debug  redis is conetcted 
+[Jan 24, 2022 11:31] debug  redis is conetcted 
+[Jan 24, 2022 11:31] debug  redis is conetcted 
+[Jan 24, 2022 11:31] debug  redis is conetcted 
+[Jan 24, 2022 11:31] debug  redis is conetcted 
+[Jan 24, 2022 11:32] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA90JZ","isLogin":true}}
+[Jan 24, 2022 11:32] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:32] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:32] debug  Master 8547 is running 
+[Jan 24, 2022 11:32] debug  redis is conetcted 
+[Jan 24, 2022 11:32] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:32] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:32] debug  Master 8568 is running 
+[Jan 24, 2022 11:32] debug  redis is conetcted 
+[Jan 24, 2022 11:32] debug  redis is conetcted 
+[Jan 24, 2022 11:32] debug  redis is conetcted 
+[Jan 24, 2022 11:32] debug  redis is conetcted 
+[Jan 24, 2022 11:32] debug  redis is conetcted 
+[Jan 24, 2022 11:32] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA94wG","isLogin":true}}
+[Jan 24, 2022 11:34:59] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:34:59] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:34:59] debug  Master 8718 is running 
+[Jan 24, 2022 11:35:00] debug  redis is conetcted 
+[Jan 24, 2022 11:35:01] debug  redis is conetcted 
+[Jan 24, 2022 11:35:01] debug  redis is conetcted 
+[Jan 24, 2022 11:35:02] debug  redis is conetcted 
+[Jan 24, 2022 11:35:02] debug  redis is conetcted 
+[Jan 24, 2022 11:35:23] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA9n1r","isLogin":true}}
+[Jan 24, 2022 11:35:26] info  redis url:redis://:redis9394@localhost:6379 {"message":"url:redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:35:26] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:35:26] debug  Master 8804 is running 
+[Jan 24, 2022 11:35:26] debug  redis is conetcted 
+[Jan 24, 2022 11:35:28] debug  redis is conetcted 
+[Jan 24, 2022 11:35:28] debug  redis is conetcted 
+[Jan 24, 2022 11:35:28] debug  redis is conetcted 
+[Jan 24, 2022 11:35:28] debug  redis is conetcted 
+[Jan 24, 2022 11:35:29] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA9oWJ","isLogin":true}}
+[Jan 24, 2022 11:36:12] info  redis "redis://:redis9394@localhost:6379"
+[Jan 24, 2022 11:36:12] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:36:12] debug  Master 8848 is running 
+[Jan 24, 2022 11:36:13] debug  redis is conetcted 
+[Jan 24, 2022 11:36:16] debug  redis is conetcted 
+[Jan 24, 2022 11:36:16] debug  redis is conetcted 
+[Jan 24, 2022 11:36:16] debug  redis is conetcted 
+[Jan 24, 2022 11:36:16] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwA9zUG","isLogin":true}}
+[Jan 24, 2022 11:36:16] debug  redis is conetcted 
+[Jan 24, 2022 11:36:41] info  redis {"0":"r","1":"e","2":"d","3":"i","4":"s","5":":","6":"/","7":"/","8":":","9":"r","10":"e","11":"d","12":"i","13":"s","14":"9","15":"3","16":"9","17":"4","18":"@","19":"l","20":"o","21":"c","22":"a","23":"l","24":"h","25":"o","26":"s","27":"t","28":":","29":"6","30":"3","31":"7","32":"9"}
+[Jan 24, 2022 11:36:41] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:36:41] debug  Master 8899 is running 
+[Jan 24, 2022 11:36:42] debug  redis is conetcted 
+[Jan 24, 2022 11:36:44] debug  redis is conetcted 
+[Jan 24, 2022 11:36:44] debug  redis is conetcted 
+[Jan 24, 2022 11:36:44] debug  redis is conetcted 
+[Jan 24, 2022 11:36:44] debug  redis is conetcted 
+[Jan 24, 2022 11:36:58] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:36:59] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:36:59] debug  Master 8937 is running 
+[Jan 24, 2022 11:36:59] debug  redis is conetcted 
+[Jan 24, 2022 11:37:01] debug  redis is conetcted 
+[Jan 24, 2022 11:37:01] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAA8uF","isLogin":true}}
+[Jan 24, 2022 11:37:01] debug  redis is conetcted 
+[Jan 24, 2022 11:37:01] debug  redis is conetcted 
+[Jan 24, 2022 11:37:01] debug  redis is conetcted 
+[Jan 24, 2022 11:37:32] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:37:32] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:37:32] debug  Master 8975 is running 
+[Jan 24, 2022 11:37:33] debug  redis is conetcted 
+[Jan 24, 2022 11:37:35] debug  redis is conetcted 
+[Jan 24, 2022 11:37:36] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:37:36] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:37:36] debug  Master 8997 is running 
+[Jan 24, 2022 11:37:37] debug  redis is conetcted 
+[Jan 24, 2022 11:37:38] debug  redis is conetcted 
+[Jan 24, 2022 11:37:38] debug  redis is conetcted 
+[Jan 24, 2022 11:37:38] debug  redis is conetcted 
+[Jan 24, 2022 11:37:38] debug  redis is conetcted 
+[Jan 24, 2022 11:37:48] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:37:49] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:37:49] debug  Master 9028 is running 
+[Jan 24, 2022 11:37:49] debug  redis is conetcted 
+[Jan 24, 2022 11:37:50] debug  redis is conetcted 
+[Jan 24, 2022 11:37:50] debug  redis is conetcted 
+[Jan 24, 2022 11:37:50] debug  redis is conetcted 
+[Jan 24, 2022 11:37:50] debug  redis is conetcted 
+[Jan 24, 2022 11:37:52] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAALPA","isLogin":true}}
+[Jan 24, 2022 11:38:00] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:38:00] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:38:00] debug  Master 9056 is running 
+[Jan 24, 2022 11:38:00] debug  redis is conetcted 
+[Jan 24, 2022 11:38:02] debug  redis is conetcted 
+[Jan 24, 2022 11:38:02] debug  redis is conetcted 
+[Jan 24, 2022 11:38:02] debug  redis is conetcted 
+[Jan 24, 2022 11:38:02] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAANi2","isLogin":true}}
+[Jan 24, 2022 11:38:02] debug  redis is conetcted 
+[Jan 24, 2022 11:38:15] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:38:15] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:38:15] debug  Master 9093 is running 
+[Jan 24, 2022 11:38:15] debug  redis is conetcted 
+[Jan 24, 2022 11:38:17] debug  redis is conetcted 
+[Jan 24, 2022 11:38:18] debug  redis is conetcted 
+[Jan 24, 2022 11:38:18] debug  redis is conetcted 
+[Jan 24, 2022 11:38:18] debug  redis is conetcted 
+[Jan 24, 2022 11:38:18] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAARkK","isLogin":true}}
+[Jan 24, 2022 11:38:47] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:38:47] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:38:47] debug  Master 9125 is running 
+[Jan 24, 2022 11:38:48] debug  redis is conetcted 
+[Jan 24, 2022 11:38:50] debug  redis is conetcted 
+[Jan 24, 2022 11:38:50] debug  redis is conetcted 
+[Jan 24, 2022 11:38:50] debug  redis is conetcted 
+[Jan 24, 2022 11:38:50] debug  redis is conetcted 
+[Jan 24, 2022 11:38:54] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:38:54] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:38:54] debug  Master 9148 is running 
+[Jan 24, 2022 11:38:54] debug  redis is conetcted 
+[Jan 24, 2022 11:38:56] debug  redis is conetcted 
+[Jan 24, 2022 11:38:56] debug  redis is conetcted 
+[Jan 24, 2022 11:38:56] debug  redis is conetcted 
+[Jan 24, 2022 11:38:56] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAAb69","isLogin":true}}
+[Jan 24, 2022 11:38:56] debug  redis is conetcted 
+[Jan 24, 2022 11:39:00] info  redis {"url":"redis://:redis9394@localhost:6379"}
+[Jan 24, 2022 11:39:00] debug  Total Number of Cores:4 
+[Jan 24, 2022 11:39:00] debug  Master 9173 is running 
+[Jan 24, 2022 11:39:00] debug  redis is conetcted 
+[Jan 24, 2022 11:39:04] debug  redis is conetcted 
+[Jan 24, 2022 11:39:04] debug  redis is conetcted 
+[Jan 24, 2022 11:39:04] debug  redis is conetcted 
+[Jan 24, 2022 11:39:04] debug  redis is conetcted 
+[Jan 24, 2022 11:39:04] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAAcf7","isLogin":true}}
+[Jan 24, 2022 11:39:08] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAAdzj","isLogin":true}}
+[Jan 24, 2022 11:39:57] debug  房主自动创建房间 : {"roomId":"room-001_t-GusppsiKEC_web","userId":"user-user_001","user":{"userId":"user_001","sceneNum":"t-GusppsiKEC","role":"LEADER","isClient":"false","roomType":"normal","nickName":"测试1","roomId":"001","myHeadUrl":"http://downza.img.zz314.com/edu/pc/wlgj-1008/2016-06-23/64ec0888b15773e3ba5b5f744b9df16c.jpg","EIO":"4","transport":"polling","t":"NwAApm2","isLogin":true}}

error.log → logs/error.log


+ 1 - 1
src/connection/redis.js

@@ -4,7 +4,7 @@ import { logger } from "../core/logger.js";
 
 const url = `redis://:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}`;
 if (cluster.isPrimary) {
-  logger.info("url" + url);
+  logger.info("redis", { url });
 }
 const pubClient = createClient({ url: url });
 const subClient = pubClient.duplicate();

+ 6 - 8
src/controller/roomController.js

@@ -20,7 +20,7 @@ const isHoster = (role) => {
 const buildRoom = async (roomId, userId, user) => {
   const hasJoin = await pubClient.HVALS(roomId, userId);
   if (hasJoin.length === 0) {
-    console.log("创建房间", roomId);
+    log.info("创建房间", { roomId });
     await pubClient.hSet(roomId, userId, JSON.stringify(user));
   }
 };
@@ -31,7 +31,7 @@ const buildRoom = async (roomId, userId, user) => {
  */
 
 const removeRoom = async (roomId) => {
-  console.log("removeRoom", roomId);
+  log.info("removeRoom", { roomId });
   await pubClient.del(roomId);
 };
 
@@ -42,7 +42,7 @@ const removeRoom = async (roomId) => {
  * @param {*} user
  */
 const joinRoom = async (roomId, userId, user) => {
-  console.log("joinRoom", roomId);
+  log.info("joinRoom", { roomId });
   const hasRoom = await pubClient.exists(roomId);
   if (hasRoom) {
     await pubClient.hSet(roomId, userId, JSON.stringify(user));
@@ -69,7 +69,7 @@ const joinRoomAction = async (roomId, userId, user, socket) => {
   const isJoinRoom = await pubClient.hExists(roomId, userId);
   joinRoom(roomId, userId, user);
   if (!isJoinRoom) {
-    console.log("加入房间:", userId);
+    logger.info("加入房间 :", { userId, roomId, user });
     socket.join(roomId);
     socket.broadcast.emit(EVENT.roomIn, {
       user,
@@ -77,7 +77,7 @@ const joinRoomAction = async (roomId, userId, user, socket) => {
       // roomsConfig: this._roomsConfig[roomId],
     });
   } else {
-    console.log("已加入房间:", userId);
+    logger.info(`已加入房间 :`, { userId });
   }
 };
 
@@ -112,11 +112,9 @@ export async function roomController(socket) {
       user.isLogin = true;
       await pubClient.hSet(userUniqueId, user);
       await pubClient.expire(userUniqueId, 60 * 60 * 1);
-
-      console.log("1111");
       // 房主自动创建房间
       if (isHoster(role)) {
-        logger.info("房主自动创建房间:" + JSON.stringify({ roomId: roomUniqueId, userId: userUniqueId }));
+        logger.debug("房主自动创建房间 :", { roomId: roomUniqueId, userId: userUniqueId, user });
         buildRoom(roomUniqueId, userUniqueId, user);
         socket.join(roomUniqueId);
       }

+ 1 - 2
src/core/cluster.js

@@ -17,8 +17,7 @@ export class CoreCluster {
   }
   attachThead() {
     if (cluster.isMaster) {
-      logger.level = "debug";
-      logger.debug("Total Number of Cores: %o", numCPUs);
+      logger.debug("Total Number of Cores:" + numCPUs);
       logger.debug(`Master ${process.pid} is running`);
 
       // setup sticky sessions

+ 3 - 2
src/core/io.js

@@ -4,6 +4,7 @@ import { Server } from "socket.io";
 import { instrument, RedisStore } from "@socket.io/admin-ui";
 import { createAdapter } from "@socket.io/redis-adapter";
 import { pubClient, subClient } from "../connection/redis.js";
+import { logger } from "./logger.js";
 
 const httpServer = http.createServer();
 const io = new Server(httpServer, {
@@ -27,10 +28,10 @@ instrument(io, {
 Promise.all([pubClient.connect(), subClient.connect()])
   .then(() => {
     io.adapter(createAdapter(pubClient, subClient));
-    console.log("redis is conetcted");
+    logger.debug("redis is conetcted");
   })
   .catch((error) => {
-    console.log("redis is fail", error);
+    logger.error("redis is connect fail" + JSON.stringify(error));
   });
 
 export { io };

+ 29 - 8
src/core/logger.js

@@ -1,21 +1,42 @@
 import { transports, createLogger, format } from "winston";
 import cluster from "cluster";
+import path from "path";
+import { join, dirname } from "path";
+import { fileURLToPath } from "url";
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+
+// const logFormat = format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}` + (info.splat !== undefined ? `${info.splat}` : " "));
+
+const formatMeta = (meta) => {
+  // You can format the splat yourself
+  const splat = meta[Symbol.for("splat")];
+  if (splat && splat.length) {
+    return splat.length === 1 ? JSON.stringify(splat[0]) : JSON.stringify(splat);
+  }
+  return "";
+};
+
+const customFormat = format.printf(({ timestamp, level, message, label = "", ...meta }) => `[${timestamp}] ${level} ${label} ${message} ${formatMeta(meta)}`);
 
 const logger = createLogger({
-  level: "info",
-  defaultMeta: { service: "user-service" },
+  level: "debug",
+
   format: format.combine(
-    format.timestamp({
-      format: "YYYY-MM-DD HH:mm:ss",
-    }),
-    format.printf((info) => `${info.timestamp} ${info.level}: ${info.message}` + (info.splat !== undefined ? `${info.splat}` : " ")),
+    format.colorize(),
+    format.timestamp({ format: "MMM D, YYYY HH:mm:ss" }),
+    customFormat,
+    // Do not use splat format
   ),
   transports: [
     // - Write all logs with importance level of `error` or less to `error.log`
     // - Write all logs with importance level of `info` or less to `combined.log`
     //
-    new transports.File({ filename: "error.log", level: "error" }),
-    new transports.File({ filename: "combined.log" }),
+    new transports.Console(),
+    new transports.File({ filename: join(__dirname, "../../logs/error.log"), level: "error" }),
+    new transports.File({
+      filename: join(__dirname, "../../logs/combined.log"),
+    }),
   ],
 });
 export { logger };