[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/yuilib/3.17.2/yui-log/ -> yui-log-debug.js (source)

   1  /*
   2  YUI 3.17.2 (build 9c3c78e)
   3  Copyright 2014 Yahoo! Inc. All rights reserved.
   4  Licensed under the BSD License.
   5  http://yuilibrary.com/license/
   6  */
   7  
   8  YUI.add('yui-log', function (Y, NAME) {
   9  
  10  /**
  11   * Provides console log capability and exposes a custom event for
  12   * console implementations. This module is a `core` YUI module,
  13   * <a href="../classes/YUI.html#method_log">it's documentation is located under the YUI class</a>.
  14   *
  15   * @module yui
  16   * @submodule yui-log
  17   */
  18  
  19  var INSTANCE = Y,
  20      LOGEVENT = 'yui:log',
  21      UNDEFINED = 'undefined',
  22      LEVELS = { debug: 1,
  23                 info: 2,
  24                 warn: 4,
  25                 error: 8 };
  26  
  27  /**
  28   * If the 'debug' config is true, a 'yui:log' event will be
  29   * dispatched, which the Console widget and anything else
  30   * can consume.  If the 'useBrowserConsole' config is true, it will
  31   * write to the browser console if available.  YUI-specific log
  32   * messages will only be present in the -debug versions of the
  33   * JS files.  The build system is supposed to remove log statements
  34   * from the raw and minified versions of the files.
  35   *
  36   * @method log
  37   * @for YUI
  38   * @param  {String}  msg  The message to log.
  39   * @param  {String}  cat  The log category for the message.  Default
  40   *                        categories are "info", "warn", "error", "debug".
  41   *                        Custom categories can be used as well. (opt).
  42   * @param  {String}  src  The source of the the message (opt).
  43   * @param  {boolean} silent If true, the log event won't fire.
  44   * @return {YUI}      YUI instance.
  45   */
  46  INSTANCE.log = function(msg, cat, src, silent) {
  47      var bail, excl, incl, m, f, minlevel,
  48          Y = INSTANCE,
  49          c = Y.config,
  50          publisher = (Y.fire) ? Y : YUI.Env.globalEvents;
  51      // suppress log message if the config is off or the event stack
  52      // or the event call stack contains a consumer of the yui:log event
  53      if (c.debug) {
  54          // apply source filters
  55          src = src || "";
  56          if (typeof src !== "undefined") {
  57              excl = c.logExclude;
  58              incl = c.logInclude;
  59              if (incl && !(src in incl)) {
  60                  bail = 1;
  61              } else if (incl && (src in incl)) {
  62                  bail = !incl[src];
  63              } else if (excl && (src in excl)) {
  64                  bail = excl[src];
  65              }
  66  
  67              // Set a default category of info if the category was not defined.
  68              if ((typeof cat === 'undefined')) {
  69                  cat = 'info';
  70              }
  71  
  72              // Determine the current minlevel as defined in configuration
  73              Y.config.logLevel = Y.config.logLevel || 'debug';
  74              minlevel = LEVELS[Y.config.logLevel.toLowerCase()];
  75  
  76              if (cat in LEVELS && LEVELS[cat] < minlevel) {
  77                  // Skip this message if the we don't meet the defined minlevel
  78                  bail = 1;
  79              }
  80          }
  81          if (!bail) {
  82              if (c.useBrowserConsole) {
  83                  m = (src) ? src + ': ' + msg : msg;
  84                  if (Y.Lang.isFunction(c.logFn)) {
  85                      c.logFn.call(Y, msg, cat, src);
  86                  } else if (typeof console !== UNDEFINED && console.log) {
  87                      f = (cat && console[cat] && (cat in LEVELS)) ? cat : 'log';
  88                      console[f](m);
  89                  } else if (typeof opera !== UNDEFINED) {
  90                      opera.postError(m);
  91                  }
  92              }
  93  
  94              if (publisher && !silent) {
  95  
  96                  if (publisher === Y && (!publisher.getEvent(LOGEVENT))) {
  97                      publisher.publish(LOGEVENT, {
  98                          broadcast: 2
  99                      });
 100                  }
 101  
 102                  publisher.fire(LOGEVENT, {
 103                      msg: msg,
 104                      cat: cat,
 105                      src: src
 106                  });
 107              }
 108          }
 109      }
 110  
 111      return Y;
 112  };
 113  
 114  /**
 115   * Write a system message.  This message will be preserved in the
 116   * minified and raw versions of the YUI files, unlike log statements.
 117   * @method message
 118   * @for YUI
 119   * @param  {String}  msg  The message to log.
 120   * @param  {String}  cat  The log category for the message.  Default
 121   *                        categories are "info", "warn", "error", "debug".
 122   *                        Custom categories can be used as well. (opt).
 123   * @param  {String}  src  The source of the the message (opt).
 124   * @param  {boolean} silent If true, the log event won't fire.
 125   * @return {YUI}      YUI instance.
 126   */
 127  INSTANCE.message = function() {
 128      return INSTANCE.log.apply(INSTANCE, arguments);
 129  };
 130  
 131  
 132  }, '3.17.2', {"requires": ["yui-base"]});


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1