Commit 9218093b authored by Andre Freyssinet's avatar Andre Freyssinet

Logging enhancements, avoid stacktrace in WARN level.

parent 6e58c8af
......@@ -109,8 +109,8 @@ public class RESTAcquisition implements AcquisitionHandler {
try {
port = Integer.parseInt(properties.getProperty(DestinationConstants.REST_PORT_PROP));
} catch (NumberFormatException nfe) {
logger.log(BasicLevel.ERROR, "Property " + DestinationConstants.REST_PORT_PROP
+ " could not be parsed properly, use default value.", nfe);
logger.log(BasicLevel.ERROR,
"Property " + DestinationConstants.REST_PORT_PROP + " could not be parsed properly, use default value.");
}
}
......@@ -216,7 +216,8 @@ public class RESTAcquisition implements AcquisitionHandler {
uriCloseConsumer = response.getLink("close-context").getUri();
uriConsume = response.getLink("receive-message").getUri();
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "RESTAcquisition.createConsumer: uriCloseConsumer = " + uriCloseConsumer + ", uriConsume = " + uriConsume);
logger.log(BasicLevel.DEBUG,
"RESTAcquisition.createConsumer: uriCloseConsumer = " + uriCloseConsumer + ", uriConsume = " + uriConsume);
}
}
......@@ -343,12 +344,14 @@ public class RESTAcquisition implements AcquisitionHandler {
}
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "getMapMessage: ignore map entry " + key + ", " + value + " : " + e.getMessage());
logger.log(BasicLevel.ERROR,
"getMapMessage: ignore map entry " + key + ", " + value + " : " + e.getMessage());
continue;
}
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "getMapMessage: " + key + ", value = " + value + ", " + value.getClass().getSimpleName());
logger.log(BasicLevel.DEBUG,
"getMapMessage: " + key + ", value = " + value + ", " + value.getClass().getSimpleName());
}
return map;
}
......@@ -501,13 +504,15 @@ public class RESTAcquisition implements AcquisitionHandler {
} break;
default:
logger.log(BasicLevel.ERROR, "TODO::: RESTAcquisition.retrieve type = " + type + " not supported.");
logger.log(BasicLevel.ERROR, "RESTAcquisition.retrieve type = " + type + " not supported.");
break;
}
}
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.WARN))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "RESTAcquisition.retrieve json = " + json, e);
else
logger.log(BasicLevel.WARN, "RESTAcquisition.retrieve json = " + json + "\n\t" + e.getMessage());
message = null;
}
}
......@@ -521,8 +526,10 @@ public class RESTAcquisition implements AcquisitionHandler {
if (messages.size() > 0)
transmitter.transmit(messages, persistent);
} catch (Exception e) {
if (logger.isLoggable(BasicLevel.WARN))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "RESTAcquisition.retrieve", e);
else
logger.log(BasicLevel.WARN, "RESTAcquisition.retrieve:" + e.getMessage());
}
}
......@@ -535,8 +542,10 @@ public class RESTAcquisition implements AcquisitionHandler {
try {
persistent = ConversionHelper.toBoolean(properties.get(DestinationConstants.ACQUISITION_PERSISTENT));
} catch (MessageValueException e) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, "", e);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "RESTAcquisition.setProperties", e);
else
logger.log(BasicLevel.WARN, "RESTAcquisition.setProperties: " + e.getMessage());
}
}
......
......@@ -103,7 +103,7 @@ public class RESTDistribution implements DistributionHandler {
port = Integer.parseInt(properties.getProperty(DestinationConstants.REST_PORT_PROP));
} catch (NumberFormatException exc) {
logger.log(BasicLevel.ERROR,
"Property " + DestinationConstants.REST_PORT_PROP + " could not be parsed properly, use default value: " + port, exc);
"Property " + DestinationConstants.REST_PORT_PROP + " could not be parsed properly, use default value: " + port);
}
} else {
logger.log(BasicLevel.WARN,
......@@ -168,9 +168,12 @@ public class RESTDistribution implements DistributionHandler {
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, readTimeout));
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RestDistribution.createProducer(): cannot initialize Rest client", exc);
else
logger.log(BasicLevel.ERROR,
"RestDistribution.createProducer(): cannot initialize Rest client - " + exc.getMessage());
throw exc;
}
......@@ -180,9 +183,12 @@ public class RESTDistribution implements DistributionHandler {
response = client.target(base).path("jndi").path(destName)
.request().accept(MediaType.TEXT_PLAIN).head();
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RestDistribution.createProducer(): cannot get destination " + destName, exc);
else
logger.log(BasicLevel.ERROR,
"RestDistribution.createProducer(): cannot get destination " + destName + "\n\t" + exc.getMessage());
throw exc;
}
......@@ -223,7 +229,6 @@ public class RESTDistribution implements DistributionHandler {
}
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "RestDistribution.createProducer(): create-consumer = " + target.getUri());
logger.log(BasicLevel.WARN, "RestDistribution.createProducer(): create-consumer = " + target.getUri());
if (prodName != null) target = target.queryParam("name", prodName);
if (clientId != null) target = target.queryParam("client-id", clientId);
......@@ -245,9 +250,13 @@ public class RESTDistribution implements DistributionHandler {
response = target.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity(auth, MediaType.APPLICATION_FORM_URLENCODED));
}
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RestDistribution.createProducer(): cannot create producer", exc);
else
logger.log(BasicLevel.ERROR,
"RestDistribution.createProducer(): cannot create producer - " + exc.getMessage());
throw exc;
}
......@@ -279,8 +288,6 @@ public class RESTDistribution implements DistributionHandler {
try {
createProducer(userName, password);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "RestDistribution.distribute(): Cannot create producer", exc);
throw exc;
}
......@@ -308,8 +315,7 @@ public class RESTDistribution implements DistributionHandler {
ois = new ObjectInputStream(bais);
msgMap = (Map) ois.readObject();
} catch (Exception exc) {
MessageFormatException jE =
new MessageFormatException("Error while getting the body.");
MessageFormatException jE = new MessageFormatException("Error while getting the body.");
jE.setLinkedException(exc);
throw jE;
} finally {
......@@ -336,8 +342,7 @@ public class RESTDistribution implements DistributionHandler {
} catch (UnsupportedEncodingException e) {
if (logger.isLoggable(BasicLevel.WARN))
logger.log(BasicLevel.WARN, "", e);
MessageFormatException jE =
new MessageFormatException("Error while encode the bytes to string.");
MessageFormatException jE = new MessageFormatException("Error while encode the bytes to string.");
jE.setLinkedException(e);
throw jE;
}
......
......@@ -222,9 +222,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout)
.property(ClientProperties.READ_TIMEOUT, Integer.parseInt(timeout) + readTimeout));
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RestAcquisitionAsync.createConsumer(): cannot initialize Rest client", exc);
else
logger.log(BasicLevel.ERROR,
"RestAcquisitionAsync.createConsumer(): cannot initialize Rest client - " + exc.getMessage());
throw exc;
}
......@@ -233,9 +236,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
response = client.target(base).path("jndi").path(destName).request().accept(MediaType.TEXT_PLAIN).head();
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RestAcquisitionAsync.createConsumer(): cannot get destination " + destName, exc);
else
logger.log(BasicLevel.ERROR,
"RestAcquisitionAsync.createConsumer(): cannot get destination " + destName + " - " + exc.getMessage());
throw exc;
}
......@@ -294,9 +300,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
response = target.request().accept(MediaType.TEXT_PLAIN).post(Entity.entity(auth, MediaType.APPLICATION_FORM_URLENCODED));
}
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RestAcquisitionAsync.createConsumer(): cannot create consumer", exc);
else
logger.log(BasicLevel.ERROR,
"RestAcquisitionAsync.createConsumer(): cannot create consumer - " + exc.getMessage());
throw exc;
}
......@@ -359,9 +368,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
msg = createJSonMessage(map);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.WARN))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN,
"RestAcquisitionAsync.receiveNextMessage: cannot create message", exc);
else
logger.log(BasicLevel.WARN,
"RestAcquisitionAsync.receiveNextMessage: cannot create message - " + exc.getMessage());
return null;
}
......@@ -375,9 +387,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
msg = createTextMessage(text);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.WARN))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN,
"RestAcquisitionAsync.receiveNextMessage: cannot create message", exc);
else
logger.log(BasicLevel.WARN,
"RestAcquisitionAsync.receiveNextMessage: cannot create message - " + exc.getMessage());
return null;
}
......@@ -415,9 +430,13 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
msg = createTextMessage(text);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.WARN))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN,
"RestAcquisitionAsync.receiveNextMessage: cannot create message", exc);
else
logger.log(BasicLevel.WARN,
"RestAcquisitionAsync.receiveNextMessage: cannot create message", exc);
"RestAcquisitionAsync.receiveNextMessage: cannot create message - " + exc.getMessage());
return null;
}
......@@ -601,9 +620,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
array = (ArrayList<String>) jsonMap.get(key);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.WARN))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN,
"RESTAcquisitionAsync.getMapMessage: bad element, ignore map entry " + key, exc);
else
logger.log(BasicLevel.WARN,
"RESTAcquisitionAsync.getMapMessage: bad element, ignore map entry " + key + " - " + exc.getMessage());
continue;
}
......@@ -627,9 +649,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
}
map.put(key, value);
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.getMapMessage: ignore map entry " + key + ", " + array.get(0) + " / " + classname, exc);
else
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.getMapMessage: ignore map entry " + key + ", " + array.get(0) + " / " + classname + "\n\t" + exc.getMessage());
continue;
}
......@@ -677,9 +702,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
msg.setText((String) body);
return msg;
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.createJSonMessage: error setting message body", exc);
else
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.createJSonMessage: error setting message body - " + exc.getMessage());
throw new Exception("Cannot convert message", exc);
}
} else {
......@@ -702,9 +730,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
baos.close();
return msg;
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.createJSonMessage: error serializing message body", exc);
else
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.createJSonMessage: error serializing message body - " + exc.getMessage());
throw new Exception("Cannot convert message", exc);
}
} else {
......@@ -724,9 +755,12 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
bytes[i] = ((Number) jmsBody.get(i)).byteValue();
}
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.createJSonMessage: error converting BytesMessage", exc);
else
logger.log(BasicLevel.ERROR,
"RESTAcquisitionAsync.createJSonMessage: error converting BytesMessage - " + exc.getMessage());
throw new Exception("Cannot convert message", exc);
}
msg.body = bytes;
......@@ -792,7 +826,10 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.DEBUG, "RestAcquisitionAsync.closeConsumer(): -> " + response.getStatus());
} catch (Exception exc) {
logger.log(BasicLevel.WARN, "RestAcquisitionAsync.closeConsumer()", exc);
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.WARN, "RestAcquisitionAsync.closeConsumer()", exc);
else
logger.log(BasicLevel.WARN, "RestAcquisitionAsync.closeConsumer() - " + exc.getMessage());
return;
} finally {
uriCloseConsumer = null;
......@@ -825,9 +862,6 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
try {
createConsumer();
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
logger.log(BasicLevel.ERROR, "RestAcquisitionAsync.Daemon.run()", exc);
try {
canStop = true;
// TODO (AF): Handles this pause smartly.
......@@ -844,8 +878,10 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
msg = recvNextMessage();
} catch (Exception exc) {
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR, "RestAcquisitionAsync.Daemon.run()", exc);
else
logger.log(BasicLevel.ERROR, "RestAcquisitionAsync.Daemon.run(): " + exc.getMessage());
closeConsumer();
continue;
......@@ -864,8 +900,10 @@ public class RestAcquisitionAsync implements AcquisitionDaemon {
} catch (Exception exc) {
// TODO (AF): Error during transmit ??
if (logger.isLoggable(BasicLevel.ERROR))
if (logger.isLoggable(BasicLevel.DEBUG))
logger.log(BasicLevel.ERROR, "RestAcquisitionAsync.Daemon.run()", exc);
else
logger.log(BasicLevel.ERROR, "RestAcquisitionAsync.Daemon.run(): " + exc.getMessage());
closeConsumer();
continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment