LogUtil.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package com.uas.esop.util;
  2. import android.util.Log;
  3. /**
  4. * @author zps 2016/3/4
  5. */
  6. public class LogUtil {
  7. private static boolean isDebug = true;//
  8. public static boolean isDebug() {
  9. return isDebug;
  10. }
  11. /**
  12. * @param tag
  13. * @param msg
  14. */
  15. public static void i(String tag, String msg) {
  16. if (isDebug) {
  17. Log.i(tag, msg);
  18. }
  19. }
  20. /**
  21. * @param object
  22. * @param msg
  23. */
  24. public static void i(Object object, String msg) {
  25. if (isDebug) {
  26. Log.i(object.getClass().getSimpleName(), msg);
  27. }
  28. }
  29. /**
  30. * @param tag
  31. * @param msg
  32. */
  33. public static void e(String tag, String msg) {
  34. if (isDebug) {
  35. Log.e(tag, msg);
  36. }
  37. }
  38. public static void edayin(String tag, String msg) {
  39. if (tag == null || tag.length() == 0
  40. || msg == null || msg.length() == 0)
  41. return;
  42. int segmentSize = 3 * 1024;
  43. long length = msg.length();
  44. if (length <= segmentSize ) {// 长度小于等于限制直接打印
  45. Log.e(tag, msg);
  46. }else {
  47. while (msg.length() > segmentSize ) {// 循环分段打印日志
  48. String logContent = msg.substring(0, segmentSize );
  49. msg = msg.replace(logContent, "");
  50. Log.e(tag, logContent);
  51. }
  52. Log.e(tag, msg);// 打印剩余日志
  53. }
  54. }
  55. /**
  56. * @param object
  57. * @param msg
  58. */
  59. public static void e(Object object, String msg) {
  60. if (isDebug) {
  61. Log.e(object.getClass().getSimpleName(), msg);
  62. }
  63. }
  64. public static void prinlnLongMsg(String TAG, String responseInfo) {
  65. if (responseInfo != null) {
  66. if (responseInfo.length() >=3000) {
  67. Log.v(TAG, "sb.length = " + responseInfo.length());
  68. int chunkCount = responseInfo.length() / 3000; // integer division
  69. for (int i = 0; i <= chunkCount; i++) {
  70. int max = 3000 * (i + 1);
  71. if (max >= responseInfo.length()) {
  72. Log.i(TAG, "【"+ i + "】" + responseInfo.substring(3000 * i));
  73. } else {
  74. Log.i(TAG, "【" + i+ "】" + responseInfo.substring(3000 * i, max));
  75. }
  76. }
  77. } else {
  78. Log.d(TAG, "sb.length = " + responseInfo.length());
  79. Log.i(TAG, responseInfo.toString());
  80. }
  81. }
  82. }
  83. }