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,6 +16,7 @@ import com.kongzue.dialogx.DialogX
16 16
 import com.tencent.bugly.crashreport.CrashReport
17 17
 import com.xhly.corelib.Const
18 18
 import com.xhly.corelib.utils.LogShow
19
+import com.xhly.corelib.utils.LogUtils
19 20
 import com.xhly.corelib.utils.ModelNameUtils
20 21
 import com.xhly.corelib.utils.SharedPreferencesUtils
21 22
 import com.xhly.corelib.utils.SystemUtil
@@ -703,6 +704,7 @@ class ManageApplication : MultiDexApplication() {
703 704
         super.onCreate()
704 705
         val processName = SystemUtil.getProcessName(this, android.os.Process.myPid())
705 706
         if (processName != null && processName.equals(packageName)) {
707
+            LogUtils.DEBUG=com.xhkjedu.manageapp.BuildConfig.IS_DEBUG
706 708
             Const.setBaseUrl(com.xhkjedu.manageapp.BuildConfig.IS_DEBUG)
707 709
             CrashReport.initCrashReport(applicationContext, "37c72ff74c", false);
708 710
             instance = this

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

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

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

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

Loading…
Cancel
Save