mirror of
https://github.com/M66B/FairEmail.git
synced 2025-01-04 06:20:26 +00:00
Added log ring buffer
This commit is contained in:
parent
7bc5e96f2e
commit
b1c5951c14
3 changed files with 67 additions and 3 deletions
|
@ -45,8 +45,6 @@ import com.sun.mail.util.MailConnectException;
|
||||||
import com.sun.mail.util.SocketConnectException;
|
import com.sun.mail.util.SocketConnectException;
|
||||||
import com.sun.mail.util.TraceOutputStream;
|
import com.sun.mail.util.TraceOutputStream;
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -80,7 +78,6 @@ import java.util.concurrent.ExecutorService;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.mail.AuthenticationFailedException;
|
import javax.mail.AuthenticationFailedException;
|
||||||
import javax.mail.Authenticator;
|
|
||||||
import javax.mail.Folder;
|
import javax.mail.Folder;
|
||||||
import javax.mail.MessagingException;
|
import javax.mail.MessagingException;
|
||||||
import javax.mail.NoSuchProviderException;
|
import javax.mail.NoSuchProviderException;
|
||||||
|
@ -117,6 +114,7 @@ public class EmailService implements AutoCloseable {
|
||||||
private Service iservice;
|
private Service iservice;
|
||||||
private StoreListener listener;
|
private StoreListener listener;
|
||||||
private ServiceAuthenticator authenticator;
|
private ServiceAuthenticator authenticator;
|
||||||
|
private RingBuffer<String> breadcrumbs;
|
||||||
|
|
||||||
private ExecutorService executor = Helper.getBackgroundExecutor(0, "mail");
|
private ExecutorService executor = Helper.getBackgroundExecutor(0, "mail");
|
||||||
|
|
||||||
|
@ -136,6 +134,7 @@ public class EmailService implements AutoCloseable {
|
||||||
private final static int POOL_SIZE = 1; // connections
|
private final static int POOL_SIZE = 1; // connections
|
||||||
private final static int POOL_TIMEOUT = 60 * 1000; // milliseconds, default 45 sec
|
private final static int POOL_TIMEOUT = 60 * 1000; // milliseconds, default 45 sec
|
||||||
private final static long PROTOCOL_LOG_DURATION = 12 * 3600 * 1000L;
|
private final static long PROTOCOL_LOG_DURATION = 12 * 3600 * 1000L;
|
||||||
|
private final static int BREADCRUMBS_SIZE = 100;
|
||||||
|
|
||||||
private final static int MAX_IPV4 = 2;
|
private final static int MAX_IPV4 = 2;
|
||||||
private final static int MAX_IPV6 = 1;
|
private final static int MAX_IPV6 = 1;
|
||||||
|
@ -679,6 +678,8 @@ public class EmailService implements AutoCloseable {
|
||||||
SSLSocketFactoryService factory) throws MessagingException {
|
SSLSocketFactoryService factory) throws MessagingException {
|
||||||
isession = Session.getInstance(properties, authenticator);
|
isession = Session.getInstance(properties, authenticator);
|
||||||
|
|
||||||
|
breadcrumbs = new RingBuffer<>(BREADCRUMBS_SIZE);
|
||||||
|
|
||||||
isession.setDebug(debug || log);
|
isession.setDebug(debug || log);
|
||||||
if (debug || log)
|
if (debug || log)
|
||||||
isession.setDebugOut(new PrintStream(new OutputStream() {
|
isession.setDebugOut(new PrintStream(new OutputStream() {
|
||||||
|
@ -693,6 +694,7 @@ public class EmailService implements AutoCloseable {
|
||||||
if (log)
|
if (log)
|
||||||
EntityLog.log(context, EntityLog.Type.Protocol, user + " " + line);
|
EntityLog.log(context, EntityLog.Type.Protocol, user + " " + line);
|
||||||
else {
|
else {
|
||||||
|
breadcrumbs.push(line);
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
Log.i("javamail", user + " " + line);
|
Log.i("javamail", user + " " + line);
|
||||||
}
|
}
|
||||||
|
@ -876,6 +878,11 @@ public class EmailService implements AutoCloseable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void dump() {
|
||||||
|
while (breadcrumbs != null && !breadcrumbs.isEmpty())
|
||||||
|
EntityLog.log(context, "Crumb " + breadcrumbs.pop());
|
||||||
|
}
|
||||||
|
|
||||||
private static class SocketFactoryService extends SocketFactory {
|
private static class SocketFactoryService extends SocketFactory {
|
||||||
private SocketFactory factory = SocketFactory.getDefault();
|
private SocketFactory factory = SocketFactory.getDefault();
|
||||||
|
|
||||||
|
|
56
app/src/main/java/eu/faircode/email/RingBuffer.java
Normal file
56
app/src/main/java/eu/faircode/email/RingBuffer.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package eu.faircode.email;
|
||||||
|
|
||||||
|
/*
|
||||||
|
This file is part of FairEmail.
|
||||||
|
|
||||||
|
FairEmail is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
FairEmail is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class RingBuffer<T> {
|
||||||
|
private T[] buffer;
|
||||||
|
private int count = 0;
|
||||||
|
private int out = 0;
|
||||||
|
private int in = 0;
|
||||||
|
|
||||||
|
public RingBuffer(int capacity) {
|
||||||
|
buffer = (T[]) new Object[capacity];
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void push(T item) {
|
||||||
|
if (count == buffer.length)
|
||||||
|
pop();
|
||||||
|
|
||||||
|
buffer[in] = item;
|
||||||
|
in = (in + 1) % buffer.length;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized T pop() {
|
||||||
|
T item = buffer[out];
|
||||||
|
buffer[out] = null;
|
||||||
|
count--;
|
||||||
|
out = (out + 1) % buffer.length;
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized boolean isEmpty() {
|
||||||
|
return (count == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized int size() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2130,6 +2130,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
Log.i(account.name + " done state=" + state);
|
Log.i(account.name + " done state=" + state);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
last_fail = ex;
|
last_fail = ex;
|
||||||
|
iservice.dump();
|
||||||
Log.e(account.name, ex);
|
Log.e(account.name, ex);
|
||||||
EntityLog.log(this, EntityLog.Type.Account,
|
EntityLog.log(this, EntityLog.Type.Account,
|
||||||
account.name + " connect " + Log.formatThrowable(ex, false));
|
account.name + " connect " + Log.formatThrowable(ex, false));
|
||||||
|
|
Loading…
Reference in a new issue