Skip to content

Commit

Permalink
Add --log arg
Browse files Browse the repository at this point in the history
  • Loading branch information
voruti committed Mar 8, 2020
1 parent 235ec72 commit 598a62f
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/main/java/voruti/json2config/Starter.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Starter {

private static final String CLASS_NAME = Starter.class.getName();
private static final Logger LOGGER = Logger.getLogger(CLASS_NAME);
private static final Level LEVEL = Level.ALL;
private static final Level LEVEL = Level.WARNING;

private static final String DEFAULT_JSONFILE = "org.eclipse.smarthome.core.items.Item.json";
private static final String DEFAULT_ITEMSFILE = "json.items";
Expand All @@ -24,17 +24,7 @@ public static void main(String[] args) {
// logging:
System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF_%1$tT][%2$-40.40s][%4$13.13s]: %5$s%n");
LOGGER.getParent().setLevel(LEVEL);
LOGGER.getParent().getHandlers()[0].setLevel(Level.SEVERE);
FileHandler fileHandler;
try {
fileHandler = new FileHandler("latest.log");
} catch (SecurityException | IOException e) {
e.printStackTrace();
return;
}
fileHandler.setLevel(LEVEL);
fileHandler.setFormatter(new SimpleFormatter());
LOGGER.getParent().addHandler(fileHandler);
LOGGER.getParent().getHandlers()[0].setLevel(LEVEL);

// args evaluating:
boolean inNext = false;
Expand Down Expand Up @@ -70,6 +60,25 @@ public static void main(String[] args) {
}
break;

case "-l":
case "--log":
case "--enable-logging":
LOGGER.getParent().setLevel(Level.ALL);
LOGGER.getParent().getHandlers()[0].setLevel(Level.INFO);

// logging to file:
FileHandler fileHandler;
try {
fileHandler = new FileHandler("latest.log");
} catch (SecurityException | IOException e) {
e.printStackTrace();
return;
}
fileHandler.setLevel(Level.ALL);
fileHandler.setFormatter(new SimpleFormatter());
LOGGER.getParent().addHandler(fileHandler);
break;

default:
printHelp = true;
break loop;
Expand All @@ -78,7 +87,7 @@ public static void main(String[] args) {
}
if (printHelp) {
LOGGER.log(Level.WARNING, "Wrong parameter usage");
System.out.println("Usage: JSON2Config.jar [--in <path>] [--out <path>]");
System.out.println("Usage: JSON2Config.jar [--in <path>] [--out <path>] [--log]");
return;
}

Expand Down

0 comments on commit 598a62f

Please sign in to comment.