Skip to content

Commit

Permalink
removed usage printStackTrace as it is considered bad practice in fav…
Browse files Browse the repository at this point in the history
…or of using the logging framework
  • Loading branch information
PeterHasse committed Jul 25, 2024
1 parent e4939e7 commit 3aa3853
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ public void open_write_api() {
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "connect: Can't connect to InfluxDB");
Log.d(TAG,e.toString());
;
}
}

Expand All @@ -104,7 +103,6 @@ public void disconnect() {
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "disconnect: Error while closing write API");
Log.d(TAG,e.toString());
;
}
try {
Log.d(TAG, "disconnect: Closing influx connection");
Expand All @@ -113,7 +111,6 @@ public void disconnect() {
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "disconnect: Error while closing influx connection");
Log.d(TAG,e.toString());
;
}
} else {
Log.d(TAG, "disconnect() was called on not existing instance of the influx client");
Expand All @@ -130,7 +127,6 @@ public boolean writePoint(Point point) {
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "writePoint: Error while writing points to influx DB");
Log.d(TAG,e.toString());
;
return false;
}
return true;
Expand All @@ -155,14 +151,13 @@ public boolean writeRecords(List<String> points) throws IOException {
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "writeRecords: Error while writing points to influx DB");
Log.d(TAG,e.toString());
;
}
} else {
Log.d(TAG, "writeRecords: InfluxDB not reachable: " + url);
}
}
catch (Exception ex) {
ex.printStackTrace();
catch (Exception e) {
Log.d(TAG,e.toString());
}
}).start();
return true;
Expand All @@ -183,14 +178,13 @@ public boolean writePoints(List<Point> points) throws IOException {
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "writePoint: Error while writing points to influx DB");
Log.d(TAG,e.toString());
;
}
} else {
Log.d(TAG, "writePoints: InfluxDB not reachable: " + url);
}
}
catch (Exception ex) {
ex.printStackTrace();
catch (Exception e) {
Log.d(TAG,e.toString());
}
}).start();
return true;
Expand Down Expand Up @@ -231,8 +225,8 @@ public boolean flush() {
if (influxDBClient.ping()) {
writeApi.flush();
}
} catch (Exception ex) {
ex.printStackTrace();
} catch (Exception e) {
Log.d(TAG,e.toString());
}
}).start();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ public void onFragmentResult(@NonNull String requestKey,
Os.setenv("TMPDIR", String.valueOf(getActivity().getCacheDir()), true);
} catch (ErrnoException e) {
Log.d(TAG,e.toString());
;
}
return v;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Interval;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.Stream;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.TCP.TCP_UL_STREAM;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.UDP.UDP_DL_STREAM;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
Expand All @@ -38,6 +34,10 @@
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Interval;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.Stream;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.TCP.TCP_UL_STREAM;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval.Streams.UDP.UDP_DL_STREAM;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;

Expand Down Expand Up @@ -239,7 +239,6 @@ public Result doWork() {
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "logfile not created", Toast.LENGTH_SHORT).show();
Log.d(TAG,e.toString());
;
}

if(iperf3Stream == null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3;

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.preference.PreferenceManager;
import androidx.work.Data;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
Expand Down Expand Up @@ -61,12 +59,11 @@ public Result doWork() {
if(!influx.ping()){
return Result.failure(output);
}
BufferedReader br = null;
BufferedReader br;
try {
br = new BufferedReader(new FileReader(iperf3LineProtocolFile));
} catch (FileNotFoundException | NullPointerException e) {
Log.d(TAG,e.toString());
;
return Result.failure(output);
}
List<String> points = br.lines().collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ private void setupLocalFile() {
} catch (FileNotFoundException e) {
Toast.makeText(getApplicationContext(), "logfile not created", Toast.LENGTH_SHORT).show();
Log.d(TAG,e.toString());
;
}

localFileHandler = new Handler(Objects.requireNonNull(Looper.myLooper()));
Expand All @@ -455,7 +454,6 @@ private void stopLocalFile() {
Log.d(TAG, "trying to stop local file service while it was not running");
} catch (IOException e) {
Log.d(TAG,e.toString());
;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@
import androidx.work.WorkManager;

import com.influxdb.client.write.Point;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DataProvider;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.PingInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
Expand All @@ -48,6 +41,8 @@
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.PingInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;

public class PingService extends Service {
private static final String TAG = "PingService";
Expand Down Expand Up @@ -151,15 +146,13 @@ public void propertyChange(PropertyChangeEvent evt) {
ping_stream.write((point.toLineProtocol() + "\n").getBytes());
} catch (IOException e) {
Log.d(TAG,e.toString());
;
}

if (spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false) && influx.getWriteApi() != null) {
try {
influx.writePoints(List.of(point));
} catch (IOException e) {
Log.d(TAG,e.toString());
;
}
}

Expand Down Expand Up @@ -220,7 +213,6 @@ public void onChanged(Object o) {
ping_stream.close();
} catch (IOException e) {
Log.d(TAG,e.toString());
;
}
pingLogging.removeCallbacks(pingUpdate);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,21 @@
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.MainActivity;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.PingInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.RTTLine;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import de.fraunhofer.fokus.OpenMobileNetworkToolkit.MainActivity;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.PingInformation;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.RTTLine;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper;
import de.fraunhofer.fokus.OpenMobileNetworkToolkit.R;


public class PingWorker extends Worker {

Expand Down Expand Up @@ -200,7 +200,6 @@ public void propertyChange(PropertyChangeEvent evt) {
}
} catch (IOException e) {
Log.d(TAG,e.toString());
;
System.out.printf(e.toString());
} catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ private void enableForwarding() {
filter, FLAG_MANAGED_CAN_ACCESS_PARENT | FLAG_PARENT_CAN_ACCESS_MANAGED);
} catch (IntentFilter.MalformedMimeTypeException e) {
Log.d(TAG,e.toString());
;
}
}

Expand Down

0 comments on commit 3aa3853

Please sign in to comment.