-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.mjs
More file actions
62 lines (60 loc) · 1.66 KB
/
error.mjs
File metadata and controls
62 lines (60 loc) · 1.66 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import fs from "node:fs/promises";
fs.mkdir('error',{recursive:true})
.then(()=>{
console.log(`sucess creating `);
}).catch((err)=>{
console.log(`already exist ${err}`);
})
fs.access('./error/errors.txt',fs.constants.F_OK)
.then(()=>{
console.log('starting interval ')
})
.catch(()=>{
fs.writeFile('./error/errors.txt','LOGGING ALL ERRORS \n',{flag:'a'})
console.log('starting interval ')
})
async function gettingError() {
try {
const dataError=await fs.readFile('./errors.json','utf8')
const data= JSON.parse(dataError)
return data
} catch (error) {
throw err
}
}
async function randomize() {
const data= await gettingError()
let copiedData=[...data]
if (copiedData.length==0) {
copiedData=[...data]
}
const num=Math.floor(Math.random()*copiedData.length)
const randomizedData=copiedData.splice(num,1)[0]
return randomizedData
}
async function logData() {
const data=await randomize()
//console.log( da)
const date=new Date()
const timeStamp=date.toLocaleTimeString()
const {code,errno,syscall,description}=data
const value=`[${timeStamp}]\nCODE: ${code}\nERRNO: ${errno}\nSYSCALL: ${syscall}\nDESCRIPTION: ${description}\n --------\n`
return value
}
async function Logging() {
try {
const data=await logData()
await fs.appendFile('./error/errors.txt',data,{encoding:'utf8'})
const readData= await fs.readFile('./error/errors.txt','utf8')
//console.log(readData);
} catch (error) {
throw error
}
}
Logging()
const interval=setInterval(()=>{
Logging()
},50)
setTimeout(()=>{
clearInterval(interval)
},2000)