Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat Don't log to stderr / stdout #344

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ easily comprehensible for the user and allows an intuitive manual correction if
The PAGE XML format is used to support integration into existing OCR workflows.
Evaluations showed that LAREX provides an efficient and flexible way to segment pages of early printed books.

Please feel free to visit the [tool homepage](https://www.uni-wuerzburg.de/zpd/larex/). A short user manual is available [here](http://www.is.informatik.uni-wuerzburg.de/fileadmin/10030600/Mitarbeiter/Reul_Christian/Projects/Layout_Analysis/LAREX_Quick_Guide.pdf).
Please feel free to visit the [tool homepage](https://www.uni-wuerzburg.de/zpd/larex/). A short user manual is available [here](https://www.ocr4all.org/guide/user-guide/workflow#segmentation-%E2%80%93-larex).

## Table of Contents
- [Installation](#installation)
Expand Down
20 changes: 18 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.uniwue</groupId>
Expand All @@ -16,6 +17,8 @@
<java.version>1.8</java.version>
<spring.version>5.2.22.RELEASE</spring.version>
<cglib.version>3.2.8</cglib.version>
<logback.version>1.5.6</logback.version>
<log.sl4j.version>2.1.0-alpha1</log.sl4j.version>
<junit.jupiter.version>5.6.2</junit.jupiter.version>
</properties>

Expand Down Expand Up @@ -59,6 +62,19 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${log.sl4j.version}</version>
</dependency>


<!-- Java Advanced Imaging (JAI) Image I/O Tools -->
<dependency>
<groupId>com.github.jai-imageio</groupId>
Expand Down Expand Up @@ -219,4 +235,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
12 changes: 9 additions & 3 deletions src/main/java/de/uniwue/web/config/LarexConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.*;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

Expand All @@ -15,6 +17,9 @@
@Scope("session")
public class LarexConfiguration {


static Logger logger = LoggerFactory.getLogger(LarexConfiguration.class);
private String configurationFile;
private Map<String, String> configurations;

/**
Expand All @@ -26,6 +31,7 @@ public class LarexConfiguration {
public void read(File configuration) {
configurations = new HashMap<>();
try {
this.configurationFile = configuration.getAbsolutePath();
FileReader input = new FileReader(configuration);
Properties prop = new Properties();
prop.load(input);
Expand All @@ -49,7 +55,7 @@ public void read(File configuration) {
*/
public String getSetting(String setting) {
if (!isInitiated()) {
System.err.println("Configuration file has not been read.");
logger.error("Configuration {} has not been read, return empty String", this.configurationFile);
return "";
}
return configurations.getOrDefault(setting, "");
Expand All @@ -64,7 +70,7 @@ public String getSetting(String setting) {
*/
public List<String> getListSetting(String setting) {
if (!isInitiated()) {
System.err.println("Configuration file has not been read.");
logger.error("Configuration {} has not been read, return empty List", this.configurationFile);
return new ArrayList<>();
}
if (configurations.containsKey(setting)) {
Expand All @@ -83,7 +89,7 @@ public List<String> getListSetting(String setting) {
*/
public void setSetting(String setting, String value) {
if (!isInitiated()) {
System.err.println("Configuration file has not been read.");
logger.error("Configuration {} has not been read, set empty Map", this.configurationFile);
this.configurations = new HashMap<String, String>();
}
configurations.put(setting, value);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/de/uniwue/web/controller/FileController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -62,6 +64,9 @@
@Controller
@Scope("session")
public class FileController {

static Logger logger = LoggerFactory.getLogger(FileController.class);

@Autowired
private ServletContext servletContext;
@Autowired
Expand Down Expand Up @@ -406,7 +411,8 @@ private File getXMLFilePath(String xmlName, Integer bookid){
if(!savedir.endsWith(File.separator)) { savedir += File.separator; }
return new File(savedir + xmlName);
} else {
System.err.println("Warning: Save dir is not set. File could not been saved.");
logger.error("Warning: Save dir {} not set. File {} could not been saved.",
savedir, xmlName);
}
} else {
return new File(fileManager.getLocalXmlMap().get(xmlName.split("\\.")[0]));
Expand Down
30 changes: 24 additions & 6 deletions src/main/java/de/uniwue/web/controller/LibraryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import de.uniwue.web.communication.DirectRequest;
import de.uniwue.web.config.Constants;
import de.uniwue.web.io.MetsReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
Expand All @@ -31,6 +34,11 @@
@Controller
@Scope("request")
public class LibraryController {

public static final String ENV_LAREX_VERSION = "LAREX_VERSION";

static Logger logger = LoggerFactory.getLogger(LibraryController.class);

@Autowired
private ServletContext servletContext;
@Autowired
Expand Down Expand Up @@ -80,15 +88,16 @@ public String home(Model model) throws IOException {
}
File bookPath = new File(fileManager.getLocalBooksPath());
if (!bookPath.isDirectory()) {
System.err.println("ERROR:\tSpecified bookpath is not a directory");
System.err.println("\tPlease set a valid bookpath in larex.properties");
logger.error("Specified bookpath {} no directory, Please set a valid bookpath in larex.properties!",
bookPath);
return "redirect:/500";
}
FileDatabase database = new FileDatabase(bookPath, config.getListSetting("imagefilter"), false);
Library lib = new Library(database);

model.addAttribute("library", lib);
model.addAttribute("timeStamp", timeStamp);
logger.info("Start LAREX using {}", this.fileManager.getConfigurationFile());
return "lib";
}

Expand Down Expand Up @@ -120,7 +129,7 @@ public String home(Model model) throws IOException {
case "flat":
return getFileMap(baseFolder.getAbsolutePath(), Constants.IMG_EXTENSIONS_DOTTED);
default:
System.out.println("Attempting to open empty directory");
logger.error("Attempt open empty directory {}", baseFolder.getAbsolutePath());
break;
}
} catch (Exception e) {
Expand Down Expand Up @@ -162,8 +171,13 @@ public String home(Model model) throws IOException {
*/
@RequestMapping(value = "library/getOldRequest", method = RequestMethod.POST, headers = "Accept=*/*")
public @ResponseBody DirectRequest getOldRequest() {
return fileManager.getDirectRequest();
DirectRequest directRequest = this.fileManager.getDirectRequest();
if (directRequest != null) {
logger.info("pass last {}", directRequest.getMetsPath());
}
return directRequest;
}

/**
* returns each imagePath in given directory
* respecting the SubExtensionFilter set in properties
Expand Down Expand Up @@ -219,7 +233,11 @@ public Map<String, List<String>> getFileMap(String baseFolder, List<String> extL
@RequestMapping(value ="library/getVersion" , method = RequestMethod.GET)
public @ResponseBody
String getVersion() {
String larex_version = System.getenv("LAREX_VERSION");
return larex_version.equals("") ? "UNKNOWN" : larex_version;
String larexVersion = System.getenv(ENV_LAREX_VERSION);
if (larexVersion == null) {
logger.warn("LAREX_VERSION unset in Env");
larexVersion = "";
}
return "".equals(larexVersion) ? "UNKNOWN" : larexVersion;
}
}
9 changes: 7 additions & 2 deletions src/main/java/de/uniwue/web/controller/ViewerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import de.uniwue.web.communication.DirectRequest;
import de.uniwue.web.io.MetsReader;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
Expand All @@ -35,6 +38,9 @@
@Controller
@Scope("request")
public class ViewerController {

static Logger logger = LoggerFactory.getLogger(ViewerController.class);

@Autowired
private ServletContext servletContext;
@Autowired
Expand Down Expand Up @@ -99,8 +105,7 @@ public String direct(Model model,
}
mimeMap = mapper.readValue(java.net.URLDecoder.decode(mimeMapString, StandardCharsets.UTF_8.name()), TreeMap.class);
} catch (IOException e) {
System.out.println(e.getMessage());
e.printStackTrace();
logger.error("Internal Exception {}", e.getMessage());
return "redirect:/error/500";
}
if(customFlag.equals("true") && !customFolder.endsWith(File.separator)) { customFolder += File.separator; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import de.uniwue.web.model.*;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

Expand All @@ -32,6 +34,8 @@
*/
public class LarexFacade {

static Logger logger = LoggerFactory.getLogger(LarexFacade.class);

/**
* Segment a page with the LAREX segmentation algorithm
*
Expand Down Expand Up @@ -82,11 +86,9 @@ public static PageAnnotations segmentPage(SegmentationSettings settings, int pag
MemoryCleaner.clean(original);
segmentationResult = result;
} else {
System.err.println(
"Warning: Image file could not be found. Segmentation result will be empty. File: " + imagePath);
logger.warn("Image file {} could not be found. Segmentation will be empty!", imagePath);
}
// TODO fix metadata insertion here instead of frontend (?)

page.setOrientation(orientation);
if (segmentationResult != null) {
segmentation = new PageAnnotations(page.getName(), page.getXmlName(), page.getWidth(), page.getHeight(),
Expand Down
Loading
Loading