log_utils.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:common_utils/common_utils.dart';
  2. import 'package:liftmanager/common/common.dart';
  3. class Log{
  4. static init() {
  5. print("Constant.inProduction");
  6. print(Constant.inProduction);
  7. LogUtil.init(isDebug: !Constant.inProduction);
  8. }
  9. static d(String msg, {tag: 'X-LOG'}) {
  10. if (!Constant.inProduction){
  11. LogUtil.v(msg, tag: tag);
  12. }
  13. }
  14. static e(String msg, {tag: 'X-LOG'}) {
  15. if (!Constant.inProduction){
  16. LogUtil.e(msg, tag: tag);
  17. }
  18. }
  19. static json(String msg, {tag: 'X-LOG'}) {
  20. if (!Constant.inProduction){
  21. LogUtil.v(msg, tag: tag);
  22. }
  23. }
  24. /// https://github.com/rhymelph/r_logger
  25. /// json format
  26. ///
  27. /// [s] your json
  28. static String jsonFormat(String s) {
  29. int level = 0;
  30. StringBuffer jsonForMatStr = StringBuffer();
  31. for (int index = 0; index < s.length; index++) {
  32. int c = s.codeUnitAt(index);
  33. if (level > 0 &&
  34. '\n'.codeUnitAt(0) ==
  35. jsonForMatStr.toString().codeUnitAt(jsonForMatStr.length - 1)) {
  36. jsonForMatStr.write(_getLevelStr(level));
  37. }
  38. if ('{'.codeUnitAt(0) == c || '['.codeUnitAt(0) == c) {
  39. jsonForMatStr.write(String.fromCharCode(c) + "\n");
  40. level++;
  41. } else if (','.codeUnitAt(0) == c) {
  42. jsonForMatStr.write(String.fromCharCode(c) + "\n");
  43. } else if ('}'.codeUnitAt(0) == c || ']'.codeUnitAt(0) == c) {
  44. jsonForMatStr.write("\n");
  45. level--;
  46. jsonForMatStr.write(_getLevelStr(level));
  47. jsonForMatStr.writeCharCode(c);
  48. } else {
  49. jsonForMatStr.writeCharCode(c);
  50. }
  51. }
  52. return jsonForMatStr.toString();
  53. }
  54. /// json level ping
  55. ///
  56. /// [level] your level
  57. static String _getLevelStr(int level) {
  58. StringBuffer levelStr = new StringBuffer();
  59. for (int levelI = 0; levelI < level; levelI++) {
  60. List<int> codeUnits = "\t".codeUnits;
  61. codeUnits.forEach((i) {
  62. levelStr.writeCharCode(i);
  63. });
  64. }
  65. return levelStr.toString();
  66. }
  67. }