]>
git.r.bdr.sh - rbdr/cologne/blob - lib/cobalt.js
45f0e26146342ccc99dd07e7d241b36a95aa309d
4 // Load up dependencies
5 if (typeof require
=== 'function') {
6 var Ne
= require('neon');
10 Module
= global
.Module
;
15 Module(Cobalt
, 'Logger')({});
16 Module(Cobalt
, 'Formatter')({});
18 // Load up loggers + formatters
19 if (typeof require
=== 'function') {
21 Cobalt
.Formatter
.Simple
= require('./formatters/simple.js').Simple
;
22 Cobalt
.Formatter
.Ansi
= require('./formatters/ansi.js').Ansi
;
23 Cobalt
.Formatter
.Token
= require('./formatters/token.js').Token
;
26 Cobalt
.Logger
.JsConsole
= require('./loggers/console.js').JsConsole
;
27 Cobalt
.Logger
.Socket
= require('./loggers/socket.js').Socket
;
30 Cobalt
.Console
= Class(Cobalt
, 'Console')({
32 from : "Generic Cobalt Logger",
37 separatorLength : 120,
38 currentColor : "black",
40 // Initialize instance of cobalt console
41 // and extend configuration.
42 init : function (config
) {
47 for (property
in config
) {
48 co
[property
] = config
[property
];
53 addLogger : function (logger
) {
54 this.loggers
.push(logger
);
57 removeLogger : function (logger
) {
60 index
= this.loggers
.indexOf(logger
);
61 this.loggers
.splice(index
, 1);
64 // Builds a Cobalt Log Object
65 buildLog : function (item
, level
) {
68 if (!item
._cobaltLog
) {
69 if (typeof item
!== "object") {
70 item
= { _cobaltLog : true, message : item
.toString() };
74 item
._level
= item
._level
|| level
|| 7;
75 item
._levelString
= co
._levelString(item
._level
);
76 item
._version
= co
.version
;
77 item
._timestamp
= co
.now();
78 item
._indentLevel
= co
.currentIndent
;
79 item
._color
= co
.currentColor
;
85 buildSeparator : function (type
) {
90 _version : co
.version
,
91 _timestamp : co
.now(),
92 _separatorType : type
,
93 _indentLevel : co
.currentIndent
97 _log : function (severity
) {
102 for (i
= 1; i
< arguments
.length
; i
++) {
103 logObject
= co
.buildLog(arguments
[i
], severity
);
105 for (j
= 0; j
< co
.loggers
.length
; j
++) {
106 co
.loggers
[j
].log(logObject
);
112 this._log
.apply(this, [7].concat([].splice
.call(arguments
, 0)));
116 this._log
.apply(this, [6].concat([].splice
.call(arguments
, 0)));
119 notice : function () {
120 this._log
.apply(this, [5].concat([].splice
.call(arguments
, 0)));
124 this._log
.apply(this, [4].concat([].splice
.call(arguments
, 0)));
127 error : function () {
128 this._log
.apply(this, [3].concat([].splice
.call(arguments
, 0)));
131 separator : function (type
) {
134 co
._log(7, co
.buildSeparator(type
));
137 space : function (lines
) {
141 if (typeof lines
=== "undefined") {
145 for (i
= 0; i
< lines
; i
++) {
152 indent : function (callback
) {
155 if (typeof callback
=== "function") {
156 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
158 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
160 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
166 outdent : function (callback
) {
169 if (typeof callback
=== "function") {
170 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
171 if (co
.currentIndent
< 0) {
172 co
.currentIndent
= 0;
177 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
179 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
180 if (co
.currentIndent
< 0) {
181 co
.currentIndent
= 0;
188 color : function (color
, callback
) {
190 oldColor
= co
.currentColor
;
192 if (typeof callback
=== "function") {
193 co
.currentColor
= color
;
195 co
.currentColor
= oldColor
;
197 co
.currentColor
= color
;
203 // Returns the current time in microseconds.
205 if (typeof performance
!== 'undefined') {
206 return performance
.timing
.navigationStart
+ performance
.now();
209 if (typeof process
!== 'undefined') {
210 return process
.hrtime();
216 _levelString : function (level
) {
247 if (typeof require
=== 'function') {
248 global
.Formatter
= Cobalt
.Formatter
;
249 global
.Logger
= Cobalt
.Logger
;
250 global
.Console
= Cobalt
.Console
;
252 global
.Cobalt
= Cobalt
;
255 }(typeof window
!== 'undefined' ? window : (typeof module
.exports
!== 'undefined' ? module
.exports : self
)));