]>
git.r.bdr.sh - rbdr/cologne/blob - lib/cobalt.js
771c9c77e9ae8921953abbd7fab0bc8b1490317f
4 // Load up dependencies
5 if (typeof require
=== 'function') {
6 var Ne
= require('neon');
9 var Microtime
= require('microtime');
11 Module
= global
.Module
;
16 Module(Cobalt
, 'Logger')({});
17 Module(Cobalt
, 'Formatter')({});
19 // Load up loggers + formatters
20 if (typeof require
=== 'function') {
22 Cobalt
.Formatter
.Simple
= require('./formatters/simple.js').Simple
;
23 Cobalt
.Formatter
.Ansi
= require('./formatters/ansi.js').Ansi
;
24 Cobalt
.Formatter
.Token
= require('./formatters/token.js').Token
;
27 Cobalt
.Logger
.JsConsole
= require('./loggers/console.js').JsConsole
;
28 Cobalt
.Logger
.Socket
= require('./loggers/socket.js').Socket
;
31 Cobalt
.Console
= Class(Cobalt
, 'Console')({
33 from : "Generic Cobalt Logger",
38 separatorLength : 120,
39 currentColor : "black",
41 // Initialize instance of cobalt console
42 // and extend configuration.
43 init : function (config
) {
48 for (property
in config
) {
49 co
[property
] = config
[property
];
54 addLogger : function (logger
) {
55 this.loggers
.push(logger
);
58 removeLogger : function (logger
) {
61 index
= this.loggers
.indexOf(logger
);
62 this.loggers
.splice(index
, 1);
65 // Builds a Cobalt Log Object
66 buildLog : function (item
, level
) {
69 if (!item
._cobaltLog
) {
70 if (typeof item
!== "object") {
71 item
= { _cobaltLog : true, message : item
.toString() };
75 item
._level
= item
._level
|| level
|| 7;
76 item
._levelString
= co
._levelString(item
._level
);
77 item
._version
= co
.version
;
78 item
._timestamp
= co
.now();
79 item
._indentLevel
= co
.currentIndent
;
80 item
._color
= co
.currentColor
;
86 buildSeparator : function (type
) {
91 _version : co
.version
,
92 _timestamp : co
.now(),
93 _separatorType : type
,
94 _indentLevel : co
.currentIndent
,
95 _color : co
.currentColor
99 _log : function (severity
) {
104 for (i
= 1; i
< arguments
.length
; i
++) {
105 logObject
= co
.buildLog(arguments
[i
], severity
);
107 for (j
= 0; j
< co
.loggers
.length
; j
++) {
108 co
.loggers
[j
].log(logObject
);
114 this._log
.apply(this, [7].concat([].splice
.call(arguments
, 0)));
118 this._log
.apply(this, [6].concat([].splice
.call(arguments
, 0)));
121 notice : function () {
122 this._log
.apply(this, [5].concat([].splice
.call(arguments
, 0)));
126 this._log
.apply(this, [4].concat([].splice
.call(arguments
, 0)));
129 error : function () {
130 this._log
.apply(this, [3].concat([].splice
.call(arguments
, 0)));
133 separator : function (type
) {
136 co
._log(7, co
.buildSeparator(type
));
139 space : function (lines
) {
143 if (typeof lines
=== "undefined") {
147 for (i
= 0; i
< lines
; i
++) {
154 indent : function (callback
) {
157 if (typeof callback
=== "function") {
158 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
160 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
162 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
168 outdent : function (callback
) {
171 if (typeof callback
=== "function") {
172 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
173 if (co
.currentIndent
< 0) {
174 co
.currentIndent
= 0;
179 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
181 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
182 if (co
.currentIndent
< 0) {
183 co
.currentIndent
= 0;
190 color : function (color
, callback
) {
192 oldColor
= co
.currentColor
;
194 if (typeof callback
=== "function") {
195 co
.currentColor
= color
;
197 co
.currentColor
= oldColor
;
199 co
.currentColor
= color
;
205 // Returns the current time in microseconds.
207 if (typeof performance
!== 'undefined') {
208 return performance
.timing
.navigationStart
+ performance
.now();
211 if (typeof Microtime
!== 'undefined') {
212 return Microtime
.nowDouble() * 1000;
218 _levelString : function (level
) {
249 if (typeof require
=== 'function') {
250 global
.Formatter
= Cobalt
.Formatter
;
251 global
.Logger
= Cobalt
.Logger
;
252 global
.Console
= Cobalt
.Console
;
254 global
.Cobalt
= Cobalt
;
257 }(typeof window
!== 'undefined' ? window : (typeof module
.exports
!== 'undefined' ? module
.exports : self
)));