Logger.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { _decorator} from 'cc';
  2. import { Constants } from '../data/Constants';
  3. const { ccclass, property } = _decorator;
  4. @ccclass('Logger')
  5. export class Logger{
  6. /**
  7. * 调试日志(生产环境代码会被完全移除)
  8. * 使用示例:
  9. * Logger.debug('当前状态:', state);
  10. */
  11. static log = Constants.isDebug
  12. ? (...args: any[]): void => {
  13. console.log('[DEBUG]', ...args);
  14. }
  15. : (): void => {}; // 生产环境空函数
  16. /**
  17. * 调试日志(生产环境代码会被完全移除)
  18. * 使用示例:
  19. * Logger.debug('当前状态:', state);
  20. */
  21. static error = Constants.isDebug
  22. ? (...args: any[]): void => {
  23. console.error('[DEBUG]', ...args);
  24. console.trace('调试堆栈');
  25. }
  26. : (): void => {}; // 生产环境空函数
  27. /**
  28. * 调试日志(生产环境代码会被完全移除)
  29. * 使用示例:
  30. * Logger.debug('当前状态:', state);
  31. */
  32. static warn = Constants.isDebug
  33. ? (...args: any[]): void => {
  34. console.warn('[DEBUG]', ...args);
  35. }
  36. : (): void => {}; // 生产环境空函数
  37. }