-
Notifications
You must be signed in to change notification settings - Fork 187
/
Copy pathtypes.ts
192 lines (161 loc) · 4.27 KB
/
types.ts
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import type { LogLevel, LogType } from "./constants";
export interface ConsolaOptions {
/**
* An array of ConsolaReporter instances used to handle and output log messages.
*/
reporters: ConsolaReporter[];
/**
* A record mapping LogType to InputLogObject, defining the log configuration for each log type.
* See {@link LogType} and {@link InputLogObject}.
*/
types: Record<LogType, InputLogObject>;
/**
* The minimum log level to output. See {@link LogLevel}.
*/
level: LogLevel;
/**
* Default properties applied to all log messages unless overridden. See {@link InputLogObject}.
*/
defaults: InputLogObject;
/**
* The maximum number of times a log message can be repeated within a given timeframe.
*/
throttle: number;
/**
* The minimum time in milliseconds that must elapse before a throttled log message can be logged again.
*/
throttleMin: number;
/**
* The Node.js writable stream for standard output. See {@link NodeJS.WriteStream}.
* @optional
*/
stdout?: NodeJS.WriteStream;
/**
* The Node.js writeable stream for standard error output. See {@link NodeJS.WriteStream}.
* @optional
*/
stderr?: NodeJS.WriteStream;
/**
* A function that allows you to mock log messages for testing purposes.
* @optional
*/
mockFn?: (type: LogType, defaults: InputLogObject) => (...args: any) => void;
/**
* Custom prompt function to use. It can be undefined.
* @optional
*/
prompt?: typeof import("./prompt").prompt | undefined;
/**
* Configuration options for formatting log messages. See {@link FormatOptions}.
*/
formatOptions: FormatOptions;
}
/**
* @see https://nodejs.org/api/util.html#util_util_inspect_object_showhidden_depth_colors
*/
export interface FormatOptions {
/**
* The maximum number of columns to output, affects formatting.
* @optional
*/
columns?: number;
/**
* Whether to include timestamp information in log messages.
* @optional
*/
date?: boolean;
/**
* Whether to use colors in the output.
* @optional
*/
colors?: boolean;
/**
* Specifies whether or not the output should be compact. Accepts a boolean or numeric level of compactness.
* @optional
*/
compact?: boolean | number;
/**
* Error cause level.
*/
errorLevel?: number;
/**
* Allows additional custom formatting options.
*/
[key: string]: unknown;
}
export interface InputLogObject {
/**
* The logging level of the message. See {@link LogLevel}.
* @optional
*/
level?: LogLevel;
/**
* A string tag to categorise or identify the log message.
* @optional
*/
tag?: string;
/**
* The type of log message, which affects how it's processed and displayed. See {@link LogType}.
* @optional
*/
type?: LogType;
/**
* The main log message text.
* @optional
*/
message?: string;
/**
* Additional text or texts to be logged with the message.
* @optional
*/
additional?: string | string[];
/**
* Additional arguments to be logged with the message.
* @optional
*/
args?: any[];
/**
* The date and time when the log message was created.
* @optional
*/
date?: Date;
}
export interface LogObject extends InputLogObject {
/**
* The logging level of the message, overridden if required. See {@link LogLevel}.
*/
level: LogLevel;
/**
* The type of log message, overridden if required. See {@link LogType}.
*/
type: LogType;
/**
* A string tag to categorise or identify the log message, overridden if necessary.
*/
tag: string;
/**
* Additional arguments to be logged with the message, overridden if necessary.
*/
args: any[];
/**
* The date and time the log message was created, overridden if necessary.
*/
date: Date;
/**
* Allows additional custom properties to be set on the log object.
*/
[key: string]: unknown;
}
export interface ConsolaReporter {
/**
* Defines how a log message is processed and displayed by this reporter.
* @param logObj The LogObject containing the log information to process. See {@link LogObject}.
* @param ctx An object containing context information such as options. See {@link ConsolaOptions}.
*/
log: (
logObj: LogObject,
ctx: {
options: ConsolaOptions;
},
) => void;
}