@sprucelabs/spruce-skill-utils 33.1.0 → 33.2.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.
|
@@ -7,11 +7,15 @@ export declare class Logger implements Log {
|
|
|
7
7
|
private readonly colors;
|
|
8
8
|
private readonly pre;
|
|
9
9
|
private readonly shouldUseColors;
|
|
10
|
+
private history;
|
|
11
|
+
private historyLimit;
|
|
10
12
|
constructor(prefix?: string | undefined, options?: LogOptions);
|
|
13
|
+
startTrackingHistory(limit: number): void;
|
|
11
14
|
info(...args: LoggableType[]): string;
|
|
12
15
|
warn(...args: LoggableType[]): string;
|
|
13
16
|
error(...args: LoggableType[]): string;
|
|
14
17
|
buildLog(prefix?: string | undefined, options?: LogOptions): Log;
|
|
18
|
+
getHistory(): string[];
|
|
15
19
|
private write;
|
|
16
20
|
private shouldLog;
|
|
17
21
|
private resolveChalk;
|
|
@@ -54,6 +58,8 @@ export type LoggableType = Anything | Anything[] | Record<string, Anything>;
|
|
|
54
58
|
export type LogTransport = (...messageParts: string[]) => void;
|
|
55
59
|
type TransportMap = Record<Level, LogTransport | LogTransport[] | null | undefined>;
|
|
56
60
|
export interface Log {
|
|
61
|
+
startTrackingHistory(limit: number): void;
|
|
62
|
+
getHistory(): string[];
|
|
57
63
|
readonly prefix: string | undefined;
|
|
58
64
|
info: (...args: LoggableType[]) => string;
|
|
59
65
|
error: (...args: LoggableType[]) => string;
|
|
@@ -2,6 +2,8 @@ import chalk from 'chalk';
|
|
|
2
2
|
export class Logger {
|
|
3
3
|
constructor(prefix = undefined, options) {
|
|
4
4
|
var _a, _b, _c;
|
|
5
|
+
this.history = [];
|
|
6
|
+
this.historyLimit = 0;
|
|
5
7
|
const { colors = {}, log, useColors, transportsByLevel } = options !== null && options !== void 0 ? options : {};
|
|
6
8
|
const { info = 'yellow', error = 'red' } = colors;
|
|
7
9
|
this.prefix = prefix;
|
|
@@ -17,6 +19,9 @@ export class Logger {
|
|
|
17
19
|
const isInteractive = (_c = (_b = (_a = getProcess()) === null || _a === void 0 ? void 0 : _a.stdout) === null || _b === void 0 ? void 0 : _b.isTTY) !== null && _c !== void 0 ? _c : false;
|
|
18
20
|
this.shouldUseColors = useColors !== false && isInteractive;
|
|
19
21
|
}
|
|
22
|
+
startTrackingHistory(limit) {
|
|
23
|
+
this.historyLimit = limit;
|
|
24
|
+
}
|
|
20
25
|
info(...args) {
|
|
21
26
|
return this.write(this.resolveChalk('green', this.colors.info), args, 'INFO');
|
|
22
27
|
}
|
|
@@ -30,6 +35,9 @@ export class Logger {
|
|
|
30
35
|
const childPrefix = this.combinePrefixes(prefix);
|
|
31
36
|
return new Logger(childPrefix, Object.assign({ log: this.baseLog, useColors: this.useColorsOption, transportsByLevel: this.transports }, options));
|
|
32
37
|
}
|
|
38
|
+
getHistory() {
|
|
39
|
+
return this.history;
|
|
40
|
+
}
|
|
33
41
|
write(chalkMethod, rawArgs, level) {
|
|
34
42
|
if (!this.shouldWrite(level)) {
|
|
35
43
|
return '';
|
|
@@ -37,10 +45,17 @@ export class Logger {
|
|
|
37
45
|
const shouldLog = this.shouldLog();
|
|
38
46
|
const formattedArgs = this.formatArgs(rawArgs);
|
|
39
47
|
const { prefix, logArgs: logArgs } = this.buildPrefixes(formattedArgs);
|
|
48
|
+
const joined = rawArgs.join(' ');
|
|
49
|
+
const flattened = prefix ? prefix + ' ' + joined : joined;
|
|
50
|
+
if (this.historyLimit > 0) {
|
|
51
|
+
this.history.push(flattened);
|
|
52
|
+
if (this.history.length > this.historyLimit) {
|
|
53
|
+
this.history.shift();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
40
56
|
if (!shouldLog ||
|
|
41
57
|
this.dispatchToTransports(level, prefix, formattedArgs)) {
|
|
42
|
-
|
|
43
|
-
return prefix ? prefix + ' ' + joined : joined;
|
|
58
|
+
return flattened;
|
|
44
59
|
}
|
|
45
60
|
const transport = this.resolveTransport(level, this.resolveConsoleMethod(level));
|
|
46
61
|
const message = this.buildMessage(chalkMethod, logArgs, level, prefix);
|
|
@@ -7,11 +7,15 @@ export declare class Logger implements Log {
|
|
|
7
7
|
private readonly colors;
|
|
8
8
|
private readonly pre;
|
|
9
9
|
private readonly shouldUseColors;
|
|
10
|
+
private history;
|
|
11
|
+
private historyLimit;
|
|
10
12
|
constructor(prefix?: string | undefined, options?: LogOptions);
|
|
13
|
+
startTrackingHistory(limit: number): void;
|
|
11
14
|
info(...args: LoggableType[]): string;
|
|
12
15
|
warn(...args: LoggableType[]): string;
|
|
13
16
|
error(...args: LoggableType[]): string;
|
|
14
17
|
buildLog(prefix?: string | undefined, options?: LogOptions): Log;
|
|
18
|
+
getHistory(): string[];
|
|
15
19
|
private write;
|
|
16
20
|
private shouldLog;
|
|
17
21
|
private resolveChalk;
|
|
@@ -54,6 +58,8 @@ export type LoggableType = Anything | Anything[] | Record<string, Anything>;
|
|
|
54
58
|
export type LogTransport = (...messageParts: string[]) => void;
|
|
55
59
|
type TransportMap = Record<Level, LogTransport | LogTransport[] | null | undefined>;
|
|
56
60
|
export interface Log {
|
|
61
|
+
startTrackingHistory(limit: number): void;
|
|
62
|
+
getHistory(): string[];
|
|
57
63
|
readonly prefix: string | undefined;
|
|
58
64
|
info: (...args: LoggableType[]) => string;
|
|
59
65
|
error: (...args: LoggableType[]) => string;
|
|
@@ -8,6 +8,8 @@ exports.default = buildLog;
|
|
|
8
8
|
const chalk_1 = __importDefault(require("chalk"));
|
|
9
9
|
class Logger {
|
|
10
10
|
constructor(prefix = undefined, options) {
|
|
11
|
+
this.history = [];
|
|
12
|
+
this.historyLimit = 0;
|
|
11
13
|
const { colors = {}, log, useColors, transportsByLevel } = options ?? {};
|
|
12
14
|
const { info = 'yellow', error = 'red' } = colors;
|
|
13
15
|
this.prefix = prefix;
|
|
@@ -23,6 +25,9 @@ class Logger {
|
|
|
23
25
|
const isInteractive = getProcess()?.stdout?.isTTY ?? false;
|
|
24
26
|
this.shouldUseColors = useColors !== false && isInteractive;
|
|
25
27
|
}
|
|
28
|
+
startTrackingHistory(limit) {
|
|
29
|
+
this.historyLimit = limit;
|
|
30
|
+
}
|
|
26
31
|
info(...args) {
|
|
27
32
|
return this.write(this.resolveChalk('green', this.colors.info), args, 'INFO');
|
|
28
33
|
}
|
|
@@ -41,6 +46,9 @@ class Logger {
|
|
|
41
46
|
...options,
|
|
42
47
|
});
|
|
43
48
|
}
|
|
49
|
+
getHistory() {
|
|
50
|
+
return this.history;
|
|
51
|
+
}
|
|
44
52
|
write(chalkMethod, rawArgs, level) {
|
|
45
53
|
if (!this.shouldWrite(level)) {
|
|
46
54
|
return '';
|
|
@@ -48,10 +56,17 @@ class Logger {
|
|
|
48
56
|
const shouldLog = this.shouldLog();
|
|
49
57
|
const formattedArgs = this.formatArgs(rawArgs);
|
|
50
58
|
const { prefix, logArgs: logArgs } = this.buildPrefixes(formattedArgs);
|
|
59
|
+
const joined = rawArgs.join(' ');
|
|
60
|
+
const flattened = prefix ? prefix + ' ' + joined : joined;
|
|
61
|
+
if (this.historyLimit > 0) {
|
|
62
|
+
this.history.push(flattened);
|
|
63
|
+
if (this.history.length > this.historyLimit) {
|
|
64
|
+
this.history.shift();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
51
67
|
if (!shouldLog ||
|
|
52
68
|
this.dispatchToTransports(level, prefix, formattedArgs)) {
|
|
53
|
-
|
|
54
|
-
return prefix ? prefix + ' ' + joined : joined;
|
|
69
|
+
return flattened;
|
|
55
70
|
}
|
|
56
71
|
const transport = this.resolveTransport(level, this.resolveConsoleMethod(level));
|
|
57
72
|
const message = this.buildMessage(chalkMethod, logArgs, level, prefix);
|