| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | |
| | | import android.util.LruCache; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.utils.TimeUtils; |
| | |
| | | |
| | | //默认打印标题 |
| | | private static String logTitle = "自定义输出打印信息"; |
| | | |
| | | private static Gson gson = new Gson(); |
| | | |
| | | /** |
| | | * java打印 |
| | |
| | | * @param isAddToMemory 是否加入内存(本地日志用到) |
| | | */ |
| | | private static void printBase(String msg, String code, boolean isAddToMemory) { |
| | | CustomLogObject customLogObject = new CustomLogObject(); |
| | | customLogObject.msgOrData = msg; |
| | | customLogObject.code = code; |
| | | String json = logTitle + (UserConfigManage.getInstance().isBAccount() ? "(B端):" : "(C端):"); |
| | | json += customLogObject.getJointMessage(); |
| | | if (isPrintLogcat) { |
| | | System.out.println(json); |
| | | } |
| | | if (isAddToMemory) { |
| | | writeLog(customLogObject.getJointMessage()); |
| | | try { |
| | | CustomLogObject customLogObject = new CustomLogObject(); |
| | | customLogObject.setMsgOrData(msg); |
| | | customLogObject.setCode(code); |
| | | String json = logTitle + (UserConfigManage.getInstance().isBAccount() ? "(B端)==" : "(C端)==") + gson.toJson(customLogObject); |
| | | if (isPrintLogcat) { |
| | | System.out.println(json); |
| | | } |
| | | if (isAddToMemory) { |
| | | writeLog(json); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | |
| | |
| | | * 自定义日志类 |
| | | */ |
| | | static class CustomLogObject { |
| | | |
| | | //信息描述 |
| | | public String msgOrData = ""; |
| | | private String msgOrData; |
| | | |
| | | //状态码 |
| | | public String code = "0"; |
| | | private String code; |
| | | |
| | | public String getJointMessage() { |
| | | |
| | | if ("0".equals(code)) { |
| | | return msgOrData; |
| | | } |
| | | return msgOrData + "(" + code + ")"; |
| | | |
| | | public String getMsgOrData() { |
| | | return msgOrData == null ? "" : msgOrData; |
| | | } |
| | | |
| | | public void setMsgOrData(String msgOrData) { |
| | | this.msgOrData = msgOrData; |
| | | } |
| | | |
| | | public String getCode() { |
| | | return code == null ? "0" : code; |
| | | } |
| | | |
| | | public void setCode(String code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |