Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. /**
  2. * Debug Light (formatting not support)
  3. * version 1.2
  4. * @param prefix - Print before a main message (ex. <PREFIX><MESSAGE>)
  5. * @constructor
  6. */
  7. function DebugLight(prefix) {
  8. this.on = function () {
  9. this.__LOG_ON = true;
  10. };
  11. this.off = function () {
  12. this.__LOG_ON = true;
  13. };
  14. this.setPrefix = function (prefix) {
  15. this.__LOG_PREFIX = prefix.toString();
  16. };
  17. this.__LOG_PREFIX = prefix ? prefix+' :: ' : '[DEBUG] :: ';
  18. this.__LOG_ON = false;
  19. this.log = function () {
  20. if (this.__LOG_ON) {
  21. console.log.apply(console, this.__getArgs(arguments));
  22. }
  23. };
  24. this.info = function () {
  25. if (this.__LOG_ON) {
  26. console.info.apply(console, this.__getArgs(arguments));
  27. }
  28. };
  29. this.warn = function () {
  30. if (this.__LOG_ON) {
  31. console.warn.apply(console, this.__getArgs(arguments));
  32. }
  33. };
  34. this.__getArgs = function(fn_args){
  35. var args = Array.prototype.slice.call(fn_args);
  36. args.unshift(this.__LOG_PREFIX);
  37. return args;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement