~ubuntu-branches/ubuntu/precise/maas/precise-security

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/yui-log-nodejs/yui-log-nodejs.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('yui-log-nodejs', function(Y) {
 
8
 
 
9
var sys = require(process.binding('natives').util ? 'util' : 'sys'),
 
10
    hasColor = false;
 
11
 
 
12
try {
 
13
    var stdio = require("stdio");
 
14
    hasColor = stdio.isStderrATTY();
 
15
} catch (ex) {
 
16
    hasColor = true;
 
17
}
 
18
 
 
19
Y.config.useColor = hasColor;
 
20
 
 
21
Y.consoleColor = function(str, num) {
 
22
    if (!this.config.useColor) {
 
23
        return str;
 
24
    }
 
25
    if (!num) {
 
26
        num = '32';
 
27
    }
 
28
    return "\033[" + num +"m" + str + "\033[0m"
 
29
};
 
30
 
 
31
 
 
32
var logFn = function(str, t, m) {
 
33
    var id = '';
 
34
    if (this.id) {
 
35
        id = '[' + this.id + ']:';
 
36
    }
 
37
    t = t || 'info';
 
38
    m = (m) ? this.consoleColor(' (' +  m.toLowerCase() + '):', 35) : '';
 
39
    
 
40
    if (str === null) {
 
41
        str = 'null';
 
42
    }
 
43
 
 
44
    if ((typeof str === 'object') || str instanceof Array) {
 
45
        try {
 
46
            //Should we use this?
 
47
            if (str.tagName || str._yuid || str._query) {
 
48
                str = str.toString();
 
49
            } else {
 
50
                str = sys.inspect(str);
 
51
            }
 
52
        } catch (e) {
 
53
            //Fail catcher
 
54
        }
 
55
    }
 
56
 
 
57
    var lvl = '37;40', mLvl = ((str) ? '' : 31);
 
58
    t = t+''; //Force to a string..
 
59
    switch (t.toLowerCase()) {
 
60
        case 'error':
 
61
            lvl = mLvl = 31;
 
62
            break;
 
63
        case 'warn':
 
64
            lvl = 33;
 
65
            break;
 
66
        case 'debug':
 
67
            lvl = 34;
 
68
            break;
 
69
    }
 
70
    if (typeof str === 'string') {
 
71
        if (str && str.indexOf("\n") !== -1) {
 
72
            str = "\n" + str;
 
73
        }
 
74
    }
 
75
 
 
76
    // output log messages to stderr
 
77
    sys.error(this.consoleColor(t.toLowerCase() + ':', lvl) + m + ' ' + this.consoleColor(str, mLvl));
 
78
};
 
79
 
 
80
if (!Y.config.logFn) {
 
81
    Y.config.logFn = logFn;
 
82
}
 
83
 
 
84
 
 
85
 
 
86
}, '3.5.1' ,{requires:['yui-log']});