API Docs for: 1.0.2
Show:

File: src\plugins\aw2-log.js

  1. /**
  2. *
  3. * aw2 library
  4. * log plugin
  5. *
  6. * @module aw2.log
  7. **/
  8. (function() {
  9. if(typeof(aw2) == "undefined") {
  10. console.log("aw2.log[error]: requires aw2 core library!");
  11. return false;
  12. }
  13.  
  14. /**
  15. * object providing Log storage and methods
  16. *
  17. * @class Log
  18. * @constructor
  19. **/
  20. function Log() {
  21. var self = this;
  22. var loggingEnabled = ["console"];
  23. var internalLog = [];
  24. var invokeLog = {
  25. "internal": function() {
  26. internalLog.push(arguments);
  27. },
  28. "console": function() {
  29. try {
  30. console.log.apply(console, arguments);
  31. } catch(e) {
  32. console.log(arguments);
  33. }
  34. },
  35. "alert": function() {
  36. alert(arguments);
  37. }
  38. };
  39.  
  40. /**
  41. * enables one or more specified logging types.
  42. *
  43. * @method enable
  44. * @param {String} logType* logging type(s)
  45. * @return {undefined}
  46. **/
  47. this.enable = function() {
  48. for(var arg in arguments) {
  49. if(aw2.isArray(arguments[arg])) {
  50. self.enable.apply(this, arguments[arg]);
  51. } else {
  52. if(typeof(arguments[arg]) == "string" && typeof(invokeLog[arguments[arg]]) != "undefined") {
  53. if(aw2.arrayContains(arguments[arg], loggingEnabled) == -1) {
  54. loggingEnabled.push(arguments[arg]);
  55. }
  56. }
  57. }
  58. }
  59. };
  60.  
  61. /**
  62. * disables one or more specified logging types.
  63. *
  64. * @method disable
  65. * @param {String} logType* logging type(s)
  66. * @return {undefined}
  67. **/
  68. this.disable = function() {
  69. for(var arg in arguments) {
  70. if(aw2.isArray(arguments[arg])) {
  71. self.disable.apply(this, arguments[arg]);
  72. } else {
  73. if(typeof(arguments[arg]) == "string" && typeof(invokeLog[arguments[arg]]) != "undefined") {
  74. var findLog = aw2.arrayContains(arguments[arg], loggingEnabled);
  75.  
  76. if(findLog >= 0) {
  77. loggingEnabled.splice(findLog, 1);
  78. }
  79. }
  80. }
  81. }
  82. };
  83.  
  84. /**
  85. * returns the types of logging currently being used.
  86. *
  87. * @method isLogging
  88. * @return {undefined}
  89. **/
  90. this.isLogging = function() {
  91. return loggingEnabled;
  92. };
  93.  
  94. /**
  95. * clears the internal log storage.
  96. *
  97. * @method clear
  98. * @return {undefined}
  99. **/
  100. this.clear = function() {
  101. internalLog.length = 0;
  102. };
  103.  
  104. /**
  105. * returns the internal logging array.
  106. *
  107. * @method get
  108. * @return {Array} the internal logs currently being stored
  109. **/
  110. this.get = function() {
  111. return internalLog;
  112. };
  113.  
  114. /**
  115. * the basic log function which will perform logging of inputs
  116. *
  117. * @method log
  118. * @param {any} data* data to be logged
  119. * @return {undefined}
  120. **/
  121. var log = function() {
  122. for(var thisLog in loggingEnabled) {
  123. invokeLog[loggingEnabled[thisLog]].apply(this, arguments);
  124. }
  125. };
  126.  
  127. return aw2.extend(log, this);
  128. }
  129.  
  130. /**
  131. * Container for Log plugin functions to be made available.
  132. *
  133. * @property $aw2.log
  134. * @type {Object}
  135. **/
  136. aw2.extend({
  137. log: new Log()
  138. });
  139. })();
  140.