Browse Source

1.将socket日志输出修改为LogUtils

20241218TB223FC(测试jar包)
wangwanlei 7 months ago
parent
commit
8a488372dd

+ 2
- 0
app/src/main/java/com/xhly/manageapp/ManageApplication.kt View File

16
 import com.tencent.bugly.crashreport.CrashReport
16
 import com.tencent.bugly.crashreport.CrashReport
17
 import com.xhly.corelib.Const
17
 import com.xhly.corelib.Const
18
 import com.xhly.corelib.utils.LogShow
18
 import com.xhly.corelib.utils.LogShow
19
+import com.xhly.corelib.utils.LogUtils
19
 import com.xhly.corelib.utils.ModelNameUtils
20
 import com.xhly.corelib.utils.ModelNameUtils
20
 import com.xhly.corelib.utils.SharedPreferencesUtils
21
 import com.xhly.corelib.utils.SharedPreferencesUtils
21
 import com.xhly.corelib.utils.SystemUtil
22
 import com.xhly.corelib.utils.SystemUtil
703
         super.onCreate()
704
         super.onCreate()
704
         val processName = SystemUtil.getProcessName(this, android.os.Process.myPid())
705
         val processName = SystemUtil.getProcessName(this, android.os.Process.myPid())
705
         if (processName != null && processName.equals(packageName)) {
706
         if (processName != null && processName.equals(packageName)) {
707
+            LogUtils.DEBUG=com.xhkjedu.manageapp.BuildConfig.IS_DEBUG
706
             Const.setBaseUrl(com.xhkjedu.manageapp.BuildConfig.IS_DEBUG)
708
             Const.setBaseUrl(com.xhkjedu.manageapp.BuildConfig.IS_DEBUG)
707
             CrashReport.initCrashReport(applicationContext, "37c72ff74c", false);
709
             CrashReport.initCrashReport(applicationContext, "37c72ff74c", false);
708
             instance = this
710
             instance = this

+ 13
- 1
corelib/src/main/java/com/xhly/corelib/utils/LogUtils.java View File

4
 
4
 
5
 public class LogUtils {
5
 public class LogUtils {
6
     public static String TAG = "LogUtils";
6
     public static String TAG = "LogUtils";
7
-    private static final boolean DEBUG = true;
7
+  /*  private static final boolean DEBUG = true;*/
8
+    public static  boolean DEBUG = true;
8
 
9
 
9
     private static final int D = 745;
10
     private static final int D = 745;
10
     private static final int E = 421;
11
     private static final int E = 421;
11
     private static final int V = 674;
12
     private static final int V = 674;
13
+
14
+    private static final int I = 679;
12
     private static final String CUT_OFF = "------------------------";
15
     private static final String CUT_OFF = "------------------------";
13
     private static final String CUT_OFF_END = "----------------------" +
16
     private static final String CUT_OFF_END = "----------------------" +
14
             "--------------------------------------------------------";
17
             "--------------------------------------------------------";
27
         printf(V, tag, values);
30
         printf(V, tag, values);
28
     }
31
     }
29
 
32
 
33
+    public static void i(String tag, String... values) {
34
+        printf(I, tag, values);
35
+    }
36
+
30
     private static void printf(int mark, String tag, String... values) {
37
     private static void printf(int mark, String tag, String... values) {
31
         if (!DEBUG) {
38
         if (!DEBUG) {
32
             return;
39
             return;
105
                 Log.v(tag, " ");
112
                 Log.v(tag, " ");
106
                 Log.v(tag, startLine);
113
                 Log.v(tag, startLine);
107
                 break;
114
                 break;
115
+
116
+            case I:
117
+                Log.i(tag, " ");
118
+                Log.i(tag, startLine);
119
+                break;
108
         }
120
         }
109
 
121
 
110
 
122
 

+ 12
- 11
websocket/src/main/java/com/xhly/websocket/service/LongConnService.java View File

15
 import com.neovisionaries.ws.client.WebSocketException;
15
 import com.neovisionaries.ws.client.WebSocketException;
16
 import com.neovisionaries.ws.client.WebSocketFactory;
16
 import com.neovisionaries.ws.client.WebSocketFactory;
17
 import com.neovisionaries.ws.client.WebSocketFrame;
17
 import com.neovisionaries.ws.client.WebSocketFrame;
18
+import com.xhly.corelib.utils.LogUtils;
18
 import com.xhly.corelib.utils.NetworkUtils;
19
 import com.xhly.corelib.utils.NetworkUtils;
19
 
20
 
20
 import java.io.IOException;
21
 import java.io.IOException;
99
     @Override
100
     @Override
100
     public void onCreate() {
101
     public void onCreate() {
101
         super.onCreate();
102
         super.onCreate();
102
-        Log.i(TAG, "onCreate()............");
103
+        LogUtils.i(TAG, "onCreate()............");
103
         mListener = new WsListener();
104
         mListener = new WsListener();
104
     }
105
     }
105
 
106
 
106
     @Override
107
     @Override
107
     public int onStartCommand(Intent intent, int flags, int startId) {
108
     public int onStartCommand(Intent intent, int flags, int startId) {
108
-        Log.i(TAG, "onStartCommand()............");
109
+        LogUtils.i(TAG, "onStartCommand()............");
109
         closeWebsocket = false;
110
         closeWebsocket = false;
110
         if (mListener == null) {
111
         if (mListener == null) {
111
             mListener = new WsListener();
112
             mListener = new WsListener();
116
 
117
 
117
     @Override
118
     @Override
118
     public void onDestroy() {
119
     public void onDestroy() {
119
-        Log.i(TAG, "onDestroy()............");
120
+        LogUtils.i(TAG, "onDestroy()............");
120
         if (heartSubscription != null) {
121
         if (heartSubscription != null) {
121
             heartSubscription.dispose();
122
             heartSubscription.dispose();
122
         }
123
         }
194
                 webSocket = null;
195
                 webSocket = null;
195
             }
196
             }
196
             try {
197
             try {
197
-                Log.i(TAG, "第一次连接: " + connectUrl);
198
+                LogUtils.i(TAG, "第一次连接: " + connectUrl);
198
                 // 异步连接
199
                 // 异步连接
199
                 webSocket = createWebSocket();
200
                 webSocket = createWebSocket();
200
                 setStatus(WsStatus.CONNECTING);
201
                 setStatus(WsStatus.CONNECTING);
214
     }
215
     }
215
 
216
 
216
     private WebSocket createWebSocket() throws IOException {
217
     private WebSocket createWebSocket() throws IOException {
217
-        Log.i(TAG, "创建连接:createWebSocket()");
218
+        LogUtils.i(TAG, "创建连接:createWebSocket()");
218
         return new WebSocketFactory().createSocket(connectUrl, CONNECT_TIMEOUT)
219
         return new WebSocketFactory().createSocket(connectUrl, CONNECT_TIMEOUT)
219
                 //设置帧队列最大值为5
220
                 //设置帧队列最大值为5
220
                 .setFrameQueueSize(FRAME_QUEUE_SIZE)
221
                 .setFrameQueueSize(FRAME_QUEUE_SIZE)
232
             reconnectCount = 0;
233
             reconnectCount = 0;
233
             isReConnect = false;
234
             isReConnect = false;
234
             closeWebsocket = true;
235
             closeWebsocket = true;
235
-            Log.i(TAG, "重连失败网络不可用,当前closeWebsocket==" + closeWebsocket);
236
+            LogUtils.i(TAG, "重连失败网络不可用,当前closeWebsocket==" + closeWebsocket);
236
             return;
237
             return;
237
         }
238
         }
238
         if (HAS_HEART_RECEIVE) {
239
         if (HAS_HEART_RECEIVE) {
314
         @Override
315
         @Override
315
         public void onConnected(final WebSocket websocket, Map<String, List<String>> headers) throws Exception {
316
         public void onConnected(final WebSocket websocket, Map<String, List<String>> headers) throws Exception {
316
             super.onConnected(websocket, headers);
317
             super.onConnected(websocket, headers);
317
-            Log.i(TAG, "连接成功:" + headers.toString());
318
+            LogUtils.i(TAG, "连接成功:" + headers.toString());
318
             connected = true;
319
             connected = true;
319
             setStatus(WsStatus.CONNECT_SUCCESS);
320
             setStatus(WsStatus.CONNECT_SUCCESS);
320
             cancelReconnect();// 连接成功的时候取消重连,初始化连接次数
321
             cancelReconnect();// 连接成功的时候取消重连,初始化连接次数
325
                 Observable.interval(HEART_INTERVAL, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Long>() {
326
                 Observable.interval(HEART_INTERVAL, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Long>() {
326
                     @Override
327
                     @Override
327
                     public void onSubscribe(Disposable d) {
328
                     public void onSubscribe(Disposable d) {
328
-                        Log.d(TAG, "订阅开始");
329
+                        LogUtils.d(TAG,"订阅开始");
329
                         heartSubscription = d;
330
                         heartSubscription = d;
330
                     }
331
                     }
331
 
332
 
332
                     @Override
333
                     @Override
333
                     public void onNext(Long aLong) {
334
                     public void onNext(Long aLong) {
334
-                        Log.v(TAG, "发送心跳");
335
+                        LogUtils.d(TAG,"发送心跳");
335
                         startHeartInterval(websocket);
336
                         startHeartInterval(websocket);
336
                     }
337
                     }
337
 
338
 
352
         public void onConnectError(WebSocket websocket, WebSocketException exception) throws Exception {
353
         public void onConnectError(WebSocket websocket, WebSocketException exception) throws Exception {
353
             super.onConnectError(websocket, exception);
354
             super.onConnectError(websocket, exception);
354
             exception.printStackTrace();
355
             exception.printStackTrace();
355
-            Log.i(TAG, "连接错误: " + exception.getMessage());
356
+            LogUtils.i(TAG, "连接错误: " + exception.getMessage());
356
             HAS_HEART_RECEIVE = false;
357
             HAS_HEART_RECEIVE = false;
357
             setStatus(WsStatus.CONNECT_FAIL);
358
             setStatus(WsStatus.CONNECT_FAIL);
358
             connected = false;
359
             connected = false;
364
         @Override
365
         @Override
365
         public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
366
         public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
366
             super.onDisconnected(websocket, serverCloseFrame, clientCloseFrame, closedByServer);
367
             super.onDisconnected(websocket, serverCloseFrame, clientCloseFrame, closedByServer);
367
-            Log.i(TAG, "断开连接,是否重连" + isReConnect + ",当前closeWebsocket==" + closeWebsocket);
368
+            LogUtils.i(TAG, "断开连接,是否重连" + isReConnect + ",当前closeWebsocket==" + closeWebsocket);
368
             HAS_HEART_RECEIVE = false;
369
             HAS_HEART_RECEIVE = false;
369
             connected = false;
370
             connected = false;
370
             if (heartSubscription != null) {
371
             if (heartSubscription != null) {

+ 11
- 10
websocket/src/main/java/com/xhly/websocket/service/SocketClient.java View File

11
 import com.neovisionaries.ws.client.WebSocketException;
11
 import com.neovisionaries.ws.client.WebSocketException;
12
 import com.neovisionaries.ws.client.WebSocketFactory;
12
 import com.neovisionaries.ws.client.WebSocketFactory;
13
 import com.neovisionaries.ws.client.WebSocketFrame;
13
 import com.neovisionaries.ws.client.WebSocketFrame;
14
+import com.xhly.corelib.utils.LogUtils;
14
 import com.xhly.corelib.utils.NetworkUtils;
15
 import com.xhly.corelib.utils.NetworkUtils;
15
 
16
 
16
 import org.w3c.dom.Text;
17
 import org.w3c.dom.Text;
98
 
99
 
99
     public void startSocket(Context context) {
100
     public void startSocket(Context context) {
100
         this.context=context;
101
         this.context=context;
101
-        Log.i(TAG, "startSocket............");
102
+        LogUtils.i(TAG, "startSocket............");
102
         closeWebsocket = false;
103
         closeWebsocket = false;
103
         if (mListener == null) {
104
         if (mListener == null) {
104
             mListener = new WsListener();
105
             mListener = new WsListener();
108
 
109
 
109
 
110
 
110
     public void onDestroy() {
111
     public void onDestroy() {
111
-        Log.i(TAG, "onDestroy()............");
112
+        LogUtils.i(TAG, "onDestroy()............");
112
         if (heartSubscription != null) {
113
         if (heartSubscription != null) {
113
             heartSubscription.dispose();
114
             heartSubscription.dispose();
114
         }
115
         }
177
                 webSocket = null;
178
                 webSocket = null;
178
             }
179
             }
179
             try {
180
             try {
180
-                Log.i(TAG, "第一次连接: " + connectUrl);
181
+                LogUtils.i(TAG, "第一次连接: " + connectUrl);
181
                 // 异步连接
182
                 // 异步连接
182
                 webSocket = createWebSocket();
183
                 webSocket = createWebSocket();
183
                 setStatus(WsStatus.CONNECTING);
184
                 setStatus(WsStatus.CONNECTING);
197
     }
198
     }
198
 
199
 
199
     private WebSocket createWebSocket() throws IOException {
200
     private WebSocket createWebSocket() throws IOException {
200
-        Log.i(TAG, "创建连接:createWebSocket()");
201
+        LogUtils.i(TAG, "创建连接:createWebSocket()");
201
         return new WebSocketFactory().createSocket(connectUrl, CONNECT_TIMEOUT)
202
         return new WebSocketFactory().createSocket(connectUrl, CONNECT_TIMEOUT)
202
                 //设置帧队列最大值为5
203
                 //设置帧队列最大值为5
203
                 .setFrameQueueSize(FRAME_QUEUE_SIZE)
204
                 .setFrameQueueSize(FRAME_QUEUE_SIZE)
215
             reconnectCount = 0;
216
             reconnectCount = 0;
216
             isReConnect = false;
217
             isReConnect = false;
217
             closeWebsocket = true;
218
             closeWebsocket = true;
218
-            Log.i(TAG, "重连失败网络不可用,当前closeWebsocket==" + closeWebsocket);
219
+            LogUtils.i(TAG, "重连失败网络不可用,当前closeWebsocket==" + closeWebsocket);
219
             return;
220
             return;
220
         }
221
         }
221
         if (HAS_HEART_RECEIVE) {
222
         if (HAS_HEART_RECEIVE) {
297
         @Override
298
         @Override
298
         public void onConnected(final WebSocket websocket, Map<String, List<String>> headers) throws Exception {
299
         public void onConnected(final WebSocket websocket, Map<String, List<String>> headers) throws Exception {
299
             super.onConnected(websocket, headers);
300
             super.onConnected(websocket, headers);
300
-            Log.i(TAG, "连接成功:" + headers.toString());
301
+            LogUtils.i(TAG, "连接成功:" + headers.toString());
301
             connected = true;
302
             connected = true;
302
             setStatus(WsStatus.CONNECT_SUCCESS);
303
             setStatus(WsStatus.CONNECT_SUCCESS);
303
             cancelReconnect();// 连接成功的时候取消重连,初始化连接次数
304
             cancelReconnect();// 连接成功的时候取消重连,初始化连接次数
308
                 Observable.interval(HEART_INTERVAL, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Long>() {
309
                 Observable.interval(HEART_INTERVAL, TimeUnit.SECONDS).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Long>() {
309
                     @Override
310
                     @Override
310
                     public void onSubscribe(Disposable d) {
311
                     public void onSubscribe(Disposable d) {
311
-                        Log.d(TAG, "订阅开始");
312
+                        LogUtils.d(TAG, "订阅开始");
312
                         heartSubscription = d;
313
                         heartSubscription = d;
313
                     }
314
                     }
314
 
315
 
315
                     @Override
316
                     @Override
316
                     public void onNext(Long aLong) {
317
                     public void onNext(Long aLong) {
317
-                        Log.v(TAG, "发送心跳");
318
+                        LogUtils.d(TAG, "发送心跳");
318
                         startHeartInterval(websocket);
319
                         startHeartInterval(websocket);
319
                     }
320
                     }
320
 
321
 
335
         public void onConnectError(WebSocket websocket, WebSocketException exception) throws Exception {
336
         public void onConnectError(WebSocket websocket, WebSocketException exception) throws Exception {
336
             super.onConnectError(websocket, exception);
337
             super.onConnectError(websocket, exception);
337
             exception.printStackTrace();
338
             exception.printStackTrace();
338
-            Log.i(TAG, "连接错误: " + exception.getMessage());
339
+            LogUtils.i(TAG, "连接错误: " + exception.getMessage());
339
             HAS_HEART_RECEIVE = false;
340
             HAS_HEART_RECEIVE = false;
340
             setStatus(WsStatus.CONNECT_FAIL);
341
             setStatus(WsStatus.CONNECT_FAIL);
341
             connected = false;
342
             connected = false;
347
         @Override
348
         @Override
348
         public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
349
         public void onDisconnected(WebSocket websocket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) throws Exception {
349
             super.onDisconnected(websocket, serverCloseFrame, clientCloseFrame, closedByServer);
350
             super.onDisconnected(websocket, serverCloseFrame, clientCloseFrame, closedByServer);
350
-            Log.i(TAG, "断开连接,是否重连" + isReConnect + ",当前closeWebsocket==" + closeWebsocket);
351
+            LogUtils.i(TAG, "断开连接,是否重连" + isReConnect + ",当前closeWebsocket==" + closeWebsocket);
351
             HAS_HEART_RECEIVE = false;
352
             HAS_HEART_RECEIVE = false;
352
             connected = false;
353
             connected = false;
353
             if (heartSubscription != null) {
354
             if (heartSubscription != null) {

Loading…
Cancel
Save