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

ImageJ2Options: add log level selection #137

Merged
merged 4 commits into from
Jan 1, 2017
Merged
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
71 changes: 65 additions & 6 deletions src/main/java/net/imagej/legacy/ImageJ2Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,22 @@ public class ImageJ2Options extends OptionsPlugin implements Interactive {
* This system leverages the <a href="http://imagej.net/SCIFIO">SCIFIO</a>
* library to open image files.
*/
@Parameter(
label = "Use SCIFIO when opening files (BETA!)",
description = "<html>Whether to use ImageJ2's file I/O mechanism when "
+ "opening files.<br>Image files will be opened using the SCIFIO library "
+ "(SCientific Image<br>Format Input and Output), which provides truly "
+ "extensible support for<br>reading and writing image file formats.",
@Parameter(label = "Use SCIFIO when opening files (BETA!)",
description = "<html>Whether to use ImageJ2's file I/O mechanism when " +
"opening files.<br>Image files will be opened using the SCIFIO library " +
"(SCientific Image<br>Format Input and Output), which provides truly " +
"extensible support for<br>reading and writing image file formats.",
callback = "run")
private boolean sciJavaIO = false;

@Parameter(label = "SciJava log level",
description = "<html>Log level for SciJava",
initializer = "initializeLogLevel", //
callback = "setLogLevel", //
choices = { "ERROR", "WARN", "INFO", "DEBUG", "TRACE" }, //
persist = false)
private String logLevel;

@Parameter(label = "What is ImageJ2?", persist = false, callback = "help")
private Button help;

Expand Down Expand Up @@ -201,4 +208,56 @@ private void help() {
System.err.println(message);
}
}

@SuppressWarnings("unused")
private void initializeLogLevel() {
logLevel = parseLogLevel(log.getLevel());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This is supposed to work... 😛

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not. That's why I have asked..

}

@SuppressWarnings("unused")
private void setLogLevel() {
log.setLevel(parseLogLevel(logLevel));
}

/**
* Parses a log level from a {@code String}.
*
* @param level
* @return the {@code int} associated with the level
*/
private int parseLogLevel(final String level) {
switch (level) {
case "NONE": return LogService.NONE;
case "ERROR": return LogService.ERROR;
case "WARN": return LogService.WARN;
case "INFO": return LogService.INFO;
case "DEBUG": return LogService.DEBUG;
case "TRACE": return LogService.TRACE;
}

return LogService.WARN;
}

/**
* Parses a log level from an {@code int}.
*
* @param level
* @return the {@code String} associated with the level
*/
private String parseLogLevel(int level) {
if (level == LogService.NONE)
return "NONE";
if (level == LogService.ERROR)
return "ERROR";
if (level == LogService.WARN)
return "WARN";
if (level == LogService.INFO)
return "INFO";
if (level == LogService.DEBUG)
return "DEBUG";
if (level == LogService.TRACE)
return "TRACE";

return "" + level;
}
}