bajo 1.2.8 → 1.2.9
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.
|
@@ -12,6 +12,7 @@ const omitted = ['spawn', 'cwd', 'name', 'alias', 'applet', 'a', 'plugins']
|
|
|
12
12
|
const defConfig = {
|
|
13
13
|
log: {
|
|
14
14
|
dateFormat: 'YYYY-MM-DDTHH:MM:ss.SSS[Z]',
|
|
15
|
+
plain: false,
|
|
15
16
|
applet: false,
|
|
16
17
|
traceHook: false
|
|
17
18
|
},
|
|
@@ -65,7 +66,7 @@ export async function buildExtConfig () {
|
|
|
65
66
|
const { defaultsDeep } = this.lib.aneka
|
|
66
67
|
let resp = await readAllConfigs.call(this.app, `${this.dir.data}/config/${this.name}`)
|
|
67
68
|
resp = omitDeep(pick(resp, ['log', 'exitHandler', 'env']), omitted)
|
|
68
|
-
this.config = defaultsDeep({},
|
|
69
|
+
this.config = defaultsDeep({}, this.config, resp, defConfig)
|
|
69
70
|
this.config.env = (this.config.env ?? 'dev').toLowerCase()
|
|
70
71
|
if (values(this.envs).includes(this.config.env)) this.config.env = this.lib.aneka.getKeyByValue(this.envs, this.config.env)
|
|
71
72
|
if (!keys(this.envs).includes(this.config.env)) throw new Error(`Unknown environment '${this.config.env}'. Supported: ${this.join(keys(this.envs))}`)
|
package/boot/class/bajo-core.js
CHANGED
|
@@ -43,7 +43,6 @@ class BajoCore extends Plugin {
|
|
|
43
43
|
{ ext: '.json', readHandler: this.readJson }
|
|
44
44
|
]
|
|
45
45
|
this.whiteSpace = [' ', '\t', '\n', '\r']
|
|
46
|
-
this.logLevels = logLevels
|
|
47
46
|
this.envs = { dev: 'development', staging: 'staging', prod: 'production' }
|
|
48
47
|
}
|
|
49
48
|
|
|
@@ -484,7 +483,7 @@ class BajoCore extends Plugin {
|
|
|
484
483
|
}
|
|
485
484
|
|
|
486
485
|
isLogInRange = (level) => {
|
|
487
|
-
const levels = keys(
|
|
486
|
+
const levels = keys(logLevels)
|
|
488
487
|
const logLevel = indexOf(levels, this.app.bajo.config.log.level)
|
|
489
488
|
return indexOf(levels, level) >= logLevel
|
|
490
489
|
}
|
package/boot/class/log.js
CHANGED
|
@@ -2,8 +2,9 @@ import os from 'os'
|
|
|
2
2
|
import lodash from 'lodash'
|
|
3
3
|
import dayjs from 'dayjs'
|
|
4
4
|
import logLevels from '../lib/log-levels.js'
|
|
5
|
+
import chalk from 'chalk'
|
|
5
6
|
|
|
6
|
-
const { isEmpty, without, merge
|
|
7
|
+
const { isEmpty, without, merge } = lodash
|
|
7
8
|
|
|
8
9
|
export function isIgnored (level) {
|
|
9
10
|
const { filter, isArray } = this.lib._
|
|
@@ -47,6 +48,7 @@ class Log {
|
|
|
47
48
|
formatMsg = (level, ...params) => {
|
|
48
49
|
if (this.plugin.app.bajo.config.log.level === 'silent') return
|
|
49
50
|
if (!this.plugin.app.bajo.isLogInRange(level)) return
|
|
51
|
+
const plain = this.plugin.app.bajo.config.log.plain
|
|
50
52
|
let [data, msg, ...args] = params
|
|
51
53
|
if (typeof data === 'string') {
|
|
52
54
|
args.unshift(msg)
|
|
@@ -58,19 +60,23 @@ class Log {
|
|
|
58
60
|
msg = 'error%s'
|
|
59
61
|
args = [data.message]
|
|
60
62
|
}
|
|
61
|
-
msg =
|
|
63
|
+
msg = this.write(msg, ...args)
|
|
62
64
|
if (this.plugin.app[this.bajoLog] && this.plugin.app[this.bajoLog].logger) {
|
|
63
|
-
this.plugin.app[this.bajoLog].logger[level](data, msg
|
|
65
|
+
this.plugin.app[this.bajoLog].logger[level](data, `[${this.plugin.name}] ${msg}`, ...args)
|
|
64
66
|
} else {
|
|
65
67
|
let text
|
|
66
68
|
const dt = new Date()
|
|
67
69
|
if (this.plugin.app.bajo.config.env === 'prod') {
|
|
68
|
-
const json = { level: logLevels[level], time: dt.valueOf(), pid: process.pid, hostname: os.hostname() }
|
|
70
|
+
const json = { level: logLevels[level].number, time: dt.valueOf(), pid: process.pid, hostname: os.hostname() }
|
|
69
71
|
if (!isEmpty(data)) merge(json, data)
|
|
70
|
-
merge(json, { msg })
|
|
72
|
+
merge(json, { msg: `[${this.plugin.name}] ${msg}` })
|
|
71
73
|
text = JSON.stringify(json)
|
|
72
74
|
} else {
|
|
73
|
-
|
|
75
|
+
const date = dayjs(dt).utc(true).format(this.format)
|
|
76
|
+
const tdate = plain ? `[${date}]` : chalk.cyan(date)
|
|
77
|
+
const tlevel = plain ? level.toUpperCase() : chalk[logLevels[level].color](level.toUpperCase())
|
|
78
|
+
const tplugin = plain ? `[${this.plugin.name}]` : chalk.bgBlue(`${this.plugin.name}`)
|
|
79
|
+
text = `${tdate} ${tlevel}: ${tplugin} ${msg}`
|
|
74
80
|
if (!isEmpty(data)) text += '\n' + JSON.stringify(data)
|
|
75
81
|
}
|
|
76
82
|
if (!this.isIgnored(level)) {
|
package/boot/lib/log-levels.js
CHANGED
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export default {
|
|
1
|
+
export default {
|
|
2
|
+
trace: { number: 10, color: 'gray' },
|
|
3
|
+
debug: { number: 20, color: 'greenBright' },
|
|
4
|
+
info: { number: 30, color: 'blueBright' },
|
|
5
|
+
warn: { number: 40, color: 'yellowBright' },
|
|
6
|
+
error: { number: 50, color: 'redBright' },
|
|
7
|
+
fatal: { number: 60, color: 'magentaBright' },
|
|
8
|
+
silent: { number: 99, color: 'white' }
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bajo",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "A framework to build a giant monstrous app rapidly",
|
|
5
5
|
"main": "boot/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"add-filename-increment": "^1.0.0",
|
|
29
29
|
"aneka": "^0.1.4",
|
|
30
|
+
"chalk": "^5.5.0",
|
|
30
31
|
"dayjs": "^1.11.13",
|
|
31
32
|
"deep-freeze-strict": "^1.1.1",
|
|
32
33
|
"delay": "^6.0.0",
|