Java Code Examples for okhttp3.logging.HttpLoggingInterceptor#Logger
The following examples show how to use
okhttp3.logging.HttpLoggingInterceptor#Logger .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InterceptorUtils.java From YCAudioPlayer with Apache License 2.0 | 6 votes |
/** * 创建日志拦截器 * @return HttpLoggingInterceptor */ public static HttpLoggingInterceptor getHttpLoggingInterceptor(boolean debug) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.e("OkHttp", "log = " + message); JsonUtils.printJson("printJson",message); } }); if (debug) { // 测试 loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); } else { // 打包 loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE); } return loggingInterceptor; }
Example 2
Source File: APIProvider.java From EncryptedGsonConverter with Apache License 2.0 | 6 votes |
public APIProvider() { // for more detail visit https://github.com/simbiose/Encryption Encryption encryption = Encryption.getDefault("MyKey", "MySalt", new byte[16]); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.i("Network log", message); } }); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); okHttpClient = new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build(); retrofit = new Retrofit.Builder() .client(okHttpClient) .baseUrl(BASE_URL) .addConverterFactory(GsonEncryptConverterFactory.create(encryption)) .build(); apiService = retrofit.create(APIService.class); }
Example 3
Source File: RetrofitBase.java From OkhttpCacheInterceptor with Academic Free License v3.0 | 6 votes |
public RetrofitBase(Context context) { loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.d("HttpRetrofit", message + ""); } }); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); client = new OkHttpClient.Builder() .addInterceptor(new CacheInterceptor(context))//添加缓存拦截器,添加缓存的支持 .addInterceptor(loggingInterceptor) .retryOnConnectionFailure(true)//失败重连 .connectTimeout(30, TimeUnit.SECONDS)//网络请求超时时间单位为秒 .build(); retrofit = new Retrofit.Builder() //01:获取Retrofit对象 .baseUrl("http://gc.ditu.aliyun.com/") //02采用链式结构绑定Base url .addConverterFactory(GsonConverterFactory.create())//再将转换成bean .client(client) .build();//03执行操作 }
Example 4
Source File: NetworkManager.java From DoingDaily with Apache License 2.0 | 5 votes |
private static HttpLoggingInterceptor createLogInterceptor() { HttpLoggingInterceptor.Logger logger = new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { LogUtil.logI("http", message); } }; HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); return loggingInterceptor; }
Example 5
Source File: ApiServiceModule.java From v9porn with MIT License | 5 votes |
@Singleton @Provides HttpLoggingInterceptor providesHttpLoggingInterceptor() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(@NonNull String message) { Logger.t("OkHttp").d(message); } }); logging.setLevel(HttpLoggingInterceptor.Level.HEADERS); return logging; }
Example 6
Source File: WebServiceClient.java From device-database with Apache License 2.0 | 5 votes |
private WebServiceClient() { final Gson gson = new GsonBuilder() .setFieldNamingPolicy(FieldNamingPolicy .LOWER_CASE_WITH_UNDERSCORES) .create(); Retrofit.Builder retrofitBuilder = new Retrofit.Builder() .baseUrl("http://www.mocky.io") .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)); if (BuildConfig.DEBUG) { final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor .Logger() { @Override public void log(String message) { Log.d(TAG, message); } }); retrofitBuilder.callFactory(new OkHttpClient .Builder() .addNetworkInterceptor(loggingInterceptor) .build()); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); } service = retrofitBuilder.build().create(DeviceService.class); }
Example 7
Source File: HttpManager.java From RxjavaRetrofitDemo-master with MIT License | 5 votes |
/** * 日志输出 * 自行判定是否添加 * @return */ private HttpLoggingInterceptor getHttpLoggingInterceptor(){ //日志显示级别 HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.BODY; //新建log拦截器 HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.d("RxRetrofit","Retrofit====Message:"+message); } }); loggingInterceptor.setLevel(level); return loggingInterceptor; }
Example 8
Source File: OkHttp3LoggingInterceptorAutoConfiguration.java From okhttp-spring-boot with MIT License | 5 votes |
@Bean @ApplicationInterceptor @ConditionalOnMissingBean public HttpLoggingInterceptor okHttp3LoggingInterceptor( OkHttp3LoggingInterceptorProperties properties, ObjectProvider<HttpLoggingInterceptor.Logger> logger ) { HttpLoggingInterceptor.Logger actualLogger = logger.getIfUnique(() -> HttpLoggingInterceptor.Logger.DEFAULT); HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(actualLogger); httpLoggingInterceptor.level(properties.getLevel()); return httpLoggingInterceptor; }
Example 9
Source File: HttpManager.java From RxjavaRetrofitDemo-string-master with MIT License | 5 votes |
/** * 日志输出 * 自行判定是否添加 * * @return */ private HttpLoggingInterceptor getHttpLoggingInterceptor() { //日志显示级别 HttpLoggingInterceptor.Level level = HttpLoggingInterceptor.Level.BODY; //新建log拦截器 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.d("RxRetrofit", "Retrofit====Message:" + message); } }); loggingInterceptor.setLevel(level); return loggingInterceptor; }
Example 10
Source File: UberRidesApiTest.java From rides-java-sdk with MIT License | 5 votes |
@Test public void setLogger_isSetAfterBuild() { HttpLoggingInterceptor.Logger logger = HttpLoggingInterceptor.Logger.DEFAULT; UberRidesApi.Builder builder = UberRidesApi.with(session).setLogger(logger); builder.build(); assertEquals(logger, builder.logger); }
Example 11
Source File: RetrofitClientApp.java From RetrofitGO with Apache License 2.0 | 5 votes |
/** * 初始化默认的RetrofitClient * @param application * @param debug */ public static void initDefaultRetrofitClient(Application application, boolean debug) { RetrofitConfig.Builder builder = new RetrofitConfig.Builder() .addConverterFactory(CommonGsonConverterFactory.create()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()); // .addInterceptor(new CommonRequestHeadersInterceptor()) // .addInterceptor(new CommonRequestParamsInterceptor()); if (debug) { // 添加日志拦截器 HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.d("RetrofitClient", "OkHttp====Message:" + message); } }); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); //日志拦截器需要放到其它拦截器后面,不然有些信息打印不出,比如请求头信息 //OkHttp进行添加拦截器loggingInterceptor builder.addInterceptor(loggingInterceptor); // 添加Stetho调试拦截器,并初始化 builder.addNetworkInterceptor(new StethoInterceptor()); Stetho.initializeWithDefaults(application); } RetrofitClient.init(application, builder.build()); }
Example 12
Source File: HttpManager.java From Bailan with Apache License 2.0 | 5 votes |
/** * 日志输出 * 自行判定是否添加 * @return */ private HttpLoggingInterceptor getHttpLoggingInterceptor(){ //日志显示级别 HttpLoggingInterceptor.Level level= HttpLoggingInterceptor.Level.BODY; //新建log拦截器 HttpLoggingInterceptor loggingInterceptor=new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.d("RxRetrofit","Retrofit====Message:"+message); } }); loggingInterceptor.setLevel(level); return loggingInterceptor; }
Example 13
Source File: RetrofitActivity.java From AndroidDemo with MIT License | 5 votes |
@Override protected void init() { et_query = (EditText) findViewById(R.id.et_query); et_id = (EditText) findViewById(R.id.et_id); et_title = (EditText) findViewById(R.id.et_title); et_content = (EditText) findViewById(R.id.et_content); et_delete = (EditText) findViewById(R.id.et_delete); btn_query = (Button) findViewById(R.id.btn_query); btn_new = (Button) findViewById(R.id.btn_new); btn_update = (Button) findViewById(R.id.btn_update); btn_delete = (Button) findViewById(R.id.btn_delete); tv = (TextView) findViewById(R.id.tv); scrollView = (ScrollView) findViewById(R.id.scrollView); Gson gson = new GsonBuilder() .setDateFormat("yyyy-MM-dd HH:mm:ss") .create(); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { //打印retrofit日志 Log.i("RetrofitLog", "retrofitBack = " + message); } }); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build(); retrofit = new Retrofit.Builder() .addConverterFactory(GsonConverterFactory.create(gson)) .baseUrl("http://192.168.1.104:4567/") .client(client) .build(); }
Example 14
Source File: MaoniDoorbellListener.java From maoni with MIT License | 5 votes |
/** * Constructor, from a Builder instance * @param builder the builder instance */ public MaoniDoorbellListener(Builder builder) { this.mActivity = builder.activity; this.mApplicationId = builder.applicationId; this.mApplicationKey = builder.applicationKey; this.mFeedbackHeaderTextProvider = builder.feedbackHeaderTextProvider; this.mFeedbackFooterTextProvider = builder.feedbackFooterTextProvider; this.mHttpHeaders = builder.httpHeaders; this.mSkipFilesUpload = builder.skipFilesUpload; this.mWaitDialogTitle = builder.waitDialogTitle; this.mWaitDialogMessage = builder.waitDialogMessage; this.mWaitDialogCancelButtonText = builder.waitDialogCancelButtonText; this.mAdditionalPropertiesProvider = builder.additionalPropertiesProvider; this.mAdditionalTagsProvider = builder.additionalTagsProvider; this.mTransferListener = builder.transferListener; final OkHttpClient.Builder okHttpClientBilder = new OkHttpClient().newBuilder(); okHttpClientBilder.readTimeout(builder.readTimeout, builder.readTimeoutUnit); okHttpClientBilder.connectTimeout(builder.connectTimeout, builder.connectTimeoutUnit); if (builder.debug) { final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Log.d(USER_AGENT, message); } }); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); okHttpClientBilder.addInterceptor(interceptor); } this.mDoorbellService = new Retrofit.Builder() .baseUrl(FEEDBACK_API_BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .client(okHttpClientBilder.build()) .build() .create(DoorbellService.class); }
Example 15
Source File: ApiServiceModule.java From v9porn with MIT License | 5 votes |
@Singleton @Provides HttpLoggingInterceptor providesHttpLoggingInterceptor() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(@NonNull String message) { Logger.t(TAG).d(message); } }); logging.setLevel(HttpLoggingInterceptor.Level.HEADERS); return logging; }
Example 16
Source File: HttpBase.java From TestHub with MIT License | 5 votes |
/** * 日志拦截器 * * @return */ private HttpLoggingInterceptor getHttpLoggingInterceptor() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { Reporter.log("RetrofitLog--> " + message, true); } }); logging.setLevel(HttpLoggingInterceptor.Level.BODY);//Level中还有其他等级 return logging; }
Example 17
Source File: OkHttp3LoggingInterceptorAutoConfigurationTest.java From okhttp-spring-boot with MIT License | 4 votes |
@Bean public HttpLoggingInterceptor.Logger customLogger() { return LOGGER; }
Example 18
Source File: UberRidesApi.java From rides-java-sdk with MIT License | 4 votes |
HttpLoggingInterceptor createLoggingInterceptor(HttpLoggingInterceptor.Logger logger, HttpLoggingInterceptor.Level level) { final HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(logger); loggingInterceptor.setLevel(level); return loggingInterceptor; }
Example 19
Source File: UberRidesApi.java From rides-java-sdk with MIT License | 4 votes |
/** * Sets the {@link okhttp3.logging.HttpLoggingInterceptor.Logger} to use. * Optional and defaults to {@link okhttp3.logging.HttpLoggingInterceptor.Logger#DEFAULT} */ @Nonnull public Builder setLogger(@Nonnull HttpLoggingInterceptor.Logger logger) { this.logger = logger; return this; }
Example 20
Source File: RetrofitManager.java From Collection-Android with MIT License | 4 votes |
/**************************************获取OKHttp******************************************/ public static OkHttpClient getOkHttpClient(boolean isCache, boolean isHeaders){ OkHttpClient.Builder builder = new OkHttpClient.Builder(); //如果不是在正式包,添加拦截 打印响应json if (Config.DEBUG) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() { @Override public void log(String message) { LogUtils.info("RetrofitManager", "收到响应: " + message); } }); logging.setLevel(HttpLoggingInterceptor.Level.BODY); builder.addInterceptor(logging); } if(isHeaders&& Config.HEADERS!=null&& Config.HEADERS.size()>0){ BasicParamsInterceptor basicParamsInterceptor=new BasicParamsInterceptor.Builder() .addHeaderParamsMap(Config.HEADERS) .build(); builder.addInterceptor(basicParamsInterceptor); } if (isCache&&!TextUtils.isEmpty(Config.URL_CACHE) && Config.CONTEXT != null) { //设置缓存 File httpCacheDirectory = new File(Config.URL_CACHE); builder.cache(new Cache(httpCacheDirectory, Config.MAX_MEMORY_SIZE)); builder.addInterceptor(RequestManager.getInterceptor()); } OkHttpClient okHttpClient = builder. connectTimeout(Config.CONNECT_TIMEOUT_SECONDS, TimeUnit.SECONDS) .readTimeout(Config.READ_TIMEOUT_SECONDS, TimeUnit.SECONDS) .writeTimeout(Config.WRITE_TIMEOUT_SECONDS, TimeUnit.SECONDS) .build(); return okHttpClient; }