datata-logger 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +13 -2
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
const chalk = require('chalk')
|
|
2
|
+
const fs = require('fs')
|
|
2
3
|
|
|
3
4
|
const date = () => {
|
|
4
5
|
return new Date().toLocaleString('es-Es')
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
+
const stream = fs.createWriteStream('log.txt', { flags: 'a' })
|
|
7
8
|
const info = message => {
|
|
8
|
-
|
|
9
|
+
const logMessage = `[INFO] [${date()}] ${message}\n`
|
|
10
|
+
console.log(chalk.blue(logMessage))
|
|
11
|
+
stream.write(logMessage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function close() {
|
|
15
|
+
console.log('Close logger!')
|
|
16
|
+
stream.end()
|
|
9
17
|
}
|
|
10
18
|
|
|
19
|
+
process.on('SIGINT', closeStream)
|
|
20
|
+
|
|
11
21
|
exports.info = info
|
|
22
|
+
exports.close = close
|