From d221704baafe8b8e743dce8b75782237d1d36555 Mon Sep 17 00:00:00 2001 From: Nabarun Gogoi Date: Fri, 17 Mar 2023 15:08:15 +0530 Subject: [PATCH] Add timestamp to mobymask p2p messages (#340) * Add timestamps to mobymask logs * Fix getCurrentTime method calls --------- Co-authored-by: Dhruv Srivastava --- packages/mobymask-v2-watcher/src/libp2p-utils.ts | 7 ++++++- packages/mobymask-v2-watcher/src/peer-listener.ts | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/mobymask-v2-watcher/src/libp2p-utils.ts b/packages/mobymask-v2-watcher/src/libp2p-utils.ts index 8d951882..34e77413 100644 --- a/packages/mobymask-v2-watcher/src/libp2p-utils.ts +++ b/packages/mobymask-v2-watcher/src/libp2p-utils.ts @@ -83,7 +83,7 @@ export async function sendMessageToL2 ( } export function parseLibp2pMessage (log: debug.Debugger, peerId: string, data: any): void { - log('Received a message on mobymask P2P network from peer:', peerId); + log(`[${getCurrentTime()}] Received a message on mobymask P2P network from peer:`, peerId); const { kind, message } = data; switch (kind) { @@ -107,6 +107,11 @@ export function parseLibp2pMessage (log: debug.Debugger, peerId: string, data: a log('------------------------------------------'); } +export const getCurrentTime = (): string => { + const now = new Date(); + return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`; +}; + function _parseInvocation (log: debug.Debugger, msg: any): void { log('Signed invocations:'); log(JSON.stringify(msg, null, 2)); diff --git a/packages/mobymask-v2-watcher/src/peer-listener.ts b/packages/mobymask-v2-watcher/src/peer-listener.ts index ff715361..8957827e 100644 --- a/packages/mobymask-v2-watcher/src/peer-listener.ts +++ b/packages/mobymask-v2-watcher/src/peer-listener.ts @@ -10,7 +10,7 @@ import { // @ts-expect-error https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1319854183 } from '@cerc-io/peer'; -import { sendMessageToL2 } from './libp2p-utils'; +import { getCurrentTime, sendMessageToL2 } from './libp2p-utils'; import { readPeerId } from '@cerc-io/cli'; import { ethers } from 'ethers'; @@ -57,7 +57,7 @@ export const main = async (): Promise => { const wallet = new ethers.Wallet(argv.privateKey, ethProvider); peer.subscribeTopic(peerConfig.pubSubTopic, (peerId, data) => { - log('Received a message on mobymask P2P network from peer:', peerId); + log(`[${getCurrentTime()}] Received a message on mobymask P2P network from peer:`, peerId); // TODO: throttle message handler sendMessageToL2(wallet, argv, data);