log replace

This commit is contained in:
zhongchao
2023-02-20 20:39:13 +08:00
parent 1792a09d7a
commit b71d00aa66
4 changed files with 39 additions and 38 deletions

View File

@@ -6,8 +6,8 @@ import static com.mogo.telematic.MogoLengthFrameDecoder.MAX_FRAME_LENGTH;
import static com.mogo.telematic.MogoProtocolMsg.IDENTITY_REGIST;
import android.text.TextUtils;
import android.util.Log;
import com.elegant.log.simplelog.Logger;
import com.mogo.telematic.MogoLengthFrameDecoder;
import com.mogo.telematic.MogoMessageEncoder;
import com.mogo.telematic.MogoProtocolMsg;
@@ -122,7 +122,7 @@ public class NettyTcpClient {
public void connect() {
if (isConnecting) {
Log.d(TAG, "正在连接中connect return");
Logger.d(TAG, "正在连接中connect return");
return;
}
Thread clientThread = new Thread("client-Netty") {
@@ -160,12 +160,12 @@ public class NettyTcpClient {
}
});
} catch (Exception e) {
Log.w(TAG, "初始化出错的原因为:" + e.getMessage());
Logger.w(TAG, "初始化出错的原因为:" + e.getMessage());
}
}
private void connectServer() {
Log.d(TAG, "connectServer fun is called.");
Logger.d(TAG, "connectServer fun is called.");
synchronized (NettyTcpClient.this) {
if (!isConnected) {
isConnecting = true;
@@ -175,18 +175,18 @@ public class NettyTcpClient {
initBootstrap();
doConnect();
} else {
Log.w(TAG, "socket正在连接中无需重连");
Logger.w(TAG, "socket正在连接中无需重连");
}
}
}
private void doConnect() {
if (channel != null && channel.isOpen() && channel.isActive()) {
Log.w(TAG, "Channel is active, no need to call start.");
Logger.w(TAG, "Channel is active, no need to call start.");
return;
}
if (!canReconnect) {
Log.d(TAG, "重连已被关闭则直接return.");
Logger.d(TAG, "重连已被关闭则直接return.");
return;
}
ChannelFuture channelFuture;
@@ -206,12 +206,12 @@ public class NettyTcpClient {
// future.channel().eventLoop().shutdownGracefully();
// }
channel = null;
Log.e(TAG, "连接已经结束!");
Logger.e(TAG, "连接已经结束!");
});
Log.d(TAG, "连接获取channel已完成");
Logger.d(TAG, "连接获取channel已完成");
}
} catch (Exception e) {
Log.e(TAG, "连接Server ip:" + host + ",port:" + tcp_port + ",失败信息:" + e.getMessage());
Logger.e(TAG, "连接Server ip:" + host + ",port:" + tcp_port + ",失败信息:" + e.getMessage());
isConnected = false;
}
}
@@ -239,7 +239,7 @@ public class NettyTcpClient {
byte[] signByteArr = mSign.getBytes();
MogoProtocolMsg msg = new MogoProtocolMsg(IDENTITY_REGIST, signByteArr.length, signByteArr);
sendMsgToServer(msg, isSuccess -> {
Log.d(TAG, "身份注册成功:" + isSuccess);
Logger.d(TAG, "身份注册成功:" + isSuccess);
});
}
}
@@ -248,21 +248,21 @@ public class NettyTcpClient {
private ChannelFutureListener mFutureListener = channelFuture -> {
if (channelFuture.isDone()) {
if (channelFuture.isSuccess()) {
Log.d(TAG, "连接成功");
Logger.d(TAG, "连接成功");
reconnectNum = MAX_CONNECT_TIMES;
isConnected = true;
} else {
if (channelFuture.isCancelled()) {
Log.w(TAG, "Connection attempt cancelled by user.");
Logger.w(TAG, "Connection attempt cancelled by user.");
} else {
Log.e(TAG, "连接失败原因为:" + channelFuture.cause().getMessage());
Logger.e(TAG, "连接失败原因为:" + channelFuture.cause().getMessage());
}
isConnected = false;
channelFuture.channel().pipeline().fireChannelInactive();
}
isConnecting = false;
} else {
Log.w(TAG, "Connection isn't done.");
Logger.w(TAG, "Connection isn't done.");
isConnected = false;
}
synchronized (NettyTcpClient.this) {
@@ -271,7 +271,7 @@ public class NettyTcpClient {
};
public void disconnect() {
Log.e(TAG, "disconnect");
Logger.e(TAG, "disconnect");
isNeedReconnect = false;
group.shutdownGracefully();
group = null;

View File

@@ -1,8 +1,8 @@
package com.mogo.telematic.discovery;
import android.os.AsyncTask;
import android.util.Log;
import com.elegant.log.simplelog.Logger;
import com.mogo.telematic.discovery.bean.HostBean;
import com.mogo.telematic.discovery.bean.NetInfo;
@@ -38,7 +38,7 @@ public abstract class AbstractDiscoveryTask extends AsyncTask<Void, HostBean, Vo
this.ip = ip;
this.start = start;
this.end = end;
Log.d(TAG, "setNetwork: ip=" + NetInfo.getIpFromLongUnsigned(ip)
Logger.d(TAG, "setNetwork: ip=" + NetInfo.getIpFromLongUnsigned(ip)
+ ", start=" + NetInfo.getIpFromLongUnsigned(start)
+ ", end=" + NetInfo.getIpFromLongUnsigned(end)
);
@@ -49,7 +49,7 @@ public abstract class AbstractDiscoveryTask extends AsyncTask<Void, HostBean, Vo
@Override
protected void onProgressUpdate(HostBean... host) {
Log.d(TAG, "onProgressUpdate: isCancelled=" + isCancelled());
Logger.d(TAG, "onProgressUpdate: isCancelled=" + isCancelled());
if (hostList != null) {
if (!isCancelled()) {
if (host[0] != null) {
@@ -61,7 +61,7 @@ public abstract class AbstractDiscoveryTask extends AsyncTask<Void, HostBean, Vo
@Override
protected void onPostExecute(Void unused) {
Log.d(TAG, "onPostExecute: 完成扫描hostList=" + hostList);
Logger.d(TAG, "onPostExecute: 完成扫描hostList=" + hostList);
if (mDiscoveryDriverListenerList != null) {
for (DiscoveryDriverListener discoveryDriverListener : mDiscoveryDriverListenerList) {
discoveryDriverListener.onSuccess(hostList);
@@ -71,7 +71,7 @@ public abstract class AbstractDiscoveryTask extends AsyncTask<Void, HostBean, Vo
@Override
protected void onCancelled() {
Log.d(TAG, "onCancelled: 取消扫描");
Logger.d(TAG, "onCancelled: 取消扫描");
if (mDiscoveryDriverListenerList != null) {
for (DiscoveryDriverListener discoveryDriverListener : mDiscoveryDriverListenerList) {
discoveryDriverListener.onCancel();

View File

@@ -1,7 +1,7 @@
package com.mogo.telematic.discovery;
import android.util.Log;
import com.elegant.log.simplelog.Logger;
import com.mogo.telematic.discovery.bean.HostBean;
import com.mogo.telematic.discovery.bean.NetInfo;
@@ -36,10 +36,10 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
@Override
protected Void doInBackground(Void... params) {
Log.v(TAG, "start=" + NetInfo.getIpFromLongUnsigned(start) + " (" + start + "), end=" + NetInfo.getIpFromLongUnsigned(end) + " (" + end + "), length=" + size);
Logger.v(TAG, "start=" + NetInfo.getIpFromLongUnsigned(start) + " (" + start + "), end=" + NetInfo.getIpFromLongUnsigned(end) + " (" + end + "), length=" + size);
mPool = Executors.newFixedThreadPool(THREADS);
if (ip <= end && ip >= start) {
Log.i(TAG, "Back and forth scanning");
Logger.i(TAG, "Back and forth scanning");
// gateway
launch(start);
@@ -52,7 +52,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
if (isCancelled()) {
break;
}
Log.d(TAG, "doInBackground: "
Logger.d(TAG, "doInBackground: "
+ " ip=" + NetInfo.getIpFromLongUnsigned(ip)
+ " start=" + NetInfo.getIpFromLongUnsigned(start)
+ " end=" + NetInfo.getIpFromLongUnsigned(end)
@@ -78,7 +78,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
}
}
} else {
Log.i(TAG, "Sequencial scanning");
Logger.i(TAG, "Sequencial scanning");
for (long i = start; i <= end; i++) {
if (isCancelled()) {
break;
@@ -90,9 +90,9 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
try {
if (!mPool.awaitTermination(TIMEOUT_SCAN, TimeUnit.SECONDS)) {
mPool.shutdownNow();
Log.e(TAG, "Shutting down pool");
Logger.e(TAG, "Shutting down pool");
if (!mPool.awaitTermination(TIMEOUT_SHUTDOWN, TimeUnit.SECONDS)) {
Log.e(TAG, "Pool did not terminate");
Logger.e(TAG, "Pool did not terminate");
}
}
} catch (InterruptedException e) {
@@ -100,7 +100,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
mPool.shutdownNow();
Thread.currentThread().interrupt();
}
Log.d(TAG, "doInBackground: return null");
Logger.d(TAG, "doInBackground: return null");
return null;
}
@@ -109,7 +109,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
if (mPool != null) {
synchronized (mPool) {
mPool.shutdownNow();
Log.d(TAG, "onCancelled: 停止线程");
Logger.d(TAG, "onCancelled: 停止线程");
}
}
super.onCancelled();
@@ -117,7 +117,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
private void launch(long i) {
if (!mPool.isShutdown()) {
Log.d(TAG, "launch: 子线程:" + NetInfo.getIpFromLongUnsigned(i));
Logger.d(TAG, "launch: 子线程:" + NetInfo.getIpFromLongUnsigned(i));
mPool.execute(new CheckRunnable(NetInfo.getIpFromLongUnsigned(i)));
}
}
@@ -139,7 +139,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
publish(null);
return;
}
Log.e(TAG, "run=" + addr + " isCancelled()=" + isCancelled());
Logger.e(TAG, "run=" + addr + " isCancelled()=" + isCancelled());
// Create host object
final HostBean host = new HostBean();
host.responseTime = TIMEOUT_CONNECT;
@@ -149,7 +149,7 @@ public class DiscoveryDriverTask extends AbstractDiscoveryTask {
try {
s.bind(null);
s.connect(new InetSocketAddress(addr, dport), TIMEOUT_CONNECT);
Log.i(TAG, "found using TCP connect " + addr + " on port=" + dport);
Logger.i(TAG, "found using TCP connect " + addr + " on port=" + dport);
publish(host);
} catch (IOException | IllegalArgumentException e) {
e.printStackTrace();

View File

@@ -7,7 +7,8 @@ import android.net.wifi.SupplicantState;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.telephony.TelephonyManager;
import android.util.Log;
import com.elegant.log.simplelog.Logger;
import java.io.BufferedReader;
import java.io.File;
@@ -56,7 +57,7 @@ public class NetInfo {
InetAddress ia = nis.nextElement();
if (!ia.isLoopbackAddress()) {
if (ia instanceof Inet6Address) {
Log.i(TAG, "IPv6 detected and not supported yet!");
Logger.i(TAG, "IPv6 detected and not supported yet!");
continue;
}
return ia.getHostAddress();
@@ -83,10 +84,10 @@ public class NetInfo {
cidr = IpToCidr(match);
return;
} else {
Log.i(TAG, "cannot find cidr, using default /24");
Logger.i(TAG, "cannot find cidr, using default /24");
}
} catch (NumberFormatException e) {
Log.i(TAG, e.getMessage() + " -> cannot find cidr, using default /24");
Logger.i(TAG, e.getMessage() + " -> cannot find cidr, using default /24");
}
}
}
@@ -107,7 +108,7 @@ public class NetInfo {
}
}
} catch (Exception e) {
Log.e(TAG, "Can't use native command: " + e.getMessage());
Logger.e(TAG, "Can't use native command: " + e.getMessage());
return null;
}
return null;