@stacksjs/logging 0.58.57 → 0.58.59
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/dist/index.js +10932 -1773
- package/package.json +1 -1
- package/src/index.ts +79 -13
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import process from 'node:process'
|
|
2
|
-
import consola from 'consola'
|
|
2
|
+
import { consola, createConsola } from 'consola'
|
|
3
3
|
import { ExitCode } from '@stacksjs/types'
|
|
4
|
+
import { logger as logConfig } from '@stacksjs/config'
|
|
4
5
|
import { logsPath } from '@stacksjs/path'
|
|
6
|
+
import type { Prompt } from '@stacksjs/cli'
|
|
7
|
+
import { buddyOptions, prompt as getPrompt } from '@stacksjs/cli'
|
|
5
8
|
|
|
6
|
-
export
|
|
9
|
+
export function logLevel() {
|
|
10
|
+
/**
|
|
11
|
+
* This regex checks for:
|
|
12
|
+
* - --verbose true or --verbose=true exactly at the end of the string ($ denotes the end of the string).
|
|
13
|
+
* - --verbose - followed by optional spaces at the end.
|
|
14
|
+
* - --verbose followed by optional spaces at the end.
|
|
15
|
+
*
|
|
16
|
+
* .trim() is used on options to ensure any trailing spaces in the entire options string do not affect the regex match.
|
|
17
|
+
*/
|
|
18
|
+
const verboseRegex = /--verbose(?!(\s*=\s*false|\s+false))(\s+|=true)?($|\s)/
|
|
19
|
+
|
|
20
|
+
if (verboseRegex.test(buddyOptions().trim()))
|
|
21
|
+
return 4
|
|
22
|
+
return logConfig.level
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const logger = createConsola({
|
|
26
|
+
level: logLevel(),
|
|
27
|
+
// fancy: true,
|
|
28
|
+
// formatOptions: {
|
|
29
|
+
// columns: 80,
|
|
30
|
+
// colors: false,
|
|
31
|
+
// compact: false,
|
|
32
|
+
// date: false,
|
|
33
|
+
// },
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
export { consola }
|
|
7
37
|
|
|
8
38
|
export const logFilePath = logsPath('console.log')
|
|
9
39
|
|
|
@@ -27,35 +57,66 @@ async function writeToLogFile(message: string) {
|
|
|
27
57
|
}
|
|
28
58
|
}
|
|
29
59
|
|
|
30
|
-
export
|
|
31
|
-
info:
|
|
32
|
-
|
|
60
|
+
export interface Log {
|
|
61
|
+
info: (...args: any[]) => void
|
|
62
|
+
success: (msg: string) => void
|
|
63
|
+
error: (err: string | Error, options?: any) => void
|
|
64
|
+
warn: (arg: string) => void
|
|
65
|
+
debug: (...args: any[]) => void
|
|
66
|
+
// start: logger.Start
|
|
67
|
+
// box: logger.Box
|
|
68
|
+
start: any
|
|
69
|
+
box: any
|
|
70
|
+
prompt: Prompt
|
|
71
|
+
dump: (...args: any[]) => void
|
|
72
|
+
dd: (...args: any[]) => void
|
|
73
|
+
echo: (...args: any[]) => void
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export const log: Log = {
|
|
77
|
+
async info(...arg: any) {
|
|
78
|
+
// @ts-expect-error intentional
|
|
79
|
+
logger.info(...arg)
|
|
33
80
|
await writeToLogFile(`INFO: ${arg}`)
|
|
34
81
|
},
|
|
35
82
|
|
|
36
|
-
|
|
37
|
-
|
|
83
|
+
async success(msg: string) {
|
|
84
|
+
logger.success(msg)
|
|
38
85
|
await writeToLogFile(`SUCCESS: ${msg}`)
|
|
39
86
|
},
|
|
40
87
|
|
|
41
|
-
|
|
88
|
+
async error(err: string | Error, options?: any) {
|
|
42
89
|
handleError(err, options) // Assuming handleError logs the error
|
|
43
90
|
await writeToLogFile(`ERROR: ${err}`)
|
|
44
91
|
},
|
|
45
92
|
|
|
46
|
-
|
|
47
|
-
|
|
93
|
+
async warn(arg: string) {
|
|
94
|
+
logger.warn(arg)
|
|
48
95
|
await writeToLogFile(`WARN: ${arg}`)
|
|
49
96
|
},
|
|
50
97
|
|
|
51
|
-
|
|
52
|
-
|
|
98
|
+
async debug(...arg: any) {
|
|
99
|
+
if (process.env.APP_ENV === 'production' || process.env.APP_ENV === 'prod')
|
|
100
|
+
return await writeToLogFile(`DEBUG: ${arg}`)
|
|
101
|
+
|
|
102
|
+
logger.debug(arg)
|
|
53
103
|
await writeToLogFile(`DEBUG: ${arg}`)
|
|
54
104
|
},
|
|
55
105
|
|
|
56
|
-
|
|
106
|
+
async start(...arg: any) {
|
|
107
|
+
logger.start(arg)
|
|
108
|
+
await writeToLogFile(`START: ${arg}`)
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
box: logger.box,
|
|
112
|
+
|
|
113
|
+
get prompt() {
|
|
114
|
+
return getPrompt()
|
|
115
|
+
},
|
|
116
|
+
|
|
57
117
|
dump,
|
|
58
118
|
dd,
|
|
119
|
+
echo,
|
|
59
120
|
}
|
|
60
121
|
|
|
61
122
|
export function dump(...args: any[]) {
|
|
@@ -68,3 +129,8 @@ export function dd(...args: any[]) {
|
|
|
68
129
|
// e.g. if used in a CDK script, we want it to fail the deployment
|
|
69
130
|
process.exit(ExitCode.FatalError)
|
|
70
131
|
}
|
|
132
|
+
|
|
133
|
+
export function echo(...args: any[]) {
|
|
134
|
+
// eslint-disable-next-line no-console
|
|
135
|
+
console.log(...args)
|
|
136
|
+
}
|