]>
git.r.bdr.sh - rbdr/cologne/blob - lib/cobalt.js
c832c7fd332f00c23ef72d26d2f9ef72ccddfce8
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
,
94 _color : co
.currentColor
98 _log : function (severity
) {
103 for (i
= 1; i
< arguments
.length
; i
++) {
104 logObject
= co
.buildLog(arguments
[i
], severity
);
106 for (j
= 0; j
< co
.loggers
.length
; j
++) {
107 co
.loggers
[j
].log(logObject
);
113 this._log
.apply(this, [7].concat([].splice
.call(arguments
, 0)));
117 this._log
.apply(this, [6].concat([].splice
.call(arguments
, 0)));
120 notice : function () {
121 this._log
.apply(this, [5].concat([].splice
.call(arguments
, 0)));
125 this._log
.apply(this, [4].concat([].splice
.call(arguments
, 0)));
128 error : function () {
129 this._log
.apply(this, [3].concat([].splice
.call(arguments
, 0)));
132 separator : function (type
) {
135 co
._log(7, co
.buildSeparator(type
));
138 space : function (lines
) {
142 if (typeof lines
=== "undefined") {
146 for (i
= 0; i
< lines
; i
++) {
153 indent : function (callback
) {
156 if (typeof callback
=== "function") {
157 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
159 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
161 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
167 outdent : function (callback
) {
170 if (typeof callback
=== "function") {
171 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
172 if (co
.currentIndent
< 0) {
173 co
.currentIndent
= 0;
178 co
.currentIndent
= co
.currentIndent
+ co
.indentSize
;
180 co
.currentIndent
= co
.currentIndent
- co
.indentSize
;
181 if (co
.currentIndent
< 0) {
182 co
.currentIndent
= 0;
189 color : function (color
, callback
) {
191 oldColor
= co
.currentColor
;
193 if (typeof callback
=== "function") {
194 co
.currentColor
= color
;
196 co
.currentColor
= oldColor
;
198 co
.currentColor
= color
;
204 // Returns the current time in microseconds.
206 if (typeof performance
!== 'undefined') {
207 return performance
.timing
.navigationStart
+ performance
.now();
210 if (typeof process
!== 'undefined') {
211 return process
.hrtime();
217 _levelString : function (level
) {
248 if (typeof require
=== 'function') {
249 global
.Formatter
= Cobalt
.Formatter
;
250 global
.Logger
= Cobalt
.Logger
;
251 global
.Console
= Cobalt
.Console
;
253 global
.Cobalt
= Cobalt
;
256 }(typeof window
!== 'undefined' ? window : (typeof module
.exports
!== 'undefined' ? module
.exports : self
)));