UI for Zipcoin Blue

log.js 1000B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var logLevel = "info";
  2. function dummy() {}
  3. function shouldLog(level) {
  4. var shouldLog = (logLevel === "info" && level === "info") ||
  5. (["info", "warning"].indexOf(logLevel) >= 0 && level === "warning") ||
  6. (["info", "warning", "error"].indexOf(logLevel) >= 0 && level === "error");
  7. return shouldLog;
  8. }
  9. function logGroup(logFn) {
  10. return function(level, msg) {
  11. if(shouldLog(level)) {
  12. logFn(msg);
  13. }
  14. };
  15. }
  16. module.exports = function(level, msg) {
  17. if(shouldLog(level)) {
  18. if(level === "info") {
  19. console.log(msg);
  20. } else if(level === "warning") {
  21. console.warn(msg);
  22. } else if(level === "error") {
  23. console.error(msg);
  24. }
  25. }
  26. };
  27. var group = console.group || dummy;
  28. var groupCollapsed = console.groupCollapsed || dummy;
  29. var groupEnd = console.groupEnd || dummy;
  30. module.exports.group = logGroup(group);
  31. module.exports.groupCollapsed = logGroup(groupCollapsed);
  32. module.exports.groupEnd = logGroup(groupEnd);
  33. module.exports.setLogLevel = function(level) {
  34. logLevel = level;
  35. };