Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove stacktrace print and reduce logging severity level #4

Merged
merged 2 commits into from
Jun 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/main/java/net/wimpi/modbus/io/ModbusRTUTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ public ModbusResponse readResponse() throws ModbusIOException {
return response;
} catch (Exception ex) {
final String errMsg = "failed to read";
logger.error("Last request: {}", ModbusUtil.toHex(lastRequest));
logger.error("{}: {}", errMsg, ex.getMessage());
logger.debug("Last request: {}", ModbusUtil.toHex(lastRequest));
logger.debug("{}: {}", errMsg, ex.getMessage());
throw new ModbusIOException(
String.format("I/O exception: %s %s", ex.getClass().getSimpleName(), ex.getMessage()));
} finally {
Expand Down Expand Up @@ -228,7 +228,7 @@ private void getResponse(int fn, BytesOutputStream out) throws IOException {
out.write(inpBuf, 0, inpBytes);
m_CommPort.disableReceiveThreshold();
if (inpBytes != bc + 2) {
logger.error("awaited {} bytes, but received {}", (bc + 2), inpBytes);
logger.debug("awaited {} bytes, but received {}", (bc + 2), inpBytes);
}
break;
case 0x05:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ public void execute() throws ModbusIOException, ModbusSlaveException, ModbusExce
try {
Thread.sleep(m_TransDelayMS);
} catch (InterruptedException ex) {
logger.error("InterruptedException: {}", ex.getMessage());
logger.debug("InterruptedException: {}", ex.getMessage());
throw;
}
}

Expand All @@ -195,12 +196,12 @@ public void execute() throws ModbusIOException, ModbusSlaveException, ModbusExce
break;
} catch (ModbusIOException e) {
tries++;
logger.error(
logger.debug(
"execute try {}/{} error: {}. Request: {} (unit id {} & transaction {}). Serial parameters: {}",
tries, m_Retries + 1, e.getMessage(), m_Request, m_Request.getUnitID(),
m_Request.getTransactionID(), m_SerialCon.getParameters());
if (tries >= m_Retries) {
logger.error(
logger.debug(
"execute reached max tries {}, throwing last error: {}. Request: {} (unit id {} & transaction {}). Serial parameters: {}",
m_Retries + 1, e.getMessage(), m_Request, m_Request.getUnitID(),
m_Request.getTransactionID(), m_SerialCon.getParameters());
Expand All @@ -210,7 +211,7 @@ public void execute() throws ModbusIOException, ModbusSlaveException, ModbusExce
}
} while (true);
if (tries > 0) {
logger.info(
logger.debug(
"execute eventually succeeded with {} re-tries. Request: {} (unit id {} & transaction id {}). Serial parameters: {}",
tries, m_Request, m_Request.getUnitID(), m_Request.getTransactionID(),
m_SerialCon.getParameters());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/wimpi/modbus/io/ModbusSerialTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void setReceiveThreshold(int th) {
try {
m_CommPort.enableReceiveThreshold(th); /* chars */
} catch (UnsupportedCommOperationException e) {
logger.error("Failed to setReceiveThreshold: {}", e.getMessage());
logger.warn("Failed to setReceiveThreshold: {}", e.getMessage());
}
}

Expand All @@ -154,7 +154,7 @@ public void setReceiveTimeout(int ms) {
try {
m_CommPort.enableReceiveTimeout(ms); /* milliseconds */
} catch (UnsupportedCommOperationException e) {
logger.error("Failed to setReceiveTimeout: {}", e.getMessage());
logger.warn("Failed to setReceiveTimeout: {}", e.getMessage());
}
}

Expand All @@ -177,7 +177,7 @@ public void readEcho(int len) throws IOException {
m_CommPort.disableReceiveThreshold();
if (echoLen != len) {
final String errMsg = "Echo not received";
logger.error("Transmit {}", errMsg);
logger.debug("Transmit {}", errMsg);
throw new IOException(errMsg);
}
}// readEcho
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/wimpi/modbus/io/ModbusTCPTransaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@ public void execute() throws ModbusIOException, ModbusSlaveException, ModbusExce
break;
} catch (ModbusIOException ex) {
tries++;
logger.error(
logger.debug(
"execute try {}/{} error: {}. Request: {} (unit id {} & transaction {}). Address: {}:{}",
tries, m_Retries + 1, ex.getMessage(), m_Request, m_Request.getUnitID(),
m_Request.getTransactionID(), m_Connection.getAddress(), m_Connection.getPort());
if (tries >= m_Retries) {
logger.error(
logger.debug(
"execute reached max tries {}, throwing last error: {}. Request: {} (unit id {} & transaction {}). Address: {}:{}",
m_Retries + 1, ex.getMessage(), m_Request, m_Request.getUnitID(),
m_Request.getTransactionID(), m_Connection.getAddress(), m_Connection.getPort());
Expand All @@ -225,7 +225,7 @@ public void execute() throws ModbusIOException, ModbusSlaveException, ModbusExce
} while (true);

if (tries > 0) {
logger.info(
logger.debug(
"execute eventually succeeded with {} re-tries. Request: {} (unit id {} & transaction {}). Address: {}:{}",
tries, m_Request, m_Request.getUnitID(), m_Request.getTransactionID(),
m_Connection.getAddress(), m_Connection.getPort());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/wimpi/modbus/io/ModbusTCPTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public ModbusRequest readRequest() throws ModbusIOException {
// connection reset by peer, also EOF
throw new ModbusIOException(true);
} catch (Exception ex) {
ex.printStackTrace();
// ex.printStackTrace();
throw new ModbusIOException("I/O exception - failed to read.");
}
}// readRequest
Expand Down Expand Up @@ -223,7 +223,7 @@ public ModbusResponse readResponse() throws ModbusIOException {
* return response;
*/
} catch (Exception ex) {
ex.printStackTrace();
// ex.printStackTrace();
throw new ModbusIOException(
String.format("I/O exception: %s %s", ex.getClass().getSimpleName(), ex.getMessage()));
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/wimpi/modbus/io/ModbusUDPTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ModbusResponse readResponse() throws ModbusIOException {
} catch (InterruptedIOException ioex) {
throw new ModbusIOException("Socket timed out.");
} catch (Exception ex) {
ex.printStackTrace();
// ex.printStackTrace();
throw new ModbusIOException("I/O exception - failed to read.");
}
}// readResponse
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/net/wimpi/modbus/net/SerialConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void open() throws Exception {
m_PortIdentifyer = CommPortIdentifier.getPortIdentifier(m_Parameters.getPortName());
} catch (NoSuchPortException e) {
final String errMsg = "Could not get port identifier, maybe insufficient permissions. " + e.getMessage();
logger.error("Could not get port identifier, maybe insufficient permissions. {}: {}",
logger.debug("Could not get port identifier, maybe insufficient permissions. {}: {}",
e.getClass().getName(), e.getMessage());
throw new Exception(errMsg);
}
Expand All @@ -133,7 +133,7 @@ public void open() throws Exception {
m_SerialPort = m_PortIdentifyer.open("Modbus Serial Master", 30000);
} catch (PortInUseException e) {
String msg = "open port failed: " + e.getMessage();
logger.error("open port failed: {}: {}", e.getClass().getName(), e.getMessage());
logger.debug("open port failed: {}: {}", e.getClass().getName(), e.getMessage());
throw new Exception(msg);
}
logger.trace("Got Serial Port");
Expand All @@ -144,7 +144,7 @@ public void open() throws Exception {
} catch (Exception e) {
// ensure it is closed
m_SerialPort.close();
logger.error("parameter setup failed. {}: {}", e.getClass().getName(), e.getMessage());
logger.debug("parameter setup failed. {}: {}", e.getClass().getName(), e.getMessage());
throw e;
}

Expand All @@ -169,7 +169,7 @@ public void open() throws Exception {
} catch (IOException e) {
m_SerialPort.close();
String msg = "Error opening i/o streams: " + e.getMessage();
logger.error("Error opening i/o streams. {}: {}", e.getClass().getName(), e.getMessage());
logger.debug("Error opening i/o streams. {}: {}", e.getClass().getName(), e.getMessage());
throw new Exception(msg);
}
logger.trace("i/o Streams prepared");
Expand All @@ -180,7 +180,7 @@ public void open() throws Exception {
} catch (TooManyListenersException e) {
m_SerialPort.close();
final String errMsg = "too many listeners added:" + e.getMessage();
logger.error("too many listeners added. {}: {}", e.getClass().getName(), e.getMessage());
logger.debug("too many listeners added. {}: {}", e.getClass().getName(), e.getMessage());
throw new Exception(errMsg);
}

Expand All @@ -196,7 +196,7 @@ public void setReceiveTimeout(int ms) {
try {
m_SerialPort.enableReceiveTimeout(ms);
} catch (UnsupportedCommOperationException e) {
logger.error("Failed to set receive timeout: {}", e.getMessage());
logger.warn("Failed to set receive timeout: {}", e.getMessage());
}
}// setReceiveTimeout

Expand Down Expand Up @@ -261,13 +261,13 @@ public void close() {
try {
m_Transport.close();
} catch (IOException e) {
logger.error("Error occurred when closing transport. {}: {}", e.getClass().getName(), e.getMessage());
logger.warn("Error occurred when closing transport. {}: {}", e.getClass().getName(), e.getMessage());
}

try {
m_SerialIn.close();
} catch (IOException e) {
logger.error("Error occurred when closing serial input stream. {}: {}", e.getClass().getName(),
logger.warn("Error occurred when closing serial input stream. {}: {}", e.getClass().getName(),
e.getMessage());
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/net/wimpi/modbus/net/TCPMasterConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void close() {
try {
m_ModbusTransport.close();
} catch (IOException ex) {
logger.debug("close()");
logger.warn("close()", ex);
}
m_Connected = false;
}
Expand Down Expand Up @@ -157,7 +157,7 @@ public void setTimeout(int timeout) {
try {
m_Socket.setSoTimeout(m_Timeout);
} catch (IOException ex) {
logger.error("Could not set socket timeout on connection {} {}: {}", getAddress(), getPort(),
logger.warn("Could not set socket timeout on connection {} {}: {}", getAddress(), getPort(),
ex.getMessage());
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/wimpi/modbus/net/TCPSlaveConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public TCPSlaveConnection(Socket socket, ModbusSocketBasedTransportFactory trans
setSocket(socket);
} catch (IOException ex) {
final String errMsg = "Socket invalid";
logger.debug(errMsg);
logger.warn(errMsg);
// @commentstart@
throw new IllegalStateException(errMsg);
// @commentend@
Expand Down