src/helpers/log.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1.33

Size

Lines of Code 41
Function Count 6

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
wmc 8
c 1
b 0
f 0
nc 1
mnd 1
bc 8
fnc 6
dl 0
loc 41
rs 10
bpm 1.3333
cpm 1.3333
noi 4

6 Functions

Rating   Name   Duplication   Size   Complexity  
A log.js ➔ debug 0 3 1
A log.js ➔ shouldLog 0 3 1
A log.js ➔ warn 0 3 1
A log.js ➔ log 0 3 1
A log.js ➔ error 0 3 1
A log.js ➔ info 0 3 1
1
/*eslint no-unused-expressions: 0*/
2
/*eslint no-undef: 0*/
3
4
import { isUndefined } from 'lodash';
5
6
if (isUndefined(IS_LOGGING)) {
0 ignored issues
show
Bug introduced by
The variable IS_LOGGING seems to be never declared. If this is a global, consider adding a /** global: IS_LOGGING */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
7
  throw new Error('IS_LOGGING must be set.');
8
}
9
10
if (isUndefined(LOGGING_LEVEL)) {
0 ignored issues
show
Bug introduced by
The variable LOGGING_LEVEL seems to be never declared. If this is a global, consider adding a /** global: LOGGING_LEVEL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
11
  throw new Error('LOGGING_LEVEL must be set.');
12
}
13
14
export const LogLevels = {
15
  LOG: 1,
16
  INFO: 2,
17
  WARN: 3,
18
  ERROR: 4,
19
  DEBUG: 5
20
};
21
22
export function log() {
23
  shouldLog(LogLevels.LOG) && console.log.apply(console, arguments);
24
}
25
26
export function info() {
27
  shouldLog(LogLevels.INFO) && console.info.apply(console, arguments);
28
}
29
30
export function warn() {
31
  shouldLog(LogLevels.WARN) && console.warn.apply(console, arguments);
32
}
33
34
export function error() {
35
  shouldLog(LogLevels.ERROR) && console.error.apply(console, arguments);
36
}
37
38
export function debug() {
39
  shouldLog(LogLevels.DEBUG) && console.debug.apply(console, arguments);
40
}
41
42
function shouldLog(logLevel) {
43
  return Boolean(IS_LOGGING) && LOGGING_LEVEL >= logLevel;
0 ignored issues
show
Bug introduced by
The variable IS_LOGGING seems to be never declared. If this is a global, consider adding a /** global: IS_LOGGING */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable LOGGING_LEVEL seems to be never declared. If this is a global, consider adding a /** global: LOGGING_LEVEL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
44
}
45