@stacksjs/logging 0.59.11 → 0.61.0
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 +9 -9
- package/package.json +2 -4
- package/src/index.ts +22 -28
- package/dist/index.d.ts +0 -22
package/dist/index.js
CHANGED
|
@@ -1776,9 +1776,13 @@ var init_consola_36c0034f = __esm(() => {
|
|
|
1776
1776
|
});
|
|
1777
1777
|
|
|
1778
1778
|
// src/index.ts
|
|
1779
|
-
import process2 from "process";
|
|
1780
1779
|
import {appendFile, mkdir} from "fs/promises";
|
|
1781
1780
|
import {dirname} from "path";
|
|
1781
|
+
import process2 from "process";
|
|
1782
|
+
import {buddyOptions, prompt as getPrompt} from "@stacksjs/cli";
|
|
1783
|
+
import {handleError} from "@stacksjs/error-handling";
|
|
1784
|
+
import {logsPath} from "@stacksjs/path";
|
|
1785
|
+
import {ExitCode} from "@stacksjs/types";
|
|
1782
1786
|
|
|
1783
1787
|
// ../../../../node_modules/consola/dist/index.mjs
|
|
1784
1788
|
init_consola_36c0034f();
|
|
@@ -1787,17 +1791,12 @@ init_consola_06ad8a64();
|
|
|
1787
1791
|
init_utils();
|
|
1788
1792
|
|
|
1789
1793
|
// src/index.ts
|
|
1790
|
-
|
|
1791
|
-
import {config as config2} from "@stacksjs/config";
|
|
1792
|
-
import {handleError} from "@stacksjs/error-handling";
|
|
1793
|
-
import {buddyOptions, prompt as getPrompt} from "@stacksjs/cli";
|
|
1794
|
-
import {logsPath} from "@stacksjs/path";
|
|
1795
|
-
function logLevel() {
|
|
1794
|
+
async function logLevel() {
|
|
1796
1795
|
const verboseRegex = /--verbose(?!(\s*=\s*false|\s+false))(\s+|=true)?($|\s)/;
|
|
1797
1796
|
const opts = buddyOptions();
|
|
1798
1797
|
if (verboseRegex.test(opts))
|
|
1799
1798
|
return 4;
|
|
1800
|
-
return
|
|
1799
|
+
return 3;
|
|
1801
1800
|
}
|
|
1802
1801
|
async function writeToLogFile(message) {
|
|
1803
1802
|
const formattedMessage = `[${new Date().toISOString()}] ${message}\n`;
|
|
@@ -1824,7 +1823,7 @@ function echo(...args) {
|
|
|
1824
1823
|
console.log(...args);
|
|
1825
1824
|
}
|
|
1826
1825
|
var logger = createConsola2({
|
|
1827
|
-
level: logLevel()
|
|
1826
|
+
level: await logLevel()
|
|
1828
1827
|
});
|
|
1829
1828
|
var log = {
|
|
1830
1829
|
async info(...arg) {
|
|
@@ -1867,6 +1866,7 @@ var log = {
|
|
|
1867
1866
|
echo
|
|
1868
1867
|
};
|
|
1869
1868
|
export {
|
|
1869
|
+
writeToLogFile,
|
|
1870
1870
|
logger,
|
|
1871
1871
|
logLevel,
|
|
1872
1872
|
log,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/logging",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "The Stacks logging system.",
|
|
6
6
|
"author": "Chris Breuer",
|
|
7
7
|
"license": "MIT",
|
|
@@ -24,12 +24,10 @@
|
|
|
24
24
|
],
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"bun": "./src/index.ts",
|
|
28
27
|
"types": "./dist/index.d.ts",
|
|
29
28
|
"import": "./dist/index.js"
|
|
30
29
|
},
|
|
31
30
|
"./*": {
|
|
32
|
-
"bun": "./src/*",
|
|
33
31
|
"import": "./dist/*"
|
|
34
32
|
}
|
|
35
33
|
},
|
|
@@ -60,6 +58,6 @@
|
|
|
60
58
|
"consola": "^3.2.3"
|
|
61
59
|
},
|
|
62
60
|
"devDependencies": {
|
|
63
|
-
"typescript": "^5.4.
|
|
61
|
+
"typescript": "^5.4.5"
|
|
64
62
|
}
|
|
65
63
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import process from 'node:process'
|
|
2
1
|
import { appendFile, mkdir } from 'node:fs/promises'
|
|
3
2
|
import { dirname } from 'node:path'
|
|
4
|
-
import
|
|
5
|
-
import { ExitCode } from '@stacksjs/types'
|
|
6
|
-
import { config } from '@stacksjs/config'
|
|
7
|
-
import { handleError } from '@stacksjs/error-handling'
|
|
3
|
+
import process from 'node:process'
|
|
8
4
|
import type { Prompt } from '@stacksjs/cli'
|
|
9
5
|
import { buddyOptions, prompt as getPrompt } from '@stacksjs/cli'
|
|
6
|
+
import { handleError } from '@stacksjs/error-handling'
|
|
10
7
|
import { logsPath } from '@stacksjs/path'
|
|
8
|
+
import { ExitCode } from '@stacksjs/types'
|
|
9
|
+
import { consola, createConsola } from 'consola'
|
|
11
10
|
|
|
12
|
-
export function logLevel() {
|
|
11
|
+
export async function logLevel() {
|
|
13
12
|
/**
|
|
14
13
|
* This regex checks for:
|
|
15
14
|
* - --verbose true or --verbose=true exactly at the end of the string ($ denotes the end of the string).
|
|
@@ -20,17 +19,18 @@ export function logLevel() {
|
|
|
20
19
|
*/
|
|
21
20
|
const verboseRegex = /--verbose(?!(\s*=\s*false|\s+false))(\s+|=true)?($|\s)/
|
|
22
21
|
const opts = buddyOptions()
|
|
23
|
-
// console.log('opts:', opts)
|
|
24
|
-
// console.log('config:::', config)
|
|
25
22
|
|
|
26
|
-
if (verboseRegex.test(opts))
|
|
27
|
-
|
|
23
|
+
if (verboseRegex.test(opts)) return 4
|
|
24
|
+
|
|
25
|
+
// const config = await import('@stacksjs/config')
|
|
26
|
+
// console.log('config', config)
|
|
28
27
|
|
|
29
|
-
return
|
|
28
|
+
return 3
|
|
29
|
+
// return config.logger.level
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
export const logger = createConsola({
|
|
33
|
-
level: logLevel(),
|
|
33
|
+
level: await logLevel(),
|
|
34
34
|
// fancy: true,
|
|
35
35
|
// formatOptions: {
|
|
36
36
|
// columns: 80,
|
|
@@ -42,7 +42,7 @@ export const logger = createConsola({
|
|
|
42
42
|
|
|
43
43
|
export { consola }
|
|
44
44
|
|
|
45
|
-
async function writeToLogFile(message: string) {
|
|
45
|
+
export async function writeToLogFile(message: string) {
|
|
46
46
|
const formattedMessage = `[${new Date().toISOString()}] ${message}\n`
|
|
47
47
|
try {
|
|
48
48
|
try {
|
|
@@ -51,12 +51,10 @@ async function writeToLogFile(message: string) {
|
|
|
51
51
|
await mkdir(dirname(logFilePath), { recursive: true })
|
|
52
52
|
// Append the message to the log file
|
|
53
53
|
await appendFile(logFilePath, formattedMessage)
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
54
|
+
} catch (error) {
|
|
56
55
|
console.error('Failed to write to log file:', error)
|
|
57
56
|
}
|
|
58
|
-
}
|
|
59
|
-
catch (error) {
|
|
57
|
+
} catch (error) {
|
|
60
58
|
console.error('Failed to write to log file:', error)
|
|
61
59
|
}
|
|
62
60
|
}
|
|
@@ -64,7 +62,7 @@ async function writeToLogFile(message: string) {
|
|
|
64
62
|
export interface Log {
|
|
65
63
|
info: (...args: any[]) => void
|
|
66
64
|
success: (msg: string) => void
|
|
67
|
-
error: (err: string | Error, options?: any | Error) => void
|
|
65
|
+
error: (err: string | Error | unknown, options?: any | Error) => void
|
|
68
66
|
warn: (arg: string) => void
|
|
69
67
|
debug: (...args: any[]) => void
|
|
70
68
|
// start: logger.Start
|
|
@@ -89,13 +87,10 @@ export const log: Log = {
|
|
|
89
87
|
await writeToLogFile(`SUCCESS: ${msg}`)
|
|
90
88
|
},
|
|
91
89
|
|
|
92
|
-
async error(err:
|
|
93
|
-
if (err instanceof Error)
|
|
94
|
-
|
|
95
|
-
else
|
|
96
|
-
handleError(options)
|
|
97
|
-
else
|
|
98
|
-
handleError(err, options)
|
|
90
|
+
async error(err: unknown, options?: any | Error) {
|
|
91
|
+
if (err instanceof Error) handleError(err, options)
|
|
92
|
+
else if (options instanceof Error) handleError(options)
|
|
93
|
+
else handleError(err, options)
|
|
99
94
|
|
|
100
95
|
await writeToLogFile(`ERROR: ${err}`)
|
|
101
96
|
},
|
|
@@ -130,17 +125,16 @@ export const log: Log = {
|
|
|
130
125
|
}
|
|
131
126
|
|
|
132
127
|
export function dump(...args: any[]) {
|
|
133
|
-
args.forEach(arg => log.debug(arg))
|
|
128
|
+
args.forEach((arg) => log.debug(arg))
|
|
134
129
|
}
|
|
135
130
|
|
|
136
131
|
export function dd(...args: any[]) {
|
|
137
|
-
args.forEach(arg => log.debug(arg))
|
|
132
|
+
args.forEach((arg) => log.debug(arg))
|
|
138
133
|
// we need to return a non-zero exit code to indicate an error
|
|
139
134
|
// e.g. if used in a CDK script, we want it to fail the deployment
|
|
140
135
|
process.exit(ExitCode.FatalError)
|
|
141
136
|
}
|
|
142
137
|
|
|
143
138
|
export function echo(...args: any[]) {
|
|
144
|
-
// eslint-disable-next-line no-console
|
|
145
139
|
console.log(...args)
|
|
146
140
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { consola } from 'consola';
|
|
2
|
-
import type { Prompt } from '@stacksjs/cli';
|
|
3
|
-
export declare function logLevel(): any;
|
|
4
|
-
export declare const logger: import("consola").ConsolaInstance;
|
|
5
|
-
export { consola };
|
|
6
|
-
export interface Log {
|
|
7
|
-
info: (...args: any[]) => void;
|
|
8
|
-
success: (msg: string) => void;
|
|
9
|
-
error: (err: string | Error, options?: any | Error) => void;
|
|
10
|
-
warn: (arg: string) => void;
|
|
11
|
-
debug: (...args: any[]) => void;
|
|
12
|
-
start: any;
|
|
13
|
-
box: any;
|
|
14
|
-
prompt: Prompt;
|
|
15
|
-
dump: (...args: any[]) => void;
|
|
16
|
-
dd: (...args: any[]) => void;
|
|
17
|
-
echo: (...args: any[]) => void;
|
|
18
|
-
}
|
|
19
|
-
export declare const log: Log;
|
|
20
|
-
export declare function dump(...args: any[]): void;
|
|
21
|
-
export declare function dd(...args: any[]): void;
|
|
22
|
-
export declare function echo(...args: any[]): void;
|