Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.

Commit

Permalink
Replace log_oc with timber
Browse files Browse the repository at this point in the history
  • Loading branch information
abelgardep committed Jan 8, 2020
1 parent 8b0f9c4 commit d6364ba
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@
import com.owncloud.android.lib.common.http.HttpConstants;
import com.owncloud.android.lib.common.http.methods.HttpBaseMethod;
import com.owncloud.android.lib.common.network.RedirectionPath;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.common.utils.RandomUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import okhttp3.Cookie;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import timber.log.Timber;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -58,7 +57,6 @@ public class OwnCloudClient extends HttpClient {
public static final String STATUS_PATH = "/status.php";
public static final String FILES_WEB_PATH = "/index.php/apps/files";

private static final String TAG = OwnCloudClient.class.getSimpleName();
private static final int MAX_REDIRECTIONS_COUNT = 3;
private static final int MAX_REPEAT_COUNT_WITH_FRESH_CREDENTIALS = 1;

Expand Down Expand Up @@ -86,7 +84,7 @@ public OwnCloudClient(Uri baseUri) {
mBaseUri = baseUri;

mInstanceNumber = sIntanceCounter++;
Log_OC.d(TAG + " #" + mInstanceNumber, "Creating OwnCloudClient");
Timber.d(" #" + mInstanceNumber + "Creating OwnCloudClient");

clearCredentials();
clearCookies();
Expand Down Expand Up @@ -163,7 +161,7 @@ private void setRequestId(HttpBaseMethod method) {
// Header to allow tracing requests in apache and ownCloud logs
addHeaderForAllRequests(OC_X_REQUEST_ID, requestId);

Log_OC.d(TAG, "Executing " + method.getClass().getSimpleName() + " in request with id " + requestId);
Timber.d("Executing " + method.getClass().getSimpleName() + " in request with id " + requestId);
}

public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception {
Expand All @@ -175,15 +173,14 @@ public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception
(status == HttpConstants.HTTP_MOVED_PERMANENTLY ||
status == HttpConstants.HTTP_MOVED_TEMPORARILY ||
status == HttpConstants.HTTP_TEMPORARY_REDIRECT)
) {
) {

final String location = method.getResponseHeader(HttpConstants.LOCATION_HEADER) != null
? method.getResponseHeader(HttpConstants.LOCATION_HEADER)
: method.getResponseHeader(HttpConstants.LOCATION_HEADER_LOWER);

if (location != null) {
Log_OC.d(TAG + " #" + mInstanceNumber,
"Location to redirect: " + location);
Timber.d("#" + mInstanceNumber + "Location to redirect: " + location);

redirectionPath.addLocation(location);

Expand Down Expand Up @@ -216,7 +213,7 @@ public RedirectionPath followRedirection(HttpBaseMethod method) throws Exception
redirectionsCount++;

} else {
Log_OC.d(TAG + " #" + mInstanceNumber, "No location to redirect!");
Timber.d(" #" + mInstanceNumber + "No location to redirect!");
status = HttpConstants.HTTP_NOT_FOUND;
}
}
Expand All @@ -237,8 +234,7 @@ public void exhaustResponse(InputStream responseBodyAsStream) {
responseBodyAsStream.close();

} catch (IOException io) {
Log_OC.e(TAG, "Unexpected exception while exhausting not interesting HTTP response;" +
" will be IGNORED", io);
Timber.e(io, "Unexpected exception while exhausting not interesting HTTP response; will be IGNORED");
}
}
}
Expand Down Expand Up @@ -296,38 +292,6 @@ public void setCredentials(OwnCloudCredentials credentials) {
}
}

private void logCookie(Cookie cookie) {
Log_OC.d(TAG, "Cookie name: " + cookie.name());
Log_OC.d(TAG, " value: " + cookie.value());
Log_OC.d(TAG, " domain: " + cookie.domain());
Log_OC.d(TAG, " path: " + cookie.path());
Log_OC.d(TAG, " expiryDate: " + cookie.expiresAt());
Log_OC.d(TAG, " secure: " + cookie.secure());
}

private void logCookiesAtRequest(Headers headers, String when) {
int counter = 0;
for (final String cookieHeader : headers.toMultimap().get("cookie")) {
Log_OC.d(TAG + " #" + mInstanceNumber,
"Cookies at request (" + when + ") (" + counter++ + "): "
+ cookieHeader);
}
if (counter == 0) {
Log_OC.d(TAG + " #" + mInstanceNumber, "No cookie at request before");
}
}

private void logSetCookiesAtResponse(Headers headers) {
int counter = 0;
for (final String cookieHeader : headers.toMultimap().get("set-cookie")) {
Log_OC.d(TAG + " #" + mInstanceNumber,
"Set-Cookie (" + counter++ + "): " + cookieHeader);
}
if (counter == 0) {
Log_OC.d(TAG + " #" + mInstanceNumber, "No set-cookie");
}
}

