# All files / lib levels.js

40% Statements 10/25
31.25% Branches 5/16
57.14% Functions 4/7
40% Lines 10/25

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86

    18x
    18x

    14x

    3x

    3x

    17x

    17x

    17x
    17x

    2x

     'use strict';

    /**
     * @name Level
     * @namespace Log4js
     */
    class Level {
      constructor(level, levelStr) {
        this.level = level;
        this.levelStr = levelStr;
      }

      toString() {
        return this.levelStr;
      }

      isLessThanOrEqualTo(otherLevel) {
        Iif (typeof otherLevel === 'string') {
          otherLevel = toLevel(otherLevel);
        }
        return this.level <= otherLevel.level;
      }

      isGreaterThanOrEqualTo(otherLevel) {
        if (typeof otherLevel === 'string') {
          otherLevel = toLevel(otherLevel);
        }
        return this.level >= otherLevel.level;
      }

      isEqualTo(otherLevel) {
        if (typeof otherLevel === 'string') {
          otherLevel = toLevel(otherLevel);
        }
        return this.level === otherLevel.level;
      }

    }

    /**
     * converts given String to corresponding Level
     * @param {Level|String} sArg -- String value of Level OR Log4js.Level
     * @param {Level} [defaultLevel] -- default Level, if no String representation
     * @return {Level}
     */
    function toLevel(sArg, defaultLevel) {
      Iif (!sArg) {
        return defaultLevel;
      }

      Iif (sArg instanceof Level) {
        module.exports[sArg.toString()] = sArg;
        return sArg;
      }

      Eif (typeof sArg === 'string') {
        return module.exports[sArg.toUpperCase()] || defaultLevel;
      }

      return toLevel(sArg.toString());
    }

    function getLevel(levelStr) {
      let level;
      if (typeof levelStr === 'string') {
        const levelUpper = levelStr.toUpperCase();
        level = toLevel(levelUpper);
      }
      return level;
    }

    module.exports = {
      ALL: new Level(Number.MIN_VALUE, 'ALL'),
      TRACE: new Level(5000, 'TRACE'),
      DEBUG: new Level(10000, 'DEBUG'),
      INFO: new Level(20000, 'INFO'),
      WARN: new Level(30000, 'WARN'),
      ERROR: new Level(40000, 'ERROR'),
      FATAL: new Level(50000, 'FATAL'),
      MARK: new Level(9007199254740992, 'MARK'), // 2^53
      OFF: new Level(Number.MAX_VALUE, 'OFF'),
      toLevel: toLevel,
      Level: Level,
      getLevel: getLevel
    };