Skip to content

Commit 81e3678

Browse files
committed
L logger refactoring
1 parent ee50fd1 commit 81e3678

File tree

6 files changed

+71
-64
lines changed

6 files changed

+71
-64
lines changed

library/src/com/nostra13/universalimageloader/core/DisplayBitmapTask.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
package com.nostra13.universalimageloader.core;
1717

1818
import android.graphics.Bitmap;
19-
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
2019
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
2120
import com.nostra13.universalimageloader.core.display.BitmapDisplayer;
2221
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
22+
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
2323
import com.nostra13.universalimageloader.utils.L;
2424

2525
/**
@@ -45,8 +45,6 @@ final class DisplayBitmapTask implements Runnable {
4545
private final ImageLoaderEngine engine;
4646
private final LoadedFrom loadedFrom;
4747

48-
private boolean loggingEnabled;
49-
5048
public DisplayBitmapTask(Bitmap bitmap, ImageLoadingInfo imageLoadingInfo, ImageLoaderEngine engine,
5149
LoadedFrom loadedFrom) {
5250
this.bitmap = bitmap;
@@ -62,13 +60,13 @@ public DisplayBitmapTask(Bitmap bitmap, ImageLoadingInfo imageLoadingInfo, Image
6260
@Override
6361
public void run() {
6462
if (imageAware.isCollected()) {
65-
if (loggingEnabled) L.d(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED, memoryCacheKey);
63+
L.d(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED, memoryCacheKey);
6664
listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
6765
} else if (isViewWasReused()) {
68-
if (loggingEnabled) L.d(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED, memoryCacheKey);
66+
L.d(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED, memoryCacheKey);
6967
listener.onLoadingCancelled(imageUri, imageAware.getWrappedView());
7068
} else {
71-
if (loggingEnabled) L.d(LOG_DISPLAY_IMAGE_IN_IMAGEAWARE, loadedFrom, memoryCacheKey);
69+
L.d(LOG_DISPLAY_IMAGE_IN_IMAGEAWARE, loadedFrom, memoryCacheKey);
7270
displayer.display(bitmap, imageAware, loadedFrom);
7371
engine.cancelDisplayTaskFor(imageAware);
7472
listener.onLoadingComplete(imageUri, imageAware.getWrappedView(), bitmap);
@@ -80,8 +78,4 @@ private boolean isViewWasReused() {
8078
String currentCacheKey = engine.getLoadingUriForView(imageAware);
8179
return !memoryCacheKey.equals(currentCacheKey);
8280
}
83-
84-
void setLoggingEnabled(boolean loggingEnabled) {
85-
this.loggingEnabled = loggingEnabled;
86-
}
8781
}

library/src/com/nostra13/universalimageloader/core/ImageLoader.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import android.text.TextUtils;
2222
import android.view.View;
2323
import android.widget.ImageView;
24-
2524
import com.nostra13.universalimageloader.cache.disc.DiskCache;
2625
import com.nostra13.universalimageloader.cache.memory.MemoryCache;
2726
import com.nostra13.universalimageloader.core.assist.FailReason;
@@ -30,8 +29,8 @@
3029
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
3130
import com.nostra13.universalimageloader.core.assist.ViewScaleType;
3231
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
33-
import com.nostra13.universalimageloader.core.imageaware.NonViewAware;
3432
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;
33+
import com.nostra13.universalimageloader.core.imageaware.NonViewAware;
3534
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
3635
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
3736
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
@@ -94,7 +93,7 @@ public synchronized void init(ImageLoaderConfiguration configuration) {
9493
throw new IllegalArgumentException(ERROR_INIT_CONFIG_WITH_NULL);
9594
}
9695
if (this.configuration == null) {
97-
if (configuration.writeLogs) L.d(LOG_INIT_CONFIG);
96+
L.d(LOG_INIT_CONFIG);
9897
engine = new ImageLoaderEngine(configuration);
9998
this.configuration = configuration;
10099
} else {
@@ -237,7 +236,7 @@ public void displayImage(String uri, ImageAware imageAware, DisplayImageOptions
237236

238237
Bitmap bmp = configuration.memoryCache.get(memoryCacheKey);
239238
if (bmp != null && !bmp.isRecycled()) {
240-
if (configuration.writeLogs) L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
239+
L.d(LOG_LOAD_IMAGE_FROM_MEMORY_CACHE, memoryCacheKey);
241240

242241
if (options.shouldPostProcess()) {
243242
ImageLoadingInfo imageLoadingInfo = new ImageLoadingInfo(uri, imageAware, targetSize, memoryCacheKey,
@@ -725,7 +724,7 @@ public void stop() {
725724
* method.
726725
*/
727726
public void destroy() {
728-
if (configuration != null && configuration.writeLogs) L.d(LOG_DESTROY);
727+
if (configuration != null) L.d(LOG_DESTROY);
729728
stop();
730729
configuration.diskCache.close();
731730
engine = null;

library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import android.content.Context;
1919
import android.content.res.Resources;
2020
import android.util.DisplayMetrics;
21-
2221
import com.nostra13.universalimageloader.cache.disc.DiskCache;
2322
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
2423
import com.nostra13.universalimageloader.cache.memory.MemoryCache;
@@ -72,7 +71,6 @@ public final class ImageLoaderConfiguration {
7271
final ImageDownloader downloader;
7372
final ImageDecoder decoder;
7473
final DisplayImageOptions defaultDisplayImageOptions;
75-
final boolean writeLogs;
7674

7775
final ImageDownloader networkDeniedDownloader;
7876
final ImageDownloader slowNetworkDownloader;
@@ -92,7 +90,6 @@ private ImageLoaderConfiguration(final Builder builder) {
9290
diskCache = builder.diskCache;
9391
memoryCache = builder.memoryCache;
9492
defaultDisplayImageOptions = builder.defaultDisplayImageOptions;
95-
writeLogs = builder.writeLogs;
9693
downloader = builder.downloader;
9794
decoder = builder.decoder;
9895

@@ -101,6 +98,8 @@ private ImageLoaderConfiguration(final Builder builder) {
10198

10299
networkDeniedDownloader = new NetworkDeniedImageDownloader(downloader);
103100
slowNetworkDownloader = new SlowNetworkImageDownloader(downloader);
101+
102+
L.writeDebugLogs(builder.writeLogs);
104103
}
105104

106105
/**
@@ -218,7 +217,7 @@ public Builder memoryCacheExtraOptions(int maxImageWidthForMemoryCache, int maxI
218217
*/
219218
@Deprecated
220219
public Builder discCacheExtraOptions(int maxImageWidthForDiskCache, int maxImageHeightForDiskCache,
221-
BitmapProcessor processorForDiskCache) {
220+
BitmapProcessor processorForDiskCache) {
222221
return diskCacheExtraOptions(maxImageWidthForDiskCache, maxImageHeightForDiskCache, processorForDiskCache);
223222
}
224223

@@ -409,7 +408,7 @@ public Builder memoryCache(MemoryCache memoryCache) {
409408
return this;
410409
}
411410

412-
/** @deprecated Use {@link #diskCacheSize(int)} instead */
411+
/** @deprecated Use {@link #diskCacheSize(int)} instead */
413412
@Deprecated
414413
public Builder discCacheSize(int maxCacheSize) {
415414
return diskCacheSize(maxCacheSize);
@@ -547,7 +546,8 @@ public Builder defaultDisplayImageOptions(DisplayImageOptions defaultDisplayImag
547546

548547
/**
549548
* Enables detail logging of {@link ImageLoader} work. To prevent detail logs don't call this method.
550-
* Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable ImageLoader logging completely (even error logs)
549+
* Consider {@link com.nostra13.universalimageloader.utils.L#disableLogging()} to disable
550+
* ImageLoader logging completely (even error logs)
551551
*/
552552
public Builder writeDebugLogs() {
553553
this.writeLogs = true;
@@ -584,8 +584,7 @@ private void initEmptyFieldsWithDefaultValues() {
584584
memoryCache = DefaultConfigurationFactory.createMemoryCache(memoryCacheSize);
585585
}
586586
if (denyCacheImageMultipleSizesInMemory) {
587-
memoryCache = new FuzzyKeyMemoryCache(memoryCache,
588-
MemoryCacheUtils.createFuzzyKeyComparator());
587+
memoryCache = new FuzzyKeyMemoryCache(memoryCache, MemoryCacheUtils.createFuzzyKeyComparator());
589588
}
590589
if (downloader == null) {
591590
downloader = DefaultConfigurationFactory.createImageDownloader(context);

library/src/com/nostra13/universalimageloader/core/LoadAndDisplayImageTask.java

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
import android.graphics.Bitmap;
1919
import android.os.Handler;
20-
2120
import com.nostra13.universalimageloader.core.assist.FailReason;
2221
import com.nostra13.universalimageloader.core.assist.FailReason.FailType;
23-
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
24-
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
2522
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
2623
import com.nostra13.universalimageloader.core.assist.ImageSize;
2724
import com.nostra13.universalimageloader.core.assist.LoadedFrom;
@@ -31,6 +28,8 @@
3128
import com.nostra13.universalimageloader.core.download.ImageDownloader;
3229
import com.nostra13.universalimageloader.core.download.ImageDownloader.Scheme;
3330
import com.nostra13.universalimageloader.core.imageaware.ImageAware;
31+
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;
32+
import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
3433
import com.nostra13.universalimageloader.utils.IoUtils;
3534
import com.nostra13.universalimageloader.utils.L;
3635

@@ -83,7 +82,6 @@ final class LoadAndDisplayImageTask implements Runnable, IoUtils.CopyListener {
8382
private final ImageDownloader networkDeniedDownloader;
8483
private final ImageDownloader slowNetworkDownloader;
8584
private final ImageDecoder decoder;
86-
private final boolean writeLogs;
8785
final String uri;
8886
private final String memoryCacheKey;
8987
final ImageAware imageAware;
@@ -106,7 +104,6 @@ public LoadAndDisplayImageTask(ImageLoaderEngine engine, ImageLoadingInfo imageL
106104
networkDeniedDownloader = configuration.networkDeniedDownloader;
107105
slowNetworkDownloader = configuration.slowNetworkDownloader;
108106
decoder = configuration.decoder;
109-
writeLogs = configuration.writeLogs;
110107
uri = imageLoadingInfo.uri;
111108
memoryCacheKey = imageLoadingInfo.memoryCacheKey;
112109
imageAware = imageLoadingInfo.imageAware;
@@ -123,9 +120,9 @@ public void run() {
123120
if (delayIfNeed()) return;
124121

125122
ReentrantLock loadFromUriLock = imageLoadingInfo.loadFromUriLock;
126-
log(LOG_START_DISPLAY_IMAGE_TASK);
123+
L.d(LOG_START_DISPLAY_IMAGE_TASK, memoryCacheKey);
127124
if (loadFromUriLock.isLocked()) {
128-
log(LOG_WAITING_FOR_IMAGE_LOADED);
125+
L.d(LOG_WAITING_FOR_IMAGE_LOADED, memoryCacheKey);
129126
}
130127

131128
loadFromUriLock.lock();
@@ -142,24 +139,24 @@ public void run() {
142139
checkTaskInterrupted();
143140

144141
if (options.shouldPreProcess()) {
145-
log(LOG_PREPROCESS_IMAGE);
142+
L.d(LOG_PREPROCESS_IMAGE, memoryCacheKey);
146143
bmp = options.getPreProcessor().process(bmp);
147144
if (bmp == null) {
148145
L.e(ERROR_PRE_PROCESSOR_NULL, memoryCacheKey);
149146
}
150147
}
151148

152149
if (bmp != null && options.isCacheInMemory()) {
153-
log(LOG_CACHE_IMAGE_IN_MEMORY);
150+
L.d(LOG_CACHE_IMAGE_IN_MEMORY, memoryCacheKey);
154151
configuration.memoryCache.put(memoryCacheKey, bmp);
155152
}
156153
} else {
157154
loadedFrom = LoadedFrom.MEMORY_CACHE;
158-
log(LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING);
155+
L.d(LOG_GET_IMAGE_FROM_MEMORY_CACHE_AFTER_WAITING, memoryCacheKey);
159156
}
160157

161158
if (bmp != null && options.shouldPostProcess()) {
162-
log(LOG_POSTPROCESS_IMAGE);
159+
L.d(LOG_POSTPROCESS_IMAGE, memoryCacheKey);
163160
bmp = options.getPostProcessor().process(bmp);
164161
if (bmp == null) {
165162
L.e(ERROR_POST_PROCESSOR_NULL, memoryCacheKey);
@@ -175,7 +172,6 @@ public void run() {
175172
}
176173

177174
DisplayBitmapTask displayBitmapTask = new DisplayBitmapTask(bmp, imageLoadingInfo, engine, loadedFrom);
178-
displayBitmapTask.setLoggingEnabled(writeLogs);
179175
runTask(displayBitmapTask, syncLoading, handler, engine);
180176
}
181177

@@ -185,14 +181,14 @@ private boolean waitIfPaused() {
185181
if (pause.get()) {
186182
synchronized (engine.getPauseLock()) {
187183
if (pause.get()) {
188-
log(LOG_WAITING_FOR_RESUME);
184+
L.d(LOG_WAITING_FOR_RESUME, memoryCacheKey);
189185
try {
190186
engine.getPauseLock().wait();
191187
} catch (InterruptedException e) {
192188
L.e(LOG_TASK_INTERRUPTED, memoryCacheKey);
193189
return true;
194190
}
195-
log(LOG_RESUME_AFTER_PAUSE);
191+
L.d(LOG_RESUME_AFTER_PAUSE, memoryCacheKey);
196192
}
197193
}
198194
}
@@ -202,7 +198,7 @@ private boolean waitIfPaused() {
202198
/** @return <b>true</b> - if task should be interrupted; <b>false</b> - otherwise */
203199
private boolean delayIfNeed() {
204200
if (options.shouldDelayBeforeLoading()) {
205-
log(LOG_DELAY_BEFORE_LOADING, options.getDelayBeforeLoading(), memoryCacheKey);
201+
L.d(LOG_DELAY_BEFORE_LOADING, options.getDelayBeforeLoading(), memoryCacheKey);
206202
try {
207203
Thread.sleep(options.getDelayBeforeLoading());
208204
} catch (InterruptedException e) {
@@ -219,14 +215,14 @@ private Bitmap tryLoadBitmap() throws TaskCancelledException {
219215
try {
220216
File imageFile = configuration.diskCache.get(uri);
221217
if (imageFile != null && imageFile.exists()) {
222-
log(LOG_LOAD_IMAGE_FROM_DISK_CACHE);
218+
L.d(LOG_LOAD_IMAGE_FROM_DISK_CACHE, memoryCacheKey);
223219
loadedFrom = LoadedFrom.DISC_CACHE;
224220

225221
checkTaskNotActual();
226222
bitmap = decodeImage(Scheme.FILE.wrap(imageFile.getAbsolutePath()));
227223
}
228224
if (bitmap == null || bitmap.getWidth() <= 0 || bitmap.getHeight() <= 0) {
229-
log(LOG_LOAD_IMAGE_FROM_NETWORK);
225+
L.d(LOG_LOAD_IMAGE_FROM_NETWORK, memoryCacheKey);
230226
loadedFrom = LoadedFrom.NETWORK;
231227

232228
String imageUriForDecoding = uri;
@@ -270,7 +266,7 @@ private Bitmap decodeImage(String imageUri) throws IOException {
270266

271267
/** @return <b>true</b> - if image was downloaded successfully; <b>false</b> - otherwise */
272268
private boolean tryCacheImageOnDisk() throws TaskCancelledException {
273-
log(LOG_CACHE_IMAGE_ON_DISK);
269+
L.d(LOG_CACHE_IMAGE_ON_DISK, memoryCacheKey);
274270

275271
boolean loaded;
276272
try {
@@ -279,7 +275,7 @@ private boolean tryCacheImageOnDisk() throws TaskCancelledException {
279275
int width = configuration.maxImageWidthForDiskCache;
280276
int height = configuration.maxImageHeightForDiskCache;
281277
if (width > 0 || height > 0) {
282-
log(LOG_RESIZE_CACHED_IMAGE_FILE);
278+
L.d(LOG_RESIZE_CACHED_IMAGE_FILE, memoryCacheKey);
283279
resizeAndSaveImage(width, height); // TODO : process boolean result
284280
}
285281
}
@@ -309,7 +305,7 @@ private boolean resizeAndSaveImage(int maxWidth, int maxHeight) throws IOExcepti
309305
getDownloader(), specialOptions);
310306
Bitmap bmp = decoder.decode(decodingInfo);
311307
if (bmp != null && configuration.processorForDiskCache != null) {
312-
log(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK);
308+
L.d(LOG_PROCESS_IMAGE_BEFORE_CACHE_ON_DISK, memoryCacheKey);
313309
bmp = configuration.processorForDiskCache.process(bmp);
314310
if (bmp == null) {
315311
L.e(ERROR_PROCESSOR_FOR_DISK_CACHE_NULL, memoryCacheKey);
@@ -408,7 +404,7 @@ private void checkViewCollected() throws TaskCancelledException {
408404
/** @return <b>true</b> - if target ImageAware is collected by GC; <b>false</b> - otherwise */
409405
private boolean isViewCollected() {
410406
if (imageAware.isCollected()) {
411-
log(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED);
407+
L.d(LOG_TASK_CANCELLED_IMAGEAWARE_COLLECTED, memoryCacheKey);
412408
return true;
413409
}
414410
return false;
@@ -428,7 +424,7 @@ private boolean isViewReused() {
428424
// If ImageAware is reused for another task then current task should be cancelled.
429425
boolean imageAwareWasReused = !memoryCacheKey.equals(currentCacheKey);
430426
if (imageAwareWasReused) {
431-
log(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED);
427+
L.d(LOG_TASK_CANCELLED_IMAGEAWARE_REUSED, memoryCacheKey);
432428
return true;
433429
}
434430
return false;
@@ -444,7 +440,7 @@ private void checkTaskInterrupted() throws TaskCancelledException {
444440
/** @return <b>true</b> - if current task was interrupted; <b>false</b> - otherwise */
445441
private boolean isTaskInterrupted() {
446442
if (Thread.interrupted()) {
447-
log(LOG_TASK_INTERRUPTED);
443+
L.d(LOG_TASK_INTERRUPTED, memoryCacheKey);
448444
return true;
449445
}
450446
return false;
@@ -454,14 +450,6 @@ String getLoadingUri() {
454450
return uri;
455451
}
456452

457-
private void log(String message) {
458-
if (writeLogs) L.d(message, memoryCacheKey);
459-
}
460-
461-
private void log(String message, Object... args) {
462-
if (writeLogs) L.d(message, args);
463-
}
464-
465453
static void runTask(Runnable r, boolean sync, Handler handler, ImageLoaderEngine engine) {
466454
if (sync) {
467455
r.run();

library/src/com/nostra13/universalimageloader/core/ProcessAndDisplayImageTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,12 @@ public ProcessAndDisplayImageTask(ImageLoaderEngine engine, Bitmap bitmap, Image
4848

4949
@Override
5050
public void run() {
51-
if (engine.configuration.writeLogs) L.d(LOG_POSTPROCESS_IMAGE, imageLoadingInfo.memoryCacheKey);
51+
L.d(LOG_POSTPROCESS_IMAGE, imageLoadingInfo.memoryCacheKey);
5252

5353
BitmapProcessor processor = imageLoadingInfo.options.getPostProcessor();
5454
Bitmap processedBitmap = processor.process(bitmap);
5555
DisplayBitmapTask displayBitmapTask = new DisplayBitmapTask(processedBitmap, imageLoadingInfo, engine,
5656
LoadedFrom.MEMORY_CACHE);
57-
displayBitmapTask.setLoggingEnabled(engine.configuration.writeLogs);
5857
LoadAndDisplayImageTask.runTask(displayBitmapTask, imageLoadingInfo.options.isSyncLoading(), handler, engine);
5958
}
6059
}

0 commit comments

Comments
 (0)