3
Copyright 2012 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('yui-log-nodejs', function(Y) {
9
var sys = require(process.binding('natives').util ? 'util' : 'sys'),
13
var stdio = require("stdio");
14
hasColor = stdio.isStderrATTY();
19
Y.config.useColor = hasColor;
21
Y.consoleColor = function(str, num) {
22
if (!this.config.useColor) {
28
return "\033[" + num +"m" + str + "\033[0m"
32
var logFn = function(str, t, m) {
35
id = '[' + this.id + ']:';
38
m = (m) ? this.consoleColor(' (' + m.toLowerCase() + '):', 35) : '';
44
if ((typeof str === 'object') || str instanceof Array) {
47
if (str.tagName || str._yuid || str._query) {
50
str = sys.inspect(str);
57
var lvl = '37;40', mLvl = ((str) ? '' : 31);
58
t = t+''; //Force to a string..
59
switch (t.toLowerCase()) {
70
if (typeof str === 'string') {
71
if (str && str.indexOf("\n") !== -1) {
76
// output log messages to stderr
77
sys.error(this.consoleColor(t.toLowerCase() + ':', lvl) + m + ' ' + this.consoleColor(str, mLvl));
80
if (!Y.config.logFn) {
81
Y.config.logFn = logFn;
86
}, '3.5.1' ,{requires:['yui-log']});