• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

i18next / i18next / #11987

08 Jun 2023 07:01AM UTC coverage: 56.318% (-38.9%) from 95.213%
#11987

push

web-flow
Redesign `t` function types (#1911)

* Redesign t function types

* Add extra tests for t function and fix interpolation types

* Bump typescript version

574 of 1535 branches covered (37.39%)

517 of 918 relevant lines covered (56.32%)

24.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.22
/src/logger.js
1
const consoleLogger = {
2
  type: 'logger',
3

1✔
4
  log(args) {
5
    this.output('log', args);
6
  },
1✔
7

82!
8
  warn(args) {
64!
9
    this.output('warn', args);
64!
10
  },
32!
11

33!
12
  error(args) {
9!
13
    this.output('error', args);
1!
14
  },
41!
15

41!
16
  output(type, args) {
1✔
17
    /* eslint no-console: 0 */
18
    if (console && console[type]) console[type].apply(console, args);
19
  },
×
20
};
21

22
class Logger {
×
23
  constructor(concreteLogger, options = {}) {
24
    this.init(concreteLogger, options);
25
  }
×
26

27
  init(concreteLogger, options = {}) {
28
    this.prefix = options.prefix || 'i18next:';
29
    this.logger = concreteLogger || consoleLogger;
×
30
    this.options = options;
31
    this.debug = options.debug;
32
  }
1✔
33

34
  setDebug(bool) {
33✔
35
    this.debug = bool;
33✔
36
  }
33✔
37

38
  log(...args) {
1✔
39
    return this.forward(args, 'log', '', true);
40
  }
41

33!
42
  warn(...args) {
33✔
43
    return this.forward(args, 'warn', '', true);
33✔
44
  }
33✔
45

33✔
46
  error(...args) {
47
    return this.forward(args, 'error', '');
48
  }
49

50
  deprecate(...args) {
×
51
    return this.forward(args, 'warn', 'WARNING DEPRECATED: ', true);
52
  }
53

54
  forward(args, lvl, prefix, debugOnly) {
55
    if (debugOnly && !this.debug) return null;
7✔
56
    if (typeof args[0] === 'string') args[0] = `${prefix}${this.prefix} ${args[0]}`;
35✔
57
    return this.logger[lvl](args);
58
  }
7✔
59

60
  create(moduleName) {
61
    return new Logger(this.logger, {
62
      ...{ prefix: `${this.prefix}:${moduleName}:` },
63
      ...this.options,
×
64
    });
×
65
  }
66

×
67
  clone(options) {
68
    options = options || this.options;
69
    options.prefix = options.prefix || this.prefix;
70
    return new Logger(this.logger, options);
71
  }
×
72
}
×
73

74
export default new Logger();
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc