aboutsummaryrefslogtreecommitdiff
path: root/lib/formatters/ansi.js
blob: 25ad2565b2813e6a8cb15aee07a67a6144695697 (plain)
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
(function (global) {
  var Module;

  // Load up dependencies
  if (typeof require === 'function') {
    require('colors');
    var Ne = require('neon');
    Module = Ne.Module;
  } else {
    Module = global.Module;
  }

  var Cobalt = {};
  Module(Cobalt, 'Formatter')({});

  Cobalt.Formatter.Ansi = Module(Cobalt.Formatter, 'Ansi')({
    format : function (logObject, opts){
      var indent,
          message;

      indent = Array(logObject._indentLevel + 1).join(' ');

      message = indent + logObject.message;

      switch(logObject._level) {
        case 0:
        case 1:
        case 2:
        case 3:
          return message.red;
        case 4:
          return message.yellow;
        case 5:
        case 6:
          return message.blue;
        default:
          return message;
      }
    }
  });

  if (typeof require === 'function') {
    global.Ansi = Cobalt.Formatter.Ansi;
  } else {
    global.Cobalt.Formatter.Ansi = Cobalt.Formatter.Ansi;
  }
}(typeof window !== 'undefined' ? window : (typeof exports !== 'undefined' ? exports : self)));