Skip to content

Commit

Permalink
mobile: Update Cronvoy API to allow setting log level and logger (env…
Browse files Browse the repository at this point in the history
…oyproxy#32153)

Signed-off-by: Fredy Wijaya <[email protected]>
  • Loading branch information
fredyw authored Feb 2, 2024
1 parent e7550df commit 14faf9d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.chromium.net.ICronetEngineBuilder;
import org.chromium.net.impl.Annotations.HttpCacheType;

import io.envoyproxy.envoymobile.engine.EnvoyEngine;

/** Implementation of {@link ICronetEngineBuilder} that builds Envoy-Mobile based Cronet engine. */
public abstract class CronvoyEngineBuilderImpl extends ICronetEngineBuilder {

Expand Down Expand Up @@ -66,6 +68,8 @@ final static class Pkp {
private String mExperimentalOptions;
private boolean mNetworkQualityEstimatorEnabled;
private int mThreadPriority = INVALID_THREAD_PRIORITY;
private EnvoyEngine.LogLevel mLogLevel = EnvoyEngine.LogLevel.OFF;
private CronvoyLogger mCronvoyLogger = new CronvoyLogger();

/**
* Default config enables SPDY and QUIC, disables SDCH and HTTP cache.
Expand Down Expand Up @@ -357,4 +361,22 @@ int threadPriority(int defaultThreadPriority) {
* @return {@link Context} for builder.
*/
Context getContext() { return mApplicationContext; }

/** Sets the log level. */
public CronvoyEngineBuilderImpl setLogLevel(EnvoyEngine.LogLevel logLevel) {
this.mLogLevel = logLevel;
return this;
}

/** Gets the log level. It defaults to `OFF` when not set. */
public EnvoyEngine.LogLevel getLogLevel() { return mLogLevel; }

/** Sets the {@link io.envoyproxy.envoymobile.engine.types.EnvoyLogger}. */
public CronvoyEngineBuilderImpl setLogger(CronvoyLogger cronvoyLogger) {
this.mCronvoyLogger = cronvoyLogger;
return this;
}

/** Gets the {@link org.chromium.net.impl.CronvoyLogger} implementation. */
public CronvoyLogger getLogger() { return mCronvoyLogger; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* the desired file until CronvoyUrlRequestContext.stopNetLog disables Envoy logging.
*
*/
final class CronvoyLogger implements EnvoyLogger {
public class CronvoyLogger implements EnvoyLogger {
private int mFilesize = 0;
private String mFileName = null;
private FileWriter mWriter = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class CronvoyUrlRequestContext extends CronvoyEngineBase {
private final Object mLock = new Object();
private final ConditionVariable mInitCompleted = new ConditionVariable(false);
private final AtomicInteger mActiveRequestCount = new AtomicInteger(0);
private EnvoyEngine.LogLevel mLogLevel = EnvoyEngine.LogLevel.OFF;
private EnvoyEngine.LogLevel mLogLevel;

@GuardedBy("mLock") private EnvoyEngine mEngine;
/**
Expand All @@ -61,7 +61,7 @@ public final class CronvoyUrlRequestContext extends CronvoyEngineBase {

private final String mUserAgent;
private final AtomicReference<Runnable> mInitializationCompleter = new AtomicReference<>();
private final CronvoyLogger mCronvoyLogger = new CronvoyLogger();
private final CronvoyLogger mCronvoyLogger;

/**
* Locks operations on the list of RequestFinishedInfo.Listeners, because operations can happen
Expand All @@ -84,8 +84,9 @@ public CronvoyUrlRequestContext(NativeCronvoyEngineBuilderImpl builder) {
final int threadPriority =
builder.threadPriority(THREAD_PRIORITY_BACKGROUND + THREAD_PRIORITY_MORE_FAVORABLE);
mUserAgent = builder.getUserAgent();
mLogLevel = builder.getLogLevel();
mCronvoyLogger = builder.getLogger();
synchronized (mLock) {

mEngine = builder.createEngine(() -> {
mNetworkThread = Thread.currentThread();
android.os.Process.setThreadPriority(threadPriority);
Expand Down

0 comments on commit 14faf9d

Please sign in to comment.