File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1
1
import { ObjectifyError } from '@idl/error-shared' ;
2
2
import { DEFAULT_IDL_EXTENSION_CONFIG } from '@idl/vscode/extension-config' ;
3
+ import copy from 'fast-copy' ;
3
4
4
5
import {
5
6
DEFAULT_LOGGER_OPTIONS ,
7
+ DEFAULT_TRACKER ,
6
8
ILogManagerOptions ,
7
9
ILogOptions ,
8
10
LogInterceptor ,
@@ -25,8 +27,12 @@ import {
25
27
* Manages log collections with the ability to do console and/or file logging.
26
28
*/
27
29
export class LogManager implements ILogManagerOptions {
30
+ /** Are we debug mode or not? */
28
31
debug = DEFAULT_IDL_EXTENSION_CONFIG . debugMode ;
29
32
33
+ /** Track errors and warnings */
34
+ tracker = copy ( DEFAULT_TRACKER ) ;
35
+
30
36
/** How do we handle existing logs? */
31
37
mode : FileLogMode = LOGGING_CONFIG . FILE_LOG_MODE ;
32
38
@@ -152,6 +158,18 @@ export class LogManager implements ILogManagerOptions {
152
158
return ;
153
159
}
154
160
161
+ // track number of warnings or errors
162
+ switch ( options . type ) {
163
+ case 'error' :
164
+ this . tracker . errors ++ ;
165
+ break ;
166
+ case 'warn' :
167
+ this . tracker . warnings ++ ;
168
+ break ;
169
+ default :
170
+ break ;
171
+ }
172
+
155
173
// check if we have
156
174
if ( this . interceptor !== undefined ) {
157
175
// get data we are sending
@@ -200,4 +218,11 @@ export class LogManager implements ILogManagerOptions {
200
218
break ;
201
219
}
202
220
}
221
+
222
+ /**
223
+ * Reset counts for types of logs we are tracking
224
+ */
225
+ resetTracker ( ) {
226
+ this . tracker = copy ( DEFAULT_TRACKER ) ;
227
+ }
203
228
}
Original file line number Diff line number Diff line change @@ -45,3 +45,21 @@ export const DEFAULT_LOGGER_OPTIONS: ILogOptions = {
45
45
// dont include alert message otherwise we always print since it is present
46
46
// alert: IDL_TRANSLATION.logger.defaultErrorMessage,
47
47
} ;
48
+
49
+ /**
50
+ * Data structure to track different kinds of messages in the logger
51
+ */
52
+ export interface ILogManagerTracker {
53
+ /** NUmber of errors */
54
+ errors : number ;
55
+ /** Number of warnings */
56
+ warnings : number ;
57
+ }
58
+
59
+ /**
60
+ * Default values for tracker
61
+ */
62
+ export const DEFAULT_TRACKER : ILogManagerTracker = {
63
+ errors : 0 ,
64
+ warnings : 0 ,
65
+ } ;
You can’t perform that action at this time.
0 commit comments