public String getCookiesString() {
StringBuilder cookiesString = new StringBuilder();
List<Cookie> cookieList = getCookiesFromUrl(HttpUrl.parse(mBaseUri.toString()));
Expand Down Expand Up @@ -392,11 +356,7 @@ private boolean checkUnauthorizedAccess(int status, int repeatCounter) {
credentialsWereRefreshed = true;

} catch (AccountsException | IOException e) {
Log_OC.e(
TAG,
"Error while trying to refresh auth token for " + mAccount.getSavedAccount().name,
e
);
Timber.e(e, "Error while trying to refresh auth token for %s", mAccount.getSavedAccount().name);
}
}

Expand Down Expand Up @@ -451,10 +411,6 @@ private boolean invalidateAccountCredentials() {
return true;
}

public OwnCloudClientManager getOwnCloudClientManager() {
return mOwnCloudClientManager;
}

void setOwnCloudClientManager(OwnCloudClientManager clientManager) {
mOwnCloudClientManager = clientManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

package com.owncloud.android.lib.common.network;

import com.owncloud.android.lib.common.utils.Log_OC;
import okhttp3.MediaType;
import okio.BufferedSink;
import timber.log.Timber;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -84,17 +84,17 @@ public void writeTo(BufferedSink sink) {
long maxCount = Math.min(mOffset + mChunkSize, mChannel.size());
while (mChannel.position() < maxCount) {

Log_OC.v("Sink buffer size: " + sink.buffer().size());
Timber.v("Sink buffer size: %s", sink.buffer().size());

readCount = mChannel.read(mBuffer);

Log_OC.v("Read " + readCount + " bytes from file channel to " + mBuffer.toString());
Timber.v("Read " + readCount + " bytes from file channel to " + mBuffer.toString());

sink.buffer().write(mBuffer.array(), 0, readCount);

sink.flush();

Log_OC.v("Write " + readCount + " bytes to sink buffer with size " + sink.buffer().size());
Timber.v("Write " + readCount + " bytes to sink buffer with size " + sink.buffer().size());

mBuffer.clear();
if (mTransferred < maxCount) { // condition to avoid accumulate progress for repeated chunks
Expand All @@ -108,10 +108,10 @@ public void writeTo(BufferedSink sink) {
}
}

Log_OC.v("Chunk with size " + mChunkSize + " written in request body");
Timber.v("Chunk with size " + mChunkSize + " written in request body");

} catch (Exception exception) {
Log_OC.e(exception.getMessage());
Timber.e(exception);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@

package com.owncloud.android.lib.resources.files;

import com.owncloud.android.lib.common.utils.Log_OC;
import timber.log.Timber;

import java.io.File;

public class FileUtils {

public static final String PATH_SEPARATOR = "/";
public static final String FINAL_CHUNKS_FILE = ".file";
private static final String TAG = FileUtils.class.getSimpleName();

public static String getParentPath(String remotePath) {
String parentPath = new File(remotePath).getParent();
Expand All @@ -43,15 +42,11 @@ public static String getParentPath(String remotePath) {
/**
* Validate the fileName to detect if contains any forbidden character: / , \ , < , > ,
* : , " , | , ? , *
*
* @param fileName
* @param versionSupportsForbiddenChars
* @return
*/
public static boolean isValidName(String fileName, boolean versionSupportsForbiddenChars) {
boolean result = true;

Log_OC.d(TAG, "fileName =======" + fileName);
Timber.d("fileName =======%s", fileName);
if ((versionSupportsForbiddenChars && fileName.contains(PATH_SEPARATOR)) ||
(!versionSupportsForbiddenChars && (fileName.contains(PATH_SEPARATOR) ||
fileName.contains("\\") || fileName.contains("<") || fileName.contains(">") ||
Expand All @@ -66,14 +61,11 @@ public static boolean isValidName(String fileName, boolean versionSupportsForbid
/**
* Validate the path to detect if contains any forbidden character: \ , < , > , : , " , | ,
* ? , *
*
* @param path
* @return
*/
public static boolean isValidPath(String path, boolean versionSupportsForbidenChars) {
boolean result = true;

Log_OC.d(TAG, "path ....... " + path);
Timber.d("path ....... %s", path);
if (!versionSupportsForbidenChars &&
(path.contains("\\") || path.contains("<") || path.contains(">") ||
path.contains(":") || path.contains("\"") || path.contains("|") ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import com.owncloud.android.lib.common.http.methods.nonwebdav.GetMethod
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.OK
import com.owncloud.android.lib.common.utils.Log_OC
import org.json.JSONObject
import timber.log.Timber
import java.net.URL
import java.util.ArrayList

Expand Down Expand Up @@ -95,13 +95,13 @@ class GetRemoteShareesOperation

val getMethod = GetMethod(URL(uriBuilder.build().toString()))

getMethod.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE)
getMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)

val status = client.executeHttpMethod(getMethod)
val response = getMethod.responseBodyAsString

if (isSuccess(status)) {
Log_OC.d(TAG, "Successful response: " + response!!)
Timber.d("Successful response: $response")

// Parse the response
val respJSON = JSONObject(response)
Expand All @@ -128,65 +128,61 @@ class GetRemoteShareesOperation
for (j in 0 until jsonResults[i].length()) {
val jsonResult = jsonResults[i].getJSONObject(j)
data.add(jsonResult)
Log_OC.d(TAG, "*** Added item: " + jsonResult.getString(PROPERTY_LABEL))
Timber.d("*** Added item: ${jsonResult.getString(PROPERTY_LABEL)}")
}
}

result = RemoteOperationResult(OK)
result.data = data

Log_OC.d(TAG, "*** Get Users or groups completed ")
Timber.d("*** Get Users or groups completed ")

} else {
result = RemoteOperationResult(getMethod)
Log_OC.e(TAG, "Failed response while getting users/groups from the server ")
Timber.e("Failed response while getting users/groups from the server ")
if (response != null) {
Log_OC.e(TAG, "*** status code: $status; response message: $response")
Timber.e("*** status code: $status; response message: $response")
} else {
Log_OC.e(TAG, "*** status code: $status")
Timber.e("*** status code: $status")
}
}
} catch (e: Exception) {
result = RemoteOperationResult(e)
Log_OC.e(TAG, "Exception while getting users/groups", e)
Timber.e(e, "Exception while getting users/groups")
}

return result
}

private fun isSuccess(status: Int): Boolean {
return status == HttpConstants.HTTP_OK
}
private fun isSuccess(status: Int) = status == HttpConstants.HTTP_OK

companion object {

private val TAG = GetRemoteShareesOperation::class.java.simpleName

// OCS Routes
private val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/sharees" // from OC 8.2
private const val OCS_ROUTE = "ocs/v2.php/apps/files_sharing/api/v1/sharees" // from OC 8.2

// Arguments - names
private val PARAM_FORMAT = "format"
private val PARAM_ITEM_TYPE = "itemType"
private val PARAM_SEARCH = "search"
private val PARAM_PAGE = "page" // default = 1
private val PARAM_PER_PAGE = "perPage" // default = 200
private const val PARAM_FORMAT = "format"
private const val PARAM_ITEM_TYPE = "itemType"
private const val PARAM_SEARCH = "search"
private const val PARAM_PAGE = "page" // default = 1
private const val PARAM_PER_PAGE = "perPage" // default = 200

// Arguments - constant values
private val VALUE_FORMAT = "json"
private val VALUE_ITEM_TYPE = "file" // to get the server search for users / groups
private const val VALUE_FORMAT = "json"
private const val VALUE_ITEM_TYPE = "file" // to get the server search for users / groups

// JSON Node names
private val NODE_OCS = "ocs"
private val NODE_DATA = "data"
private val NODE_EXACT = "exact"
private val NODE_USERS = "users"
private val NODE_GROUPS = "groups"
private val NODE_REMOTES = "remotes"
val NODE_VALUE = "value"
val PROPERTY_LABEL = "label"
val PROPERTY_SHARE_TYPE = "shareType"
val PROPERTY_SHARE_WITH = "shareWith"
val PROPERTY_SHARE_WITH_ADDITIONAL_INFO = "shareWithAdditionalInfo"
private const val NODE_OCS = "ocs"
private const val NODE_DATA = "data"
private const val NODE_EXACT = "exact"
private const val NODE_USERS = "users"
private const val NODE_GROUPS = "groups"
private const val NODE_REMOTES = "remotes"
const val NODE_VALUE = "value"
const val PROPERTY_LABEL = "label"
const val PROPERTY_SHARE_TYPE = "shareType"
const val PROPERTY_SHARE_WITH = "shareWith"
const val PROPERTY_SHARE_WITH_ADDITIONAL_INFO = "shareWithAdditionalInfo"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.owncloud.android.lib.common.http.HttpConstants
import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.operations.RemoteOperationResult
import com.owncloud.android.lib.common.utils.Log_OC
import timber.log.Timber
import java.net.URL

/**
Expand Down Expand Up @@ -75,24 +75,19 @@ class RemoveRemoteShareOperation(private val remoteShareId: Long) : RemoteOperat
)
result = parser.parse(deleteMethod.responseBodyAsString)

Log_OC.d(TAG, "Unshare " + remoteShareId + ": " + result.logMessage)
Timber.d("Unshare " + remoteShareId + ": " + result.logMessage)

} else {
result = RemoteOperationResult(deleteMethod)
}

} catch (e: Exception) {
result = RemoteOperationResult(e)
Log_OC.e(TAG, "Unshare Link Exception " + result.logMessage, e)
Timber.e(e, "Unshare Link Exception " + result.logMessage)
}

return result
}

private fun isSuccess(status: Int): Boolean = status == HttpConstants.HTTP_OK

companion object {

private val TAG = RemoveRemoteShareOperation::class.java.simpleName
}
}
}
Loading

0 comments on commit d6364ba

Please sign in to comment.