Skip to content

Commit

Permalink
Modify print stacktrace to logger instead of stdout
Browse files Browse the repository at this point in the history
Signed-off-by: Sruti Parthiban <[email protected]>
  • Loading branch information
sruti1312 committed Apr 29, 2021
1 parent 12d58c0 commit 1ae8f68
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static HttpServer createInternalServer(
LOG.error("Could not create HttpServer on port {}", webServerPort, ex);
Runtime.getRuntime().halt(1);
} catch (Exception ex) {
ex.printStackTrace();
LOG.error("Unable to create HttpServer", ex);
Runtime.getRuntime().halt(1);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void collectAPIData(

collectStats(db, dbTimestamp, metricList, aggList, dimList, responseObserver);
} catch (Exception e) {
e.printStackTrace();
LOG.error("Exception during collecting API data", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ private ManagedChannel buildSecureChannel(final InstanceDetails remoteHost) {
.maxRetryAttempts(MAX_RETRY_ATTEMPTS)
.build();
} catch (SSLException e) {
LOG.error("Unable to build an SSL gRPC client. Exception: {}", e.getMessage());
e.printStackTrace();
LOG.error("Unable to build an SSL gRPC client.", e);

// Wrap the SSL Exception in a generic RTE and re-throw.
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,7 @@ private void readRcaEnabledFromConf() {
LOG.info("RCA enabled changed from {} to {}", oldVal, newVal);
}
} catch (IOException e) {
LOG.error("Error reading file '{}': {}", filePath.toString(), e);
e.printStackTrace();
LOG.error("Error reading file {}", filePath.toString(), e);
rcaEnabled = rcaEnabledDefaultValue;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public static String getElectedMasterHostAddress() {

return inputLine;
} catch (IOException e) {
LOG.error("Could not get the elected master node: {}", e.getMessage());
e.printStackTrace();
LOG.error("Could not get the elected master node", e);
}

return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public MetricFlowUnit gather(Queryable queryable) {
PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat(
ExceptionsAndErrors.EXCEPTION_IN_GATHER, name(), 1);
// TODO: Emit log/stats that gathering failed.
LOG.error("RCA: Caught an exception while getting the DB {}", e.getMessage());
e.printStackTrace();
LOG.error("RCA: Caught an exception while getting the DB", e);
return MetricFlowUnit.generic();
}
try {
Expand All @@ -94,8 +93,7 @@ public MetricFlowUnit gather(Queryable queryable) {
} catch (Exception e) {
PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat(
ExceptionsAndErrors.EXCEPTION_IN_GATHER, name(), 1);
e.printStackTrace();
LOG.error("Metric exception: {}", e.getMessage());
LOG.error("Metric exception:", e);
}
return MetricFlowUnit.generic();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void generateFlowUnitListFromLocal(FlowUnitOperationArgWrapper args) {
} catch (Exception ex) {
PerformanceAnalyzerApp.ERRORS_AND_EXCEPTIONS_AGGREGATOR.updateStat(
ExceptionsAndErrors.EXCEPTION_IN_OPERATE, name(), 1);
ex.printStackTrace();
LOG.error("Exception caught during operate", ex);
result = SymptomFlowUnit.generic();
}
long endTime = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ public void onNext(FlowUnitMessage flowUnitMessage) {
*/
@Override
public void onError(Throwable throwable) {
LOG.error(
"Client ran into an error while streaming flow units: {}",
throwable.getMessage());
throwable.printStackTrace();
LOG.error("Client ran into an error while streaming flow units:", throwable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ private void startExceptionHandlingThread() {
} catch (CancellationException cex) {
LOG.info("Periodic sampler cancellation requested.");
} catch (Exception ex) {
LOG.error(
"Resource state poller exception cause : {}",
ex.getCause());
ex.printStackTrace();
LOG.error("Resource state poller exception cause:", ex);
}
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class NamedCounter implements IStatistic<NamedAggregateValue> {

private static final Logger LOG = LogManager.getLogger(NamedCounter.class);
private boolean empty;
private Map<String, NamedAggregateValue> counters;

Expand Down Expand Up @@ -61,7 +65,7 @@ public void calculate(String key, Number value) {
counters.put(key, mapValue);
empty = false;
} catch (Exception ex) {
ex.printStackTrace();
LOG.error("Caught an exception while calculating the counter value", ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,10 @@ public void writeTmpFileWithPrivilege(List<Event> dataEntries, long epoch) {
writeInternal(out, data);
}
} catch (IOException e) {
e.printStackTrace();
LOG.error(
"Error writing entry '{}'. Cause: {}",
"Error writing entry '{}'. Cause:",
currEntry == null ? "NOT_INITIALIZED" : currEntry.key,
e.getMessage());
e);
}
}

Expand All @@ -118,8 +117,7 @@ public void renameFromTmpWithPrivilege(long epoch) {
try {
Files.move(tmpPath, path, REPLACE_EXISTING, ATOMIC_MOVE);
} catch (IOException e) {
e.printStackTrace();
LOG.error("Error moving file {} to {}.", tmpPath.toString(), path.toString());
LOG.error("Error moving file {} to {}.", tmpPath.toString(), path.toString(), e);
}
}

Expand Down Expand Up @@ -165,7 +163,7 @@ private void readInternal(Path pathToFile, int bufferSize, EventDispatcher proce
// TODO: Handle edge case where buffer is too small.
}
} catch (IOException ex) {
ex.printStackTrace();
LOG.error("Error reading file", ex);
}
}
}

0 comments on commit 1ae8f68

Please sign in to comment.