Skip to content
Snippets Groups Projects
Commit efa43cd0 authored by Joe Littlejohn's avatar Joe Littlejohn
Browse files

Merge pull request #16 from matthewadams/master

Made log file & encoding configurable
parents bdd97fff d94d1e63
No related branches found
No related tags found
No related merge requests found
...@@ -133,6 +133,18 @@ public class StartEmbeddedMongoMojo extends AbstractMojo { ...@@ -133,6 +133,18 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
*/ */
private String logging; private String logging;
/**
* @parameter expression="${embedmongo.logFile}"
* @since 0.1.7
*/
private String logFile = Loggers.DEFAULT_LOG_FILE_NAME;
/**
* @parameter expression="${embedmongo.logFileEncoding}"
* @since 0.1.7
*/
private String logFileEncoding = Loggers.DEFAULT_LOG_FILE_ENCODING;
/** /**
* The proxy user to be used when downloading MongoDB * The proxy user to be used when downloading MongoDB
* *
...@@ -204,7 +216,7 @@ public class StartEmbeddedMongoMojo extends AbstractMojo { ...@@ -204,7 +216,7 @@ public class StartEmbeddedMongoMojo extends AbstractMojo {
case CONSOLE: case CONSOLE:
return Loggers.console(); return Loggers.console();
case FILE: case FILE:
return Loggers.file(); return Loggers.file(logFile, logFileEncoding);
case NONE: case NONE:
return Loggers.none(); return Loggers.none();
default: default:
......
...@@ -24,13 +24,26 @@ import de.flapdoodle.embed.process.io.IStreamProcessor; ...@@ -24,13 +24,26 @@ import de.flapdoodle.embed.process.io.IStreamProcessor;
public class FileOutputStreamProcessor implements IStreamProcessor { public class FileOutputStreamProcessor implements IStreamProcessor {
private static OutputStreamWriter stream; private static OutputStreamWriter stream;
private String logFile;
private String encoding;
public FileOutputStreamProcessor(String logFile) {
this(logFile, Loggers.DEFAULT_LOG_FILE_ENCODING);
}
public FileOutputStreamProcessor(String logFile, String encoding) {
setLogFile(logFile);
setEncoding(encoding);
}
@Override @Override
public synchronized void process(String block) { public synchronized void process(String block) {
try { try {
if (stream == null) { if (stream == null) {
stream = new OutputStreamWriter(new FileOutputStream("embedmongo.log"), "utf-8"); stream = new OutputStreamWriter(new FileOutputStream(logFile), encoding);
} }
stream.write(block); stream.write(block);
...@@ -45,4 +58,18 @@ public class FileOutputStreamProcessor implements IStreamProcessor { ...@@ -45,4 +58,18 @@ public class FileOutputStreamProcessor implements IStreamProcessor {
public void onProcessed() { public void onProcessed() {
process("\n"); process("\n");
} }
public void setLogFile(String logFile) {
if (logFile == null || logFile.trim().length() == 0) {
throw new IllegalArgumentException("no logFile given");
}
this.logFile = logFile;
}
public void setEncoding(String encoding) {
if (encoding == null || encoding.trim().length() == 0) {
throw new IllegalArgumentException("no encoding given");
}
this.encoding = encoding;
}
} }
...@@ -25,8 +25,11 @@ public class Loggers { ...@@ -25,8 +25,11 @@ public class Loggers {
FILE, CONSOLE, NONE FILE, CONSOLE, NONE
} }
public static ProcessOutput file() { public static final String DEFAULT_LOG_FILE_NAME = "embedmongo.log";
FileOutputStreamProcessor file = new FileOutputStreamProcessor(); public static final String DEFAULT_LOG_FILE_ENCODING = "utf-8";
public static ProcessOutput file(String logFile, String encoding) {
FileOutputStreamProcessor file = new FileOutputStreamProcessor(logFile, encoding);
return new ProcessOutput( return new ProcessOutput(
new NamedOutputStreamProcessor("[mongod output]", file), new NamedOutputStreamProcessor("[mongod output]", file),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment