Init -- well, everything.
This commit is contained in:
parent
0b2fa17341
commit
4645561d33
9 changed files with 352 additions and 0 deletions
28
src/app/utils/logs.ts
Normal file
28
src/app/utils/logs.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import fs from 'fs'
|
||||
|
||||
export const init = (baseDir: string) => {
|
||||
if (!fs.existsSync(`${baseDir}/logs`)) {
|
||||
fs.mkdirSync(`${baseDir}/logs`)
|
||||
}
|
||||
|
||||
let date = new Date()
|
||||
|
||||
let logs: fs.WriteStream | null = null
|
||||
let errs: fs.WriteStream | null = null
|
||||
|
||||
console.log = (item: any) => {
|
||||
if (!logs) {
|
||||
logs = fs.createWriteStream(baseDir + `/logs/logs-${date.toISOString()}.log`, { flags: 'a' })
|
||||
}
|
||||
|
||||
logs.write(`[${new Date().toISOString()}]: ${item}\n`)
|
||||
}
|
||||
|
||||
console.error = (item: any) => {
|
||||
if (!errs) {
|
||||
errs = fs.createWriteStream(baseDir + `/logs/errors-${date.toISOString()}.log`, { flags: 'a' })
|
||||
}
|
||||
|
||||
errs.write(`[${new Date().toISOString()}]: ${item}\n`)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue