log.js 822 B

123456789101112131415161718192021222324252627282930313233
  1. "use strict";
  2. const config_config = require("../config/config.js");
  3. class log {
  4. static Debug(msg, ...other) {
  5. if (config_config.config.LOG_OPEN) {
  6. console.log(msg, other.length > 0 ? other[0] : "", log.stack());
  7. }
  8. }
  9. static stack() {
  10. let callingLocation = "";
  11. try {
  12. throw new Error();
  13. } catch (e) {
  14. const stack = e.stack;
  15. const lines = stack.split("\n");
  16. if (lines.length >= 4) {
  17. callingLocation = lines[3];
  18. }
  19. }
  20. return callingLocation;
  21. }
  22. static Error(msg, ...other) {
  23. if (config_config.config.LOG_OPEN) {
  24. console.error(msg, other.length > 0 ? other[0] : "");
  25. }
  26. }
  27. static Info(msg, ...other) {
  28. if (config_config.config.LOG_OPEN) {
  29. console.info(msg, other.length > 0 ? other[0] : "");
  30. }
  31. }
  32. }
  33. exports.log = log;