Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 5095782

Browse files
eldreygalindosilva-fabio
authored andcommitted
docs: add jsdoc to consolelogger
1 parent 14e8854 commit 5095782

3 files changed

Lines changed: 75 additions & 44 deletions

File tree

packages/opencensus-core/src/common/console-logger.ts

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,57 +19,88 @@ import {Logger, LoggerOptions} from './types';
1919
const logDriver = require('log-driver');
2020

2121

22-
class ConsoleLogger implements Logger {
23-
22+
/**
23+
* This class represente a console-logger
24+
*/
25+
class ConsoleLogger implements Logger {
2426
// tslint:disable:no-any
25-
private logger:any;
27+
private logger: any;
2628
static LEVELS = ['error', 'warn', 'info', 'debug', 'silly'];
2729

30+
/**
31+
* Constructs a new ConsoleLogger instance
32+
* @param options A logger configuration object.
33+
*/
2834
constructor(options?: LoggerOptions|string) {
2935
let opt: LoggerOptions = {};
30-
if (typeof options === "string") {
31-
opt = {
32-
level: options
33-
};
36+
if (typeof options === 'string') {
37+
opt = {level: options};
3438
} else {
3539
opt = options || {};
3640
}
3741

38-
this.logger = logDriver({
39-
levels: ConsoleLogger.LEVELS,
40-
level: opt.level || 'error'
41-
});
42+
this.logger =
43+
logDriver({levels: ConsoleLogger.LEVELS, level: opt.level || 'error'});
4244
}
4345

46+
/**
47+
* Logger error function.
48+
* @param message menssage erro to log in console
49+
* @param args arguments to log in console
50+
*/
4451
// tslint:disable:no-any
4552
error(message: any, ...args: any[]): void {
4653
this.logger.error(arguments);
4754
}
4855

56+
/**
57+
* Logger warning function.
58+
* @param message menssage warning to log in console
59+
* @param args arguments to log in console
60+
*/
4961
// tslint:disable:no-any
5062
warn(message: any, ...args: any[]): void {
5163
this.logger.warn(arguments);
5264
}
5365

66+
/**
67+
* Logger info function.
68+
* @param message menssage info to log in console
69+
* @param args arguments to log in console
70+
*/
5471
// tslint:disable:no-any
5572
info(message: any, ...args: any[]): void {
5673
this.logger.info(arguments);
5774
}
5875

76+
/**
77+
* Logger debug function.
78+
* @param message menssage debug to log in console
79+
* @param args arguments to log in console
80+
*/
5981
// tslint:disable:no-any
60-
debug (message: any, ...args: any[]): void {
82+
debug(message: any, ...args: any[]): void {
6183
this.logger.debug(arguments);
6284
}
6385

86+
/**
87+
* Logger silly function.
88+
* @param message menssage silly to log in console
89+
* @param args arguments to log in console
90+
*/
6491
// tslint:disable:no-any
65-
silly (message: any, ...args: any[]): void {
92+
silly(message: any, ...args: any[]): void {
6693
this.logger.silly(arguments);
6794
}
6895
}
6996

7097
let defaultLogger = null;
7198

72-
const logger = (options?: LoggerOptions|string) => {
99+
/**
100+
* Function logger exported to others classes.
101+
* @param options A logger options or strig to logger in console
102+
*/
103+
const logger = (options?: LoggerOptions|string) => {
73104
defaultLogger = new ConsoleLogger(options);
74105
logger['logger'] = defaultLogger;
75106
return defaultLogger;

packages/opencensus-core/src/common/types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
// tslint:disable:no-any
17+
// tslint:disable:no-any
1818
export type LogFunction = (message: any, ...args: any[]) => void;
1919

20+
/** Defines an logger interface. */
2021
export interface Logger {
2122
error: LogFunction;
2223
warn: LogFunction;
@@ -25,8 +26,8 @@ export interface Logger {
2526
silly: LogFunction;
2627
}
2728

29+
/** Defines an logger options interface. */
2830
export interface LoggerOptions {
2931
level?: string;
3032
tag?: string;
3133
}
32-

packages/opencensus-core/test/test-console-logger.ts

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,153 +22,152 @@ const LEVELS = ['error', 'warn', 'info', 'debug', 'silly'];
2222
let consoleTxt = '';
2323

2424

25-
26-
2725
describe('ConsoleLogger', () => {
2826
const intercept = require('intercept-stdout');
2927
const unhookIntercept = intercept((txt) => {
3028
consoleTxt = txt;
3129
return txt;
3230
});
31+
32+
/** Should create a new ConsoleLogger */
3333
describe('new ConsoleLogger()', () => {
34-
it('should levels from consoleLogger equals default levels', () => {
34+
it('should consoleLogger with default levels', () => {
3535
const consoleLogger = logger();
3636
assert.equal(LEVELS.length, consoleLogger.logger.levels.length);
3737
});
3838

39-
it('should level from consoleLogger equal error', () => {
39+
it('should consoleLogger with error', () => {
4040
const consoleLogger = logger(LEVELS[0]);
4141
assert.strictEqual(LEVELS[0], consoleLogger.logger.level);
4242
});
4343
});
4444

45-
/**
46-
*
47-
*/
45+
/** Should logger only error log */
4846
describe('error logger', () => {
4947
const consoleLogger = logger(LEVELS[0]);
5048

51-
it('should logger error in console', () => {
49+
it('should logger error', () => {
5250
consoleTxt = '';
53-
consoleLogger.error('error test logger in console');
51+
consoleLogger.error('error test logger');
5452
unhookIntercept();
5553
const validateString = consoleTxt.indexOf('error');
5654

5755
assert.ok(validateString >= 0);
5856
});
5957

60-
it('should not logger warn in console', () => {
58+
it('should not logger warn', () => {
6159
consoleTxt = '';
62-
consoleLogger.warn('warn test logger in console');
60+
consoleLogger.warn('warn test logger');
6361
unhookIntercept();
6462

6563
const validateString = consoleTxt.indexOf('warn');
6664

6765
assert.equal(validateString, -1);
6866
});
6967

70-
it('should not logger info in console', () => {
68+
it('should not logger info', () => {
7169
consoleTxt = '';
72-
consoleLogger.info('info test logger in console');
70+
consoleLogger.info('info test logger');
7371
unhookIntercept();
7472

7573
const validateString = consoleTxt.indexOf('info');
7674

7775
assert.equal(validateString, -1);
7876
});
7977

80-
it('should not logger debug in console', () => {
78+
it('should not logger debug', () => {
8179
consoleTxt = '';
82-
consoleLogger.debug('debug test logger in console');
80+
consoleLogger.debug('debug test logger');
8381
unhookIntercept();
8482
const validateString = consoleTxt.indexOf('debug');
8583

8684
assert.equal(validateString, -1);
8785
});
8886

89-
it('should not logger silly in console', () => {
87+
it('should not logger silly', () => {
9088
consoleTxt = '';
91-
consoleLogger.silly('silly test logger in console');
89+
consoleLogger.silly('silly test logger');
9290
unhookIntercept();
9391
const validateString = consoleTxt.indexOf('silly');
9492

9593
assert.equal(validateString, -1);
9694
});
9795
});
98-
96+
97+
/** Should logger error, warn and info log */
9998
describe('info logger', () => {
10099

101100
const consoleLogger = logger(LEVELS[2]);
102101

103-
it('should logger error in console', () => {
102+
it('should logger error', () => {
104103
const intercept = require('intercept-stdout');
105104
const unhookIntercept = intercept((txt) => {
106105
consoleTxt = txt;
107106
return txt;
108107
});
109108

110109
consoleTxt = '';
111-
consoleLogger.error('error test logger in console');
110+
consoleLogger.error('error test logger');
112111
unhookIntercept();
113112
const validateString = consoleTxt.indexOf('error');
114113

115114
assert.ok(validateString >= 0);
116115
});
117116

118-
it('should not logger warn in console', () => {
117+
it('should not logger warn', () => {
119118
const intercept = require('intercept-stdout');
120119
const unhookIntercept = intercept((txt) => {
121120
consoleTxt = txt;
122121
return txt;
123122
});
124123

125124
consoleTxt = '';
126-
consoleLogger.warn('warn test logger in console');
125+
consoleLogger.warn('warn test logger');
127126
unhookIntercept();
128127
const validateString = consoleTxt.indexOf('warn');
129128

130129
assert.ok(validateString >= 0);
131130
});
132131

133-
it('should logger info in console', () => {
132+
it('should logger info', () => {
134133
const intercept = require('intercept-stdout');
135134
const unhookIntercept = intercept((txt) => {
136135
consoleTxt = txt;
137136
return txt;
138137
});
139138

140139
consoleTxt = '';
141-
consoleLogger.info('info test logger in console');
140+
consoleLogger.info('info test logger');
142141
unhookIntercept();
143142
const validateString = consoleTxt.indexOf('info');
144143

145144
assert.ok(validateString >= 0);
146145
});
147146

148-
it('should not logger debug in console', () => {
147+
it('should not logger debug', () => {
149148
const intercept = require('intercept-stdout');
150149
const unhookIntercept = intercept((txt) => {
151150
consoleTxt = txt;
152151
return txt;
153152
});
154153

155154
consoleTxt = '';
156-
consoleLogger.debug('debug test logger in console');
155+
consoleLogger.debug('debug test logger');
157156
unhookIntercept();
158157
const validateString = consoleTxt.indexOf('debug');
159158

160159
assert.equal(validateString, -1);
161160
});
162161

163-
it('should not logger silly in console', () => {
162+
it('should not logger silly', () => {
164163
const intercept = require('intercept-stdout');
165164
const unhookIntercept = intercept((txt) => {
166165
consoleTxt = txt;
167166
return txt;
168167
});
169168

170169
consoleTxt = '';
171-
consoleLogger.silly('silly test logger in console');
170+
consoleLogger.silly('silly test logger');
172171
unhookIntercept();
173172
const validateString = consoleTxt.indexOf('silly');
174173

0 commit comments

Comments
 (0)