Merge pull request #1377 from nextcloud/bugfix/1013/stopLogFlooding

temporarily disable logging to file
This commit is contained in:
Marcel Hibbe 2021-06-30 15:10:19 +02:00 committed by GitHub
commit 8955015159
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 77 deletions

View file

@ -226,7 +226,6 @@ public class RestModule {
loggingInterceptor.redactHeader("Proxy-Authorization");
httpClient.addInterceptor(loggingInterceptor);
} else if (context.getResources().getBoolean(R.bool.nc_is_debug)) {
HttpLoggingInterceptor.Logger fileLogger =
s -> LoggingUtils.INSTANCE.writeLogEntryToFile(context, s);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(fileLogger);

View file

@ -21,56 +21,49 @@
package com.nextcloud.talk.utils
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import androidx.core.content.FileProvider
import com.nextcloud.talk.BuildConfig
import java.io.FileNotFoundException
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
// TODO: improve log handling. https://github.com/nextcloud/talk-android/issues/1376
// writing logs to a file is temporarily disabled to avoid huge logfiles.
object LoggingUtils {
fun writeLogEntryToFile(context: Context, logEntry: String) {
val dateFormat = SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ROOT)
val date = Date()
val logEntryWithDateTime = dateFormat.format(date) + ": " + logEntry + "\n"
try {
val outputStream = context.openFileOutput(
"nc_log.txt",
Context.MODE_PRIVATE or Context.MODE_APPEND
)
outputStream.write(logEntryWithDateTime.toByteArray())
outputStream.flush()
outputStream.close()
} catch (e: FileNotFoundException) {
e.printStackTrace()
} catch (e: IOException) {
e.printStackTrace()
}
// val dateFormat = SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.ROOT)
// val date = Date()
// val logEntryWithDateTime = dateFormat.format(date) + ": " + logEntry + "\n"
//
// try {
// val outputStream = context.openFileOutput(
// "nc_log.txt",
// Context.MODE_PRIVATE or Context.MODE_APPEND
// )
// outputStream.write(logEntryWithDateTime.toByteArray())
// outputStream.flush()
// outputStream.close()
// } catch (e: FileNotFoundException) {
// e.printStackTrace()
// } catch (e: IOException) {
// e.printStackTrace()
// }
}
fun sendMailWithAttachment(context: Context) {
val logFile = context.getFileStreamPath("nc_log.txt")
val emailIntent = Intent(Intent.ACTION_SEND)
val mailto = "android@nextcloud.com"
emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mailto))
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Talk logs")
emailIntent.type = "text/plain"
emailIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
val uri: Uri
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
uri = Uri.fromFile(logFile)
} else {
uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile)
}
emailIntent.putExtra(Intent.EXTRA_STREAM, uri)
emailIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context.startActivity(emailIntent)
// val logFile = context.getFileStreamPath("nc_log.txt")
// val emailIntent = Intent(Intent.ACTION_SEND)
// val mailto = "android@nextcloud.com"
// emailIntent.putExtra(Intent.EXTRA_EMAIL, arrayOf(mailto))
// emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Talk logs")
// emailIntent.type = "text/plain"
// emailIntent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
// val uri: Uri
//
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
// uri = Uri.fromFile(logFile)
// } else {
// uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, logFile)
// }
//
// emailIntent.putExtra(Intent.EXTRA_STREAM, uri)
// emailIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
// context.startActivity(emailIntent)
}
}

View file

@ -35,7 +35,6 @@ import com.nextcloud.talk.events.WebSocketCommunicationEvent;
import com.nextcloud.talk.models.json.signaling.DataChannelMessage;
import com.nextcloud.talk.models.json.signaling.DataChannelMessageNick;
import com.nextcloud.talk.models.json.signaling.NCIceCandidate;
import com.nextcloud.talk.utils.LoggingUtils;
import org.greenrobot.eventbus.EventBus;
import org.webrtc.DataChannel;
@ -275,8 +274,6 @@ public class MagicPeerConnectionWrapper {
data.get(bytes);
String strData = new String(bytes);
Log.d(TAG, "Got msg: " + strData + " over " + TAG + " " + sessionId);
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"Got msg: " + strData + " over " + peerConnection.hashCode() + " " + sessionId);
try {
DataChannelMessage dataChannelMessage = LoganSquare.parse(strData, DataChannelMessage.class);
@ -350,8 +347,6 @@ public class MagicPeerConnectionWrapper {
@Override
public void onIceConnectionChange(PeerConnection.IceConnectionState iceConnectionState) {
peerIceConnectionState = iceConnectionState;
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"iceConnectionChangeTo: " + iceConnectionState.name() + " over " + peerConnection.hashCode() + " " + sessionId);
Log.d("iceConnectionChangeTo: ", iceConnectionState.name() + " over " + peerConnection.hashCode() + " " + sessionId);
if (iceConnectionState.equals(PeerConnection.IceConnectionState.CONNECTED)) {
@ -441,17 +436,13 @@ public class MagicPeerConnectionWrapper {
@Override
public void onCreateFailure(String s) {
Log.d(TAG, s);
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"SDPObserver createFailure: " + s + " over " + peerConnection.hashCode() + " " + sessionId);
Log.d(TAG, "SDPObserver createFailure: " + s + " over " + peerConnection.hashCode() + " " + sessionId);
}
@Override
public void onSetFailure(String s) {
Log.d(TAG, s);
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"SDPObserver setFailure: " + s + " over " + peerConnection.hashCode() + " " + sessionId);
Log.d(TAG,"SDPObserver setFailure: " + s + " over " + peerConnection.hashCode() + " " + sessionId);
}
@Override

View file

@ -40,7 +40,6 @@ import com.nextcloud.talk.models.json.websocket.ErrorOverallWebSocketMessage;
import com.nextcloud.talk.models.json.websocket.EventOverallWebSocketMessage;
import com.nextcloud.talk.models.json.websocket.HelloResponseOverallWebSocketMessage;
import com.nextcloud.talk.models.json.websocket.JoinedRoomOverallWebSocketMessage;
import com.nextcloud.talk.utils.LoggingUtils;
import com.nextcloud.talk.utils.MagicMap;
import com.nextcloud.talk.utils.bundle.BundleKeys;
@ -152,6 +151,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
public void restartWebSocket() {
reconnecting = true;
// TODO: when improving logging, keep in mind this issue: https://github.com/nextcloud/talk-android/issues/1013
Log.d(TAG, "restartWebSocket: " + connectionUrl);
Request request = new Request.Builder().url(connectionUrl).build();
okHttpClient.newWebSocket(request, this);
@ -162,8 +162,6 @@ public class MagicWebSocketInstance extends WebSocketListener {
public void onMessage(WebSocket webSocket, String text) {
if (webSocket == internalWebSocket) {
Log.d(TAG, "Receiving : " + webSocket.toString() + " " + text);
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket " + webSocket.hashCode() + " receiving: " + text);
try {
BaseWebSocketMessage baseWebSocketMessage = LoganSquare.parse(text, BaseWebSocketMessage.class);
@ -200,8 +198,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
Log.e(TAG, "Received error: " + text);
ErrorOverallWebSocketMessage errorOverallWebSocketMessage = LoganSquare.parse(text, ErrorOverallWebSocketMessage.class);
if (("no_such_session").equals(errorOverallWebSocketMessage.getErrorWebSocketMessage().getCode())) {
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket " + webSocket.hashCode() + " resumeID " + resumeId + " expired");
Log.d(TAG, "WebSocket " + webSocket.hashCode() + " resumeID " + resumeId + " expired");
resumeId = "";
currentRoomToken = "";
restartWebSocket();
@ -299,9 +296,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
break;
}
} catch (IOException e) {
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket " + webSocket.hashCode() + " IOException: " + e.getMessage());
Log.e(TAG, "Failed to recognize WebSocket message");
Log.e(TAG, "Failed to recognize WebSocket message", e);
}
}
}
@ -320,15 +315,11 @@ public class MagicWebSocketInstance extends WebSocketListener {
@Override
public void onClosing(WebSocket webSocket, int code, String reason) {
Log.d(TAG, "Closing : " + code + " / " + reason);
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket " + webSocket.hashCode() + " Closing: " + reason);
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
Log.d(TAG, "Error : " + t.getMessage());
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket " + webSocket.hashCode() + " onFailure: " + t.getMessage());
Log.d(TAG, "Error : WebSocket " + webSocket.hashCode() + " onFailure: " + t.getMessage());
closeWebSocket(webSocket);
}
@ -366,9 +357,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
internalWebSocket.send(message);
}
} catch (IOException e) {
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket sendCalLMessage: " + e.getMessage() + "\n" + ncMessageWrapper.toString());
Log.e(TAG, "Failed to serialize signaling message");
Log.e(TAG, "Failed to serialize signaling message", e);
}
}
@ -387,9 +376,7 @@ public class MagicWebSocketInstance extends WebSocketListener {
internalWebSocket.send(message);
}
} catch (IOException e) {
LoggingUtils.INSTANCE.writeLogEntryToFile(context,
"WebSocket requestOfferForSessionIdWithType: " + e.getMessage() + "\n" + sessionIdParam + " " + roomType);
Log.e(TAG, "Failed to offer request");
Log.e(TAG, "Failed to offer request. sessionIdParam: " + sessionIdParam + " roomType:" + roomType, e);
}
}

View file

@ -1 +1 @@
439
438