Skip to content

Commit

Permalink
LogFile fixed and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Nov 1, 2017
1 parent bc0c95a commit d7a5fe5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -11,3 +11,4 @@ bin/
*/secring.gpg


nb-configuration.xml
10 changes: 4 additions & 6 deletions src/main/java/co/comdor/LogFile.java
Expand Up @@ -27,8 +27,6 @@

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.apache.log4j.FileAppender;
import org.apache.log4j.Level;
import org.apache.log4j.PatternLayout;
Expand Down Expand Up @@ -60,7 +58,7 @@ public final class LogFile implements Log {
* @throws IOException If the log file cannot be created/configured.
*/
public LogFile(final String dir, final String id) throws IOException {
this.id = id;
this.id = id;
this.setup(dir);
}

Expand Down Expand Up @@ -89,12 +87,12 @@ private void setup(final String dir) throws IOException {

final String logFilePath;
if(dir == null) {
logFilePath = "/" + this.id;
logFilePath = "/" + this.id + ".log";
} else {
if(dir.endsWith("/")) {
logFilePath = dir + this.id;
logFilePath = dir + this.id + ".log";
} else {
logFilePath = dir + "/" + this.id;
logFilePath = dir + "/" + this.id + ".log";
}
}

Expand Down
15 changes: 5 additions & 10 deletions src/test/java/co/comdor/LogFileTestCase.java
Expand Up @@ -26,22 +26,17 @@
package co.comdor;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Test;

/**
* Tests for {@link LogFile}
* Tests for {@link LogFile}.
* The tests in this class will create *.log files
* under /src/test/resources/log_tests. These are ignored by git, via .gitignore,
* so just don't mind them. We do not try to delete them in a cleanup method in order
* to avoid access rights or file lock problems.
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.1
Expand Down

0 comments on commit d7a5fe5

Please sign in to comment.