Skip to content

Commit cd598ed

Browse files
New API for logging
1 parent 3519437 commit cd598ed

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

libs/logger/src/lib/log-manager.class.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { ObjectifyError } from '@idl/error-shared';
22
import { DEFAULT_IDL_EXTENSION_CONFIG } from '@idl/vscode/extension-config';
3+
import copy from 'fast-copy';
34

45
import {
56
DEFAULT_LOGGER_OPTIONS,
7+
DEFAULT_TRACKER,
68
ILogManagerOptions,
79
ILogOptions,
810
LogInterceptor,
@@ -25,8 +27,12 @@ import {
2527
* Manages log collections with the ability to do console and/or file logging.
2628
*/
2729
export class LogManager implements ILogManagerOptions {
30+
/** Are we debug mode or not? */
2831
debug = DEFAULT_IDL_EXTENSION_CONFIG.debugMode;
2932

33+
/** Track errors and warnings */
34+
tracker = copy(DEFAULT_TRACKER);
35+
3036
/** How do we handle existing logs? */
3137
mode: FileLogMode = LOGGING_CONFIG.FILE_LOG_MODE;
3238

@@ -152,6 +158,18 @@ export class LogManager implements ILogManagerOptions {
152158
return;
153159
}
154160

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+
155173
// check if we have
156174
if (this.interceptor !== undefined) {
157175
// get data we are sending
@@ -200,4 +218,11 @@ export class LogManager implements ILogManagerOptions {
200218
break;
201219
}
202220
}
221+
222+
/**
223+
* Reset counts for types of logs we are tracking
224+
*/
225+
resetTracker() {
226+
this.tracker = copy(DEFAULT_TRACKER);
227+
}
203228
}

libs/logger/src/lib/log-manager.interface.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,21 @@ export const DEFAULT_LOGGER_OPTIONS: ILogOptions = {
4545
// dont include alert message otherwise we always print since it is present
4646
// alert: IDL_TRANSLATION.logger.defaultErrorMessage,
4747
};
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+
};

0 commit comments

Comments
 (0)