LogHelper.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. //package com.example.xiaoshiweixinback.business.utils;
  2. //
  3. //import org.slf4j.Logger;
  4. //import org.slf4j.LoggerFactory;
  5. //import org.slf4j.MDC;
  6. //
  7. //import java.io.PrintWriter;
  8. //import java.io.StringWriter;
  9. //
  10. //
  11. ///**
  12. // * 日志工具类
  13. // *
  14. // * @author Peach
  15. // */
  16. //
  17. //public class LogHelper {
  18. //
  19. // private static Logger logger = null;
  20. //
  21. // //------------------------------------------系统日志记录-------------------------
  22. //
  23. // /**
  24. // * @param info
  25. // */
  26. //
  27. // public static void log(Object... info) {
  28. // logger = LoggerFactory.getLogger("");
  29. // logger.info("info={}", info);
  30. // }
  31. //
  32. // public static void log(Throwable e, Object... info) {
  33. // logger = LoggerFactory.getLogger("");
  34. // logger.info("exception={} info={}", throwable2String(e), info);
  35. // }
  36. //
  37. //
  38. // /**
  39. // * @param clazz
  40. // * @param info
  41. // */
  42. //
  43. // public static void log(Class clazz, String info) {
  44. // logger = LoggerFactory.getLogger(clazz);
  45. // logger.info(info);
  46. // }
  47. //
  48. //
  49. // /**
  50. // * @param clazz
  51. // * @param e
  52. // */
  53. //
  54. // public static void log(Class clazz, Throwable e) {
  55. // log(clazz, throwable2String(e));
  56. // }
  57. //
  58. // /**
  59. // * @param name
  60. // * @param info
  61. // */
  62. //
  63. // @Deprecated
  64. // public static void log(String name, String info) {
  65. // logger = LoggerFactory.getLogger(name);
  66. // logger.info(name + "-" + info);
  67. // }
  68. //
  69. //
  70. // /**
  71. // * @param name
  72. // * @param e
  73. // */
  74. //
  75. // @Deprecated
  76. // public static void log(String name, Throwable e) {
  77. // log(name, throwable2String(e));
  78. // }
  79. //
  80. //
  81. // /**
  82. // * @param name
  83. // * @param info
  84. // * @param e
  85. // */
  86. // @Deprecated
  87. // public static void log(String name, String info, Throwable e) {
  88. // log(name, info + "-" + throwable2String(e));
  89. // }
  90. //
  91. //
  92. // /**
  93. // * @param clazz
  94. // * @param info
  95. // * @param e
  96. // */
  97. // public static void log(Class clazz, String info, Throwable e) {
  98. // log(clazz, info + "-" + throwable2String(e));
  99. // }
  100. //
  101. //
  102. // /**
  103. // * 将异常信息转为string
  104. // *
  105. // * @param e
  106. // * @return
  107. // */
  108. //
  109. // private static String throwable2String(Throwable e) {
  110. // if (checkBaseBusinessException(e)) {
  111. // BaseBusinessException bbe = (BaseBusinessException) e;
  112. // return "----->" + bbe.getErrorMessage() + (bbe.getExtraMessage() == null ? "" : bbe.getExtraMessage());
  113. // }
  114. // PrintWriter pw = null;
  115. // StringWriter sw = null;
  116. // try {
  117. // sw = new StringWriter();
  118. // pw = new PrintWriter(sw);
  119. // e.printStackTrace(pw);
  120. // pw.flush();
  121. // sw.flush();
  122. // } catch (Exception e1) {
  123. // logger.info(e.getMessage());
  124. // } finally {
  125. // if (sw != null) {
  126. // try {
  127. // sw.close();
  128. // } catch (Exception e2) {
  129. // e2.printStackTrace();
  130. // return "";
  131. // }
  132. // } else {
  133. // return "";
  134. // }
  135. // if (pw != null) {
  136. // pw.close();
  137. // }
  138. // return sw.toString();
  139. // }
  140. //
  141. // }
  142. //
  143. //
  144. // /**
  145. // * @param @param e
  146. // * @param @return 参数
  147. // * @return boolean 返回类型
  148. // * @throws
  149. // * @Title: checkBaseBusinessException
  150. // * @Description: 判断异常是否为系统异常
  151. // * @author Orange
  152. // * @date 2019年1月23日
  153. // */
  154. //
  155. // private static boolean checkBaseBusinessException(Throwable e) {
  156. // return BaseBusinessException.class.isInstance(e);
  157. // }
  158. //
  159. //
  160. // //------------------------------------------多业务日志记录-------------------------
  161. // /**
  162. // * @param @param e
  163. // * @param @param info 参数
  164. // * @return void 返回类型
  165. // * @throws
  166. // * @Title: warnLog
  167. // * @Description: 警告日志
  168. // * @author Orange
  169. // * @date 2019年1月26日
  170. // */
  171. // public static void warnLog(Throwable e, Object... info) {
  172. // //系统级别日志不打印
  173. // if (checkBaseBusinessException(e)) {
  174. // log(e, info);
  175. // } else {
  176. // Logger logger = LoggerFactory.getLogger("error_log");
  177. // logger.warn("[System Exception] exception={} ,info={}", throwable2String(e), info);
  178. // }
  179. // }
  180. //}