Das ist meine Projektstruktur: Warum log4j2 hat nicht funktioniert?
build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
jar {
baseName = 'dcv_crawler_engine'
version = '1.0.0-SNAPSHOT'
}
repositories {
jcenter()
}
dependencies {
compile 'edu.uci.ics:crawler4j:4.2'
compile 'org.apache.logging.log4j:log4j-api:2.5'
testCompile 'junit:junit:4.12'
testCompile 'edu.uci.ics:crawler4j:4.2'
testCompile 'org.apache.logging.log4j:log4j-api:2.5'
}
EntryPoint.java
package com.dcvsolution.crawler;
import edu.uci.ics.crawler4j.crawler.CrawlConfig;
import edu.uci.ics.crawler4j.crawler.CrawlController;
import edu.uci.ics.crawler4j.fetcher.PageFetcher;
import edu.uci.ics.crawler4j.robotstxt.RobotstxtConfig;
import edu.uci.ics.crawler4j.robotstxt.RobotstxtServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class EntryPoint {
/**
* For logging.
*/
private static final Logger logger = LogManager.getLogger();
public static void main(String[] args) throws Exception {
logger.info("Bat dau crawling.");
String crawlStorageFolder = "/data/crawl/root";
int numberOfCrawlers = 7;
CrawlConfig config = new CrawlConfig();
config.setCrawlStorageFolder(crawlStorageFolder);
/*
* Instantiate the controller for this crawl.
*/
PageFetcher pageFetcher = new PageFetcher(config);
RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);
/*
* For each crawl, you need to add some seed urls. These are the first
* URLs that are fetched and then the crawler starts following links
* which are found in these pages
*/
controller.addSeed("http://www.ics.uci.edu/~lopes/");
controller.addSeed("http://www.ics.uci.edu/~welling/");
controller.addSeed("http://www.ics.uci.edu/");
/*
* Start the crawl. This is a blocking operation, meaning that your code
* will reach the line after this only when crawling is finished.
*/
logger.info("Bat dau crawling.");
controller.start(MyCrawler.class, numberOfCrawlers);
}
}
MyCrawler.java
log4j2.properties
log4j.rootLogger=DEBUG, stdout
mir Hilfe warum log4j nicht funktioniert?
Das ist mein ganzes Projekt https://gitlab.com/Donhu/DCV_crawler_engine/tree/master –