Skip to content

Commit

Permalink
Merge pull request #3351 from TeamAmaze/feature/slf4j
Browse files Browse the repository at this point in the history
Remove printstacktraces
  • Loading branch information
VishalNehra authored Jun 14, 2022
2 parents 6e6cf93 + b7648e8 commit d9ba61e
Show file tree
Hide file tree
Showing 46 changed files with 277 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
reportSenderFactoryClasses = AcraReportSenderFactory.class)
public class AppConfig extends GlideApplication {

private static final String TAG = AppConfig.class.getSimpleName();
private static final Logger LOG = LoggerFactory.getLogger(AppConfig.class);

private UtilitiesProvider utilsProvider;
private RequestQueue requestQueue;
Expand All @@ -83,7 +83,6 @@ public class AppConfig extends GlideApplication {
private UtilitiesDatabase utilitiesDatabase;

private ExplorerDatabase explorerDatabase;
private Logger log = null;

public UtilitiesProvider getUtilsProvider() {
return utilsProvider;
Expand All @@ -108,7 +107,6 @@ public void onCreate() {
// disabling file exposure method check for api n+
StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
StrictMode.setVmPolicy(builder.build());
log = LoggerFactory.getLogger(AppConfig.class);
}

@Override
Expand Down Expand Up @@ -258,7 +256,7 @@ protected void initACRA() {
.build();
ACRA.init(this, acraConfig);
} catch (final ACRAConfigurationException ace) {
ace.printStackTrace();
LOG.warn("failed to initialize ACRA", ace);
ErrorActivity.reportError(
this,
ace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

import java.lang.ref.WeakReference;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amaze.filemanager.R;
import com.amaze.filemanager.application.AppConfig;
import com.amaze.filemanager.database.CloudHandler;
Expand All @@ -47,6 +50,8 @@

public class CloudLoaderAsyncTask extends AsyncTask<Void, Void, Boolean> {

private static final Logger LOG = LoggerFactory.getLogger(CloudLoaderAsyncTask.class);

private final Cursor data;
private final WeakReference<MainActivity> mainActivity;
private final CloudHandler cloudHandler;
Expand Down Expand Up @@ -78,7 +83,7 @@ public Boolean doInBackground(Void... voids) {
CloudRail.setAppKey(data.getString(1));
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
LOG.warn("failed to set app key", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_api_key);
Expand Down Expand Up @@ -115,7 +120,7 @@ public Boolean doInBackground(Void... voids) {
try {
cloudStorageDrive.loadAsString(savedCloudEntryGdrive.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
LOG.warn("failed to load cloud storage connection", e);
// we need to update the persist string as existing one is been compromised

cloudStorageDrive.login();
Expand All @@ -133,7 +138,7 @@ public Boolean doInBackground(Void... voids) {
dataUtils.addAccount(cloudStorageDrive);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
LOG.warn("failed to find cloud entry", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
Expand All @@ -143,7 +148,7 @@ public Boolean doInBackground(Void... voids) {
}
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
LOG.warn("failed to authenticate cloud connection", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
Expand All @@ -154,7 +159,7 @@ public Boolean doInBackground(Void... voids) {
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
LOG.warn("Failed to load cloud conn due to network conditions or other error", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
Expand Down Expand Up @@ -186,7 +191,7 @@ public Boolean doInBackground(Void... voids) {
try {
cloudStorageDropbox.loadAsString(savedCloudEntryDropbox.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
LOG.warn("failed to load cloud storage connection", e);
// we need to persist data again

cloudStorageDropbox.login();
Expand All @@ -204,7 +209,7 @@ public Boolean doInBackground(Void... voids) {
dataUtils.addAccount(cloudStorageDropbox);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
LOG.warn("failed to find cloud entry", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
Expand All @@ -214,7 +219,7 @@ public Boolean doInBackground(Void... voids) {
}
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
LOG.warn("failed to authenticate cloud connection", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
Expand All @@ -223,7 +228,7 @@ public Boolean doInBackground(Void... voids) {
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
LOG.warn("Failed to load cloud conn due to network conditions or other error", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
Expand Down Expand Up @@ -253,7 +258,7 @@ public Boolean doInBackground(Void... voids) {
try {
cloudStorageBox.loadAsString(savedCloudEntryBox.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
LOG.warn("failed to load cloud storage connection", e);
// we need to persist data again
cloudStorageBox.login();
cloudEntryBox = new CloudEntry(OpenMode.BOX, cloudStorageBox.saveAsString());
Expand All @@ -268,15 +273,15 @@ public Boolean doInBackground(Void... voids) {
dataUtils.addAccount(cloudStorageBox);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
LOG.warn("failed to find cloud entry", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
mainActivity.deleteConnection(OpenMode.BOX);
} else cancel(true);
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
LOG.warn("failed to authenticate cloud connection", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
Expand All @@ -285,7 +290,7 @@ public Boolean doInBackground(Void... voids) {
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
LOG.warn("Failed to load cloud conn due to network conditions or other error", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
Expand Down Expand Up @@ -315,7 +320,7 @@ public Boolean doInBackground(Void... voids) {
try {
cloudStorageOnedrive.loadAsString(savedCloudEntryOnedrive.getPersistData().value);
} catch (ParseException e) {
e.printStackTrace();
LOG.warn("failed to load cloud storage connection", e);
// we need to persist data again

cloudStorageOnedrive.login();
Expand All @@ -333,15 +338,15 @@ public Boolean doInBackground(Void... voids) {
dataUtils.addAccount(cloudStorageOnedrive);
hasUpdatedDrawer = true;
} catch (CloudPluginException e) {
e.printStackTrace();
LOG.warn("failed to find cloud entry", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_error_plugin);
mainActivity.deleteConnection(OpenMode.ONEDRIVE);
} else cancel(true);
return false;
} catch (AuthenticationException e) {
e.printStackTrace();
LOG.warn("failed to authenticate cloud connection", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.cloud_fail_authenticate);
Expand All @@ -350,7 +355,7 @@ public Boolean doInBackground(Void... voids) {
return false;
} catch (Exception e) {
// any other exception due to network conditions or other error
e.printStackTrace();
LOG.warn("Failed to load cloud conn due to network conditions or other error", e);
final MainActivity mainActivity = this.mainActivity.get();
if (mainActivity != null) {
AppConfig.toast(mainActivity, R.string.failed_cloud_new_connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@

import java.util.ArrayList;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.amaze.filemanager.R;
import com.amaze.filemanager.application.AppConfig;
import com.amaze.filemanager.database.CryptHandler;
Expand Down Expand Up @@ -62,6 +65,8 @@
public class DeleteTask
extends AsyncTask<ArrayList<HybridFileParcelable>, String, AsyncTaskResult<Boolean>> {

private static final Logger LOG = LoggerFactory.getLogger(DeleteTask.class);

private ArrayList<HybridFileParcelable> files;
private final Context applicationContext;
private final boolean rootMode;
Expand Down Expand Up @@ -177,14 +182,14 @@ private boolean doDeleteFile(@NonNull HybridFileParcelable file) throws Exceptio
cloudStorage.delete(CloudUtil.stripPath(file.getMode(), file.getPath()));
return true;
} catch (Exception e) {
e.printStackTrace();
LOG.warn("failed to delete cloud files", e);
return false;
}
default:
try {
return (file.delete(applicationContext, rootMode));
} catch (ShellNotRunningException | SmbException e) {
e.printStackTrace();
LOG.warn("failed to delete files", e);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public LoadFilesListTask(
if (!e.getMessage().toLowerCase().contains("denied")) {
mainFragment.reauthenticateSmb();
}
e.printStackTrace();
LOG.warn("failed to load smb list, authentication issue", e);
return null;
} catch (SmbException | NullPointerException e) {
LOG.warn("Failed to load smb files for path: " + path, e);
Expand Down Expand Up @@ -240,7 +240,7 @@ public LoadFilesListTask(
if (elem != null) list.add(elem);
});
} catch (CloudPluginException e) {
e.printStackTrace();
LOG.warn("failed to load cloud files", e);
AppConfig.toast(context, context.getResources().getString(R.string.failed_no_connection));
return new Pair<>(openmode, list);
}
Expand Down Expand Up @@ -329,7 +329,7 @@ protected void onPostExecute(@Nullable Pair<OpenMode, ArrayList<LayoutElementPar
longSize = baseFile.getSize();
size = Formatter.formatFileSize(context, longSize);
} catch (NumberFormatException e) {
e.printStackTrace();
LOG.warn("failed to create list parcelables", e);
}
}
mainFragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import android.text.TextUtils
import com.amaze.filemanager.ui.activities.texteditor.SearchResultIndex
import com.amaze.filemanager.utils.OnAsyncTaskFinished
import com.amaze.filemanager.utils.OnProgressUpdate
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.IOException
import java.io.LineNumberReader
import java.io.StringReader
Expand All @@ -38,6 +40,8 @@ class SearchTextTask(
) : AsyncTask<Unit, SearchResultIndex, List<SearchResultIndex>>() {
private val lineNumberReader: LineNumberReader

private val log: Logger = LoggerFactory.getLogger(SearchTextTask::class.java)

override fun doInBackground(vararg params: Unit): List<SearchResultIndex> {
if (TextUtils.isEmpty(searchedText)) {
return emptyList()
Expand All @@ -54,7 +58,7 @@ class SearchTextTask(
try {
lineNumberReader.skip((nextPosition - charIndex).toLong())
} catch (e: IOException) {
e.printStackTrace()
log.warn("failed to search text", e)
}
charIndex = nextPosition
val index = SearchResultIndex(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private MoveFilesReturn processFile(
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
}
} catch (ShellNotRunningException e) {
e.printStackTrace();
LOG.warn("failed to move file in local filesystem", e);
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
}
} else {
Expand All @@ -142,7 +142,7 @@ private MoveFilesReturn processFile(
cloudStorage.move(
CloudUtil.stripPath(mode, baseFile.getPath()), CloudUtil.stripPath(mode, destPath));
} catch (RuntimeException e) {
e.printStackTrace();
LOG.warn("failed to move file in cloud filesystem", e);
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import net.schmizz.sshj.userauth.password.Resource
import org.bouncycastle.openssl.PEMKeyPair
import org.bouncycastle.openssl.PEMParser
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.io.IOException
import java.io.InputStream
import java.io.StringReader
Expand Down Expand Up @@ -74,6 +76,8 @@ class PemToKeyPairTask(
OpenSshV1PemToKeyPairConverter(),
PuttyPrivateKeyToKeyPairConverter()
)
private val log: Logger = LoggerFactory.getLogger(PemToKeyPairTask::class.java)

private var paused = false
private var passwordFinder: PasswordFinder? = null
private var errorMessage: String? = null
Expand Down Expand Up @@ -188,7 +192,7 @@ class PemToKeyPairTask(
fun convert(source: String?): KeyPair? = runCatching {
throwingConvert(source)
}.onFailure {
it.printStackTrace()
log.warn("failed to convert pem to keypair", it)
}.getOrNull()

@Throws(Exception::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import net.schmizz.sshj.common.DisconnectReason
import net.schmizz.sshj.common.KeyType
import net.schmizz.sshj.transport.TransportException
import net.schmizz.sshj.userauth.keyprovider.KeyProvider
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.net.SocketException
import java.net.SocketTimeoutException
import java.security.KeyPair
Expand Down Expand Up @@ -72,6 +74,8 @@ class SshAuthenticationTask(
private val privateKey: KeyPair? = null
) : AsyncTask<Void, Void, AsyncTaskResult<SSHClient>>() {

private val log: Logger = LoggerFactory.getLogger(SshAuthenticationTask::class.java)

override fun doInBackground(vararg params: Void): AsyncTaskResult<SSHClient> {
val sshClient = SshConnectionPool.sshClientFactory.create(CustomSshJConfig()).also {
it.addHostKeyVerifier(hostKey)
Expand Down Expand Up @@ -102,7 +106,7 @@ class SshAuthenticationTask(
AsyncTaskResult(sshClient)
}
}.getOrElse {
it.printStackTrace()
log.warn("failed to authenticate ssh connection", it)
AsyncTaskResult(it)
}
}
Expand Down
Loading

0 comments on commit d9ba61e

Please sign in to comment.