-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsw-cli-log.js
58 lines (46 loc) · 2.15 KB
/
sw-cli-log.js
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
// Distributed under AGPLv3 license: see /LICENSE for terms. Copyright 2019-2023 Dominic Morris.
const utilsWallet = require('./utils')
//const chalk = require('chalk')
const colors = require('colors')
module.exports = {
param: (name, value, source) => {
console.log(`<< ${name.toString().padEnd(15, '.').cyan.bold} ${(source||'').padEnd(15, '.')}: ${value}`)
},
cmd: (s, p) => {
if (p) console.log(`\n<< ${s.toString().bgCyan.white.bold}`, p)
else console.log(`\n<< ${s.toString().bgCyan.white.bold}`)
},
info: (s, p) => {
if (p) console.log(`<< ${s.toString().cyan.bold}`, p)
else console.log(`<< ${s.toString().cyan.bold}`)
//utilsWallet.log('(sw-cli-log) << ' + s.toString(), p)
},
warn: (s, p) => {
if (p) console.log(`<< ${'WARNING'.yellow.bold.underline + ' ' + s.toString().yellow.bold}`, p)
else console.log(`<< ${'WARNING'.yellow.bold.underline + ' ' + s.toString().yellow.bold}`)
},
error: (s, p) => {
if (p) console.log(`<< ${' FAIL '.bgRed.white.bold + ' ' + s.toString().red.bold.underline}`, p)
else console.log(`<< ${' FAIL '.bgRed.white.bold + ' ' + s.toString().red.bold.underline}`)
},
success: (s, p) => {
if (p) console.log(`<< ${' OK '.bgGreen.white.bold + ' ' + s.toString().cyan.bold}`, p)
else console.log(`<< ${' OK '.bgGreen.white.bold + ' ' + s.toString().cyan.bold}`)
},
logTail: (appWorker, store, p) => {
var { lines, debug } = p
if (!lines || !Number.isInteger(Number(lines))) lines = 100
lines *= 2 // some double \n somewhere somehow
const logDebug = utilsWallet.isParamTrue(debug)
const readLastLines = require('read-last-lines')
const readOp = logDebug
? readLastLines.read('./debug.log', lines)
: readLastLines.read('./info.log', lines)
return readOp.then((lines) => {
console.log(lines)
return new Promise((resolve) => {
resolve({ ok: true })
})
})
}
}