Browse Source

added minimal logging

Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
main json_1.0.1
Stephan Richter 2 months ago
parent
commit
29faafbbdb
  1. 2
      de.srsoftware.configuration.json/build.gradle.kts
  2. 10
      de.srsoftware.configuration.json/src/main/java/de/srsoftware/configuration/JsonConfig.java

2
de.srsoftware.configuration.json/build.gradle.kts

@ -14,7 +14,7 @@ object Meta { @@ -14,7 +14,7 @@ object Meta {
val COMPONENT_TYPE = "java" // "java" or "versionCatalog"
val GROUP = "de.srsoftware"
val ARTIFACT_ID = "configuration.json"
val VERSION = "1.0.0"
val VERSION = "1.0.1"
val PUBLISHING_TYPE = "AUTOMATIC" // USER_MANAGED or AUTOMATIC
val SHA_ALGORITHMS = listOf("SHA-256", "SHA-512") // sha256 and sha512 are supported but not mandatory. Only sha1 is mandatory but it is supported by default.
val DESC = "SRSoftware Configuration: Json-based Implementation"

10
de.srsoftware.configuration.json/src/main/java/de/srsoftware/configuration/JsonConfig.java

@ -2,6 +2,9 @@ @@ -2,6 +2,9 @@
package de.srsoftware.configuration;
import static java.lang.System.Logger;
import static java.lang.System.getLogger;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@ -9,14 +12,14 @@ import java.nio.file.Files; @@ -9,14 +12,14 @@ import java.nio.file.Files;
import java.util.*;
import org.json.JSONObject;
/**
* A Configuration implementation, that stores its data in a json file.
* Altered json &lt;em&gt;is not automatically saved&gt;/em&lt; after editing!
*/
public class JsonConfig implements Configuration {
private final File file;
private final JSONObject json;
private static final Logger LOG = getLogger(JsonConfig.class.getSimpleName());
private final File file;
private final JSONObject json;
/**
* Create a new JsonConfig instance using the passed file for storage
@ -29,6 +32,7 @@ public class JsonConfig implements Configuration { @@ -29,6 +32,7 @@ public class JsonConfig implements Configuration {
if (!file.exists()) try (var out = new FileWriter(file)) {
out.write("{}\n");
}
LOG.log(Logger.Level.INFO, "Loading json config file from {0}…", file);
json = new JSONObject(Files.readString(file.toPath()));
}

Loading…
Cancel
Save