package us.codecraft.webmagic.scheduler;

import com.google.common.collect.Sets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Task;

import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Base Scheduler with duplicated urls removed locally.
 *
 * @author code4crafter@gmail.com
 * @since 0.5.0
 */
public abstract class LocalDuplicatedRemovedScheduler implements Scheduler {

    protected Logger logger = LoggerFactory.getLogger(getClass());

    private Set<String> urls = Sets.newSetFromMap(new ConcurrentHashMap<String, Boolean>());

    @Override
    public void push(Request request, Task task) {
        logger.debug("push to queue " + request.getUrl());
        if (request.getExtra(Request.CYCLE_TRIED_TIMES) != null || urls.add(request.getUrl())) {
            pushWhenNoDuplicate(request, task);
        }
    }

    protected abstract void pushWhenNoDuplicate(Request request, Task task);
}

@@ -716,28 +716,34 @@
 ger.
-debug(%22push to queue
+trace(%22get a candidate url
  %22 +
@@ -855,24 +855,84 @@
 etUrl())) %7B%0A
+        %09logger.debug(%22push to queue %22 + request.getUrl());%0A
             

Modify the log levels of LocalDuplicatedRemovedScheduler.java The old version will print a debug level log each time the push method is called. So sometimes, when a html page have multiple links for the same page, the debug log will appears more than once. Also, when we meet a duplicate URL, it will also print a log, which will be confusing. I change the level of it to trace. And each time a URL is really push into queue, print a debug level log.