-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
37 lines (33 loc) · 980 Bytes
/
utils.js
File metadata and controls
37 lines (33 loc) · 980 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @dev Function to get the current UTC timestamp in nanoseconds
* @returns {BigInt} The current UTC timestamp in nanoseconds
*/
function nowInNs () {
const timeOrigin = BigInt(Math.round(performance.timeOrigin * 1_000_000))
const now = BigInt(Math.round(performance.now() * 1_000_000))
return timeOrigin + now
}
/**
* @dev Function to get the console metadata for logging.
* @param {string} logType - The type of log.
* @param {boolean} isLog - Whether the log is a log or an error.
* @param {string} filePath - The file path of the log.
* @param {string} functionName - The name of the function that logged the message.
*/
function getConsoleMetadata (
logType,
isLog,
filePath,
functionName,
) {
const currentTime = nowInNs()
return `[${ logType
} ${ isLog ? 'LOG' : 'ERROR'
}: --logTimestamp="${ currentTime
}" --file-path="${ filePath
} --function-name="${ functionName
}"]: `
}
module.exports = {
getConsoleMetadata,
}