Skip to content

Commit f4da1f3

Browse files
committed
[core] Fixing logging issues
1 parent d9e5927 commit f4da1f3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

api/utils/log.js

+17-10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ const ACCEPTABLE = {
7070
e: ['debug', 'info', 'warn', 'error'],
7171
};
7272

73+
const NAMES = {
74+
d: 'DEBUG',
75+
i: 'INFO',
76+
w: 'WARN',
77+
e: 'ERROR'
78+
};
79+
7380
/**
7481
* Returns logger function for given preferences
7582
* @param {string} level - log level
@@ -289,28 +296,28 @@ module.exports = function(name) {
289296
* @memberof module:api/utils/log~Logger
290297
* @param {...*} var_args - string and values to format string with
291298
**/
292-
d: log('DEBUG', name, getEnabledWithLevel(ACCEPTABLE.d, name), this, console.log),
299+
d: log(NAMES.d, name, getEnabledWithLevel(ACCEPTABLE.d, name), this, console.log),
293300

294301
/**
295302
* Log information level messages
296303
* @memberof module:api/utils/log~Logger
297304
* @param {...*} var_args - string and values to format string with
298305
**/
299-
i: log('INFO', name, getEnabledWithLevel(ACCEPTABLE.i, name), this, console.info),
306+
i: log(NAMES.i, name, getEnabledWithLevel(ACCEPTABLE.i, name), this, console.info),
300307

301308
/**
302309
* Log warning level messages
303310
* @memberof module:api/utils/log~Logger
304311
* @param {...*} var_args - string and values to format string with
305312
**/
306-
w: log('WARN', name, getEnabledWithLevel(ACCEPTABLE.w, name), this, console.warn, styles.stylers.warn),
313+
w: log(NAMES.w, name, getEnabledWithLevel(ACCEPTABLE.w, name), this, console.warn, styles.stylers.warn),
307314

308315
/**
309316
* Log error level messages
310317
* @memberof module:api/utils/log~Logger
311318
* @param {...*} var_args - string and values to format string with
312319
**/
313-
e: log('ERROR', name, getEnabledWithLevel(ACCEPTABLE.e, name), this, console.error, styles.stylers.error),
320+
e: log(NAMES.e, name, getEnabledWithLevel(ACCEPTABLE.e, name), this, console.error, styles.stylers.error),
314321

315322
/**
316323
* Log variable level messages (for cases when logging parameters calculation are expensive enough and shouldn't be done unless the level is enabled)
@@ -322,7 +329,7 @@ module.exports = function(name) {
322329
*/
323330
f: function(l, fn, fl, ...fargs) {
324331
if (ACCEPTABLE[l].indexOf(levels[name] || deflt) !== -1) {
325-
fn(log('ERROR', name, getEnabledWithLevel(ACCEPTABLE.e, name), this, console.error, styles.stylers.error));
332+
fn(log(NAMES[l], name, getEnabledWithLevel(ACCEPTABLE[l], name), this, l === 'e' ? console.error : l === 'w' ? console.warn : console.log, l === 'w' ? styles.stylers.warn : l === 'e' ? styles.stylers.error : undefined));
326333
return true;
327334
}
328335
else if (fl) {
@@ -395,28 +402,28 @@ module.exports = function(name) {
395402
* @memberof module:api/utils/log~Logger
396403
* @param {...*} var_args - string and values to format string with
397404
**/
398-
d: log('DEBUG', full, getEnabledWithLevel(ACCEPTABLE.d, full), this, console.log),
405+
d: log(NAMES.d, full, getEnabledWithLevel(ACCEPTABLE.d, full), this, console.log),
399406

400407
/**
401408
* Log information level messages
402409
* @memberof module:api/utils/log~Logger
403410
* @param {...*} var_args - string and values to format string with
404411
**/
405-
i: log('INFO', full, getEnabledWithLevel(ACCEPTABLE.i, full), this, console.info),
412+
i: log(NAMES.i, full, getEnabledWithLevel(ACCEPTABLE.i, full), this, console.info),
406413

407414
/**
408415
* Log warning level messages
409416
* @memberof module:api/utils/log~Logger
410417
* @param {...*} var_args - string and values to format string with
411418
**/
412-
w: log('WARN', full, getEnabledWithLevel(ACCEPTABLE.w, full), this, console.warn, styles.stylers.warn),
419+
w: log(NAMES.w, full, getEnabledWithLevel(ACCEPTABLE.w, full), this, console.warn, styles.stylers.warn),
413420

414421
/**
415422
* Log error level messages
416423
* @memberof module:api/utils/log~Logger
417424
* @param {...*} var_args - string and values to format string with
418425
**/
419-
e: log('ERROR', full, getEnabledWithLevel(ACCEPTABLE.e, full), this, console.error, styles.stylers.error),
426+
e: log(NAMES.e, full, getEnabledWithLevel(ACCEPTABLE.e, full), this, console.error, styles.stylers.error),
420427

421428
/**
422429
* Log variable level messages (for cases when logging parameters calculation are expensive enough and shouldn't be done unless the level is enabled)
@@ -428,7 +435,7 @@ module.exports = function(name) {
428435
*/
429436
f: function(l, fn, fl, ...fargs) {
430437
if (ACCEPTABLE[l].indexOf(levels[name] || deflt) !== -1) {
431-
fn(log(l, full, getEnabledWithLevel(ACCEPTABLE.e, full), this, console.error, l === 'w' ? styles.stylers.warn : l === 'e' ? styles.stylers.error : undefined));
438+
fn(log(NAMES[l], full, getEnabledWithLevel(ACCEPTABLE[l], full), this, l === 'e' ? console.error : l === 'w' ? console.warn : console.log, l === 'w' ? styles.stylers.warn : l === 'e' ? styles.stylers.error : undefined));
432439
return true;
433440
}
434441
else if (fl) {

0 commit comments

Comments
 (0)