[DEV] update logs
This commit is contained in:
parent
e0509ee9bf
commit
45d6fb07ac
@ -35,7 +35,7 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addLibrary(final String libName, final Class<?> classHandle, String basePath) {
|
public static void addLibrary(final String libName, final Class<?> classHandle, String basePath) {
|
||||||
Log.info("Add library reference: lib=" + libName + " ==> " + classHandle.getCanonicalName() + " base path=" + basePath);
|
Log.info("Add library reference: lib={} ==> {} base path={}", libName, classHandle.getCanonicalName(), basePath);
|
||||||
if (basePath == null || basePath.isEmpty()) {
|
if (basePath == null || basePath.isEmpty()) {
|
||||||
basePath = "/";
|
basePath = "/";
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ public class Uri {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
private static List<String> getResourceFiles(final Class<?> clazz, final String path) throws IOException {
|
private static List<String> getResourceFiles(final Class<?> clazz, final String path) throws IOException {
|
||||||
List<String> filenames = new ArrayList<>();
|
final List<String> filenames = new ArrayList<>();
|
||||||
|
|
||||||
try (InputStream in = clazz.getResourceAsStream(path); BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
|
try (InputStream in = clazz.getResourceAsStream(path); BufferedReader br = new BufferedReader(new InputStreamReader(in))) {
|
||||||
String resource;
|
String resource;
|
||||||
@ -108,23 +108,23 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static InputStream getStream(final Uri uri) {
|
public static InputStream getStream(final Uri uri) {
|
||||||
Log.warning("Load resource: " + uri);
|
Log.warning("Load resource: {}", uri);
|
||||||
String offsetGroup = "";
|
String offsetGroup = "";
|
||||||
if (uri.group != null) {
|
if (uri.group != null) {
|
||||||
if (uri.group.equals("FILE")) {
|
if (uri.group.equals("FILE")) {
|
||||||
Log.warning("Load resource direct file: " + uri);
|
Log.warning("Load resource direct file: {}", uri);
|
||||||
try {
|
try {
|
||||||
return new FileInputStream(new File(uri.getPath()));
|
return new FileInputStream(new File(uri.getPath()));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (final FileNotFoundException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.warning(" find group: " + uri.group);
|
Log.warning(" find group: {}", uri.group);
|
||||||
final String ret = Uri.genericMap.get(uri.group);
|
final String ret = Uri.genericMap.get(uri.group);
|
||||||
if (ret != null) {
|
if (ret != null) {
|
||||||
Log.warning(" ==> " + ret);
|
Log.warning(" ==> {}", ret);
|
||||||
offsetGroup = ret;
|
offsetGroup = ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -134,12 +134,12 @@ public class Uri {
|
|||||||
} else {
|
} else {
|
||||||
String tmpPath = Uri.applicationBasePath + offsetGroup + uri.path;
|
String tmpPath = Uri.applicationBasePath + offsetGroup + uri.path;
|
||||||
tmpPath = tmpPath.replace("//", "/");
|
tmpPath = tmpPath.replace("//", "/");
|
||||||
Log.info("(appl) Try to load '" + tmpPath + "' in " + Uri.applicationClass.getCanonicalName());// + " ==> " + applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath());
|
Log.info("(appl) Try to load '{}' in {}", tmpPath, Uri.applicationClass.getCanonicalName());// + " ==> " + applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath());
|
||||||
URL realFileName = Uri.applicationClass.getClassLoader().getResource(tmpPath);
|
final URL realFileName = Uri.applicationClass.getClassLoader().getResource(tmpPath);
|
||||||
if (realFileName != null) {
|
if (realFileName != null) {
|
||||||
Log.info("(appl) >>> " + realFileName.getFile());
|
Log.info("(appl) >>> {}", realFileName.getFile());
|
||||||
} else {
|
} else {
|
||||||
Log.info("(appl) ??? base folder: " + Uri.applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath() + Uri.applicationBasePath + offsetGroup + uri.path);
|
Log.info("(appl) ??? base folder: {}", Uri.applicationClass.getProtectionDomain().getCodeSource().getLocation().getPath() + Uri.applicationBasePath + offsetGroup + uri.path);
|
||||||
}
|
}
|
||||||
out = Uri.applicationClass.getResourceAsStream(tmpPath);
|
out = Uri.applicationClass.getResourceAsStream(tmpPath);
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ public class Uri {
|
|||||||
Log.warning(" !! No library specified");
|
Log.warning(" !! No library specified");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
LibraryElement libraryElement = Uri.libraries.get(uri.properties.get("lib"));
|
final LibraryElement libraryElement = Uri.libraries.get(uri.properties.get("lib"));
|
||||||
if (libraryElement == null) {
|
if (libraryElement == null) {
|
||||||
Log.warning(" Can not get element in library");
|
Log.warning(" Can not get element in library");
|
||||||
return null;
|
return null;
|
||||||
@ -172,12 +172,12 @@ public class Uri {
|
|||||||
// }
|
// }
|
||||||
String tmpPath = libraryElement.basePath + offsetGroup + uri.path;
|
String tmpPath = libraryElement.basePath + offsetGroup + uri.path;
|
||||||
tmpPath = tmpPath.replace("//", "/");
|
tmpPath = tmpPath.replace("//", "/");
|
||||||
Log.info("(lib) Try to load '" + tmpPath + "' in " + libraryElement.klass.getCanonicalName());
|
Log.info("(lib) Try to load '{}' in {}", tmpPath, libraryElement.klass.getCanonicalName());
|
||||||
URL realFileName = libraryElement.klass.getClassLoader().getResource(tmpPath);
|
final URL realFileName = libraryElement.klass.getClassLoader().getResource(tmpPath);
|
||||||
if (realFileName != null) {
|
if (realFileName != null) {
|
||||||
Log.info("(lib) >>> " + realFileName.getFile());
|
Log.info("(lib) >>> {}", realFileName.getFile());
|
||||||
} else {
|
} else {
|
||||||
Log.info("(lib) ??? base folder: " + libraryElement.klass.getProtectionDomain().getCodeSource().getLocation().getPath() + libraryElement.basePath + offsetGroup + uri.path);
|
Log.info("(lib) ??? base folder: {}", libraryElement.klass.getProtectionDomain().getCodeSource().getLocation().getPath() + libraryElement.basePath + offsetGroup + uri.path);
|
||||||
}
|
}
|
||||||
out = libraryElement.klass.getResourceAsStream(tmpPath);
|
out = libraryElement.klass.getResourceAsStream(tmpPath);
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
@ -204,7 +204,7 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setApplication(final Class<?> classHandle, String basePath) {
|
public static void setApplication(final Class<?> classHandle, String basePath) {
|
||||||
Log.info("Set application reference : " + classHandle.getCanonicalName() + " base path=" + basePath);
|
Log.info("Set application reference : {} base path={}", classHandle.getCanonicalName(), basePath);
|
||||||
Uri.applicationClass = classHandle;
|
Uri.applicationClass = classHandle;
|
||||||
if (basePath == null || basePath.isEmpty()) {
|
if (basePath == null || basePath.isEmpty()) {
|
||||||
basePath = "/";
|
basePath = "/";
|
||||||
@ -219,7 +219,7 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setGroup(final String groupName, String basePath) {
|
public static void setGroup(final String groupName, String basePath) {
|
||||||
Log.info("Set Group : " + groupName + " base path=" + basePath);
|
Log.info("Set Group : {} base path={}", groupName, basePath);
|
||||||
if (basePath == null || basePath.isEmpty()) {
|
if (basePath == null || basePath.isEmpty()) {
|
||||||
basePath = "/";
|
basePath = "/";
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ public class Uri {
|
|||||||
public static Uri valueOf(String value) {
|
public static Uri valueOf(String value) {
|
||||||
String group = null;
|
String group = null;
|
||||||
String path = null;
|
String path = null;
|
||||||
Map<String, String> prop = new HashMap<>();
|
final Map<String, String> prop = new HashMap<>();
|
||||||
if (value.contains(":")) {
|
if (value.contains(":")) {
|
||||||
final String[] ret = value.split(":", 2);
|
final String[] ret = value.split(":", 2);
|
||||||
group = ret[0].toUpperCase();
|
group = ret[0].toUpperCase();
|
||||||
@ -240,7 +240,7 @@ public class Uri {
|
|||||||
} else {
|
} else {
|
||||||
group = "DATA";
|
group = "DATA";
|
||||||
}
|
}
|
||||||
int index = value.indexOf('?');
|
final int index = value.indexOf('?');
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
final String valuesMetadata = value.substring(index + 1);
|
final String valuesMetadata = value.substring(index + 1);
|
||||||
final String[] elementMetaData = valuesMetadata.split("&");
|
final String[] elementMetaData = valuesMetadata.split("&");
|
||||||
@ -266,17 +266,17 @@ public class Uri {
|
|||||||
public static void writeAll(final Uri uri, final String data) throws IOException {
|
public static void writeAll(final Uri uri, final String data) throws IOException {
|
||||||
BufferedWriter out = null;
|
BufferedWriter out = null;
|
||||||
try {
|
try {
|
||||||
FileWriter fstream = new FileWriter(uri.getPath(), false); //true tells to append data.
|
final FileWriter fstream = new FileWriter(uri.getPath(), false); //true tells to append data.
|
||||||
out = new BufferedWriter(fstream);
|
out = new BufferedWriter(fstream);
|
||||||
out.write(data);
|
out.write(data);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
Log.error("Error: " + e.getMessage());
|
Log.error("Error: {}", e.getMessage());
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
} finally {
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
try {
|
try {
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
Log.error("Error: ", e);
|
Log.error("Error: ", e);
|
||||||
throw e;
|
throw e;
|
||||||
@ -288,16 +288,16 @@ public class Uri {
|
|||||||
public static void writeAllAppend(final Uri uri, final String data) {
|
public static void writeAllAppend(final Uri uri, final String data) {
|
||||||
BufferedWriter out = null;
|
BufferedWriter out = null;
|
||||||
try {
|
try {
|
||||||
FileWriter fstream = new FileWriter(uri.getPath(), true); //true tells to append data.
|
final FileWriter fstream = new FileWriter(uri.getPath(), true); //true tells to append data.
|
||||||
out = new BufferedWriter(fstream);
|
out = new BufferedWriter(fstream);
|
||||||
out.write(data);
|
out.write(data);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
Log.error("Error: " + e.getMessage());
|
Log.error("Error: " + e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (out != null) {
|
if (out != null) {
|
||||||
try {
|
try {
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
Log.error("Error: ", e);
|
Log.error("Error: ", e);
|
||||||
}
|
}
|
||||||
@ -348,13 +348,13 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean exist() {
|
public boolean exist() {
|
||||||
InputStream stream = Uri.getStream(this);
|
final InputStream stream = Uri.getStream(this);
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -383,7 +383,7 @@ public class Uri {
|
|||||||
* @return simple filename
|
* @return simple filename
|
||||||
*/
|
*/
|
||||||
public String getFileNameNoExt() {
|
public String getFileNameNoExt() {
|
||||||
String ext = getExtention();
|
final String ext = getExtention();
|
||||||
return this.path.substring(this.path.lastIndexOf("/") + 1, this.path.length() - ext.length() + 1);
|
return this.path.substring(this.path.lastIndexOf("/") + 1, this.path.length() - ext.length() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +392,7 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Uri getParent() {
|
public Uri getParent() {
|
||||||
String path = this.path.substring(0, this.path.lastIndexOf("/"));
|
final String path = this.path.substring(0, this.path.lastIndexOf("/"));
|
||||||
return new Uri(getGroup(), path, this.properties);
|
return new Uri(getGroup(), path, this.properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,21 +433,21 @@ public class Uri {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder out = new StringBuilder();
|
final StringBuilder out = new StringBuilder();
|
||||||
if (this.group != null) {
|
if (this.group != null) {
|
||||||
out.append(this.group);
|
out.append(this.group);
|
||||||
out.append(":");
|
out.append(":");
|
||||||
}
|
}
|
||||||
out.append(this.path);
|
out.append(this.path);
|
||||||
boolean first = true;
|
final boolean first = true;
|
||||||
for (Map.Entry<String, String> entry : this.properties.entrySet()) {
|
for (final Map.Entry<String, String> entry : this.properties.entrySet()) {
|
||||||
if (first) {
|
if (first) {
|
||||||
out.append("?");
|
out.append("?");
|
||||||
} else {
|
} else {
|
||||||
out.append("&");
|
out.append("&");
|
||||||
}
|
}
|
||||||
out.append(entry.getKey());
|
out.append(entry.getKey());
|
||||||
String value = entry.getValue();
|
final String value = entry.getValue();
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
out.append("=");
|
out.append("=");
|
||||||
out.append(value);
|
out.append(value);
|
||||||
@ -462,7 +462,7 @@ public class Uri {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Uri withLib(final String lib) {
|
public Uri withLib(final String lib) {
|
||||||
Map<String, String> tmp = new HashMap<>(this.properties);
|
final Map<String, String> tmp = new HashMap<>(this.properties);
|
||||||
tmp.put("lib", lib);
|
tmp.put("lib", lib);
|
||||||
return new Uri(this.group, this.path, tmp);
|
return new Uri(this.group, this.path, tmp);
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import io.scenarium.logger.LogLevel;
|
|||||||
import io.scenarium.logger.Logger;
|
import io.scenarium.logger.Logger;
|
||||||
|
|
||||||
public class Log {
|
public class Log {
|
||||||
|
private static final boolean FORCE_ALL = false;
|
||||||
private static final String LIB_NAME = "etk";
|
private static final String LIB_NAME = "etk";
|
||||||
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
private static final String LIB_NAME_DRAW = Logger.getDrawableName(LIB_NAME);
|
||||||
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
private static final boolean PRINT_CRITICAL = Logger.getNeedPrint(LIB_NAME, LogLevel.CRITICAL);
|
||||||
@ -15,58 +16,58 @@ public class Log {
|
|||||||
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
private static final boolean PRINT_TODO = Logger.getNeedPrint(LIB_NAME, LogLevel.TODO);
|
||||||
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
private static final boolean PRINT_PRINT = Logger.getNeedPrint(LIB_NAME, LogLevel.PRINT);
|
||||||
|
|
||||||
public static void critical(final String data) {
|
public static void critical(final Exception e, final String data) {
|
||||||
if (PRINT_CRITICAL) {
|
|
||||||
Logger.critical(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void debug(final String data) {
|
|
||||||
if (PRINT_DEBUG) {
|
|
||||||
Logger.debug(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void error(final String data) {
|
|
||||||
if (PRINT_ERROR) {
|
|
||||||
Logger.error(LIB_NAME_DRAW, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void error(final String data, final Exception e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (PRINT_ERROR) {
|
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||||
Logger.error(LIB_NAME_DRAW, data);
|
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(final String data) {
|
public static void critical(final String data, final Object... objects) {
|
||||||
if (PRINT_INFO) {
|
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||||
Logger.info(LIB_NAME_DRAW, data);
|
Logger.critical(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void print(final String data) {
|
public static void debug(final String data, final Object... objects) {
|
||||||
if (PRINT_PRINT) {
|
if (PRINT_DEBUG || FORCE_ALL) {
|
||||||
Logger.print(LIB_NAME_DRAW, data);
|
Logger.debug(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void todo(final String data) {
|
public static void error(final String data, final Object... objects) {
|
||||||
if (PRINT_TODO) {
|
if (PRINT_ERROR || FORCE_ALL) {
|
||||||
Logger.todo(LIB_NAME_DRAW, data);
|
Logger.error(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(final String data) {
|
public static void info(final String data, final Object... objects) {
|
||||||
if (PRINT_VERBOSE) {
|
if (PRINT_INFO || FORCE_ALL) {
|
||||||
Logger.verbose(LIB_NAME_DRAW, data);
|
Logger.info(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(final String data) {
|
public static void print(final String data, final Object... objects) {
|
||||||
if (PRINT_WARNING) {
|
if (PRINT_PRINT || FORCE_ALL) {
|
||||||
Logger.warning(LIB_NAME_DRAW, data);
|
Logger.print(LIB_NAME_DRAW, data, objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void todo(final String data, final Object... objects) {
|
||||||
|
if (PRINT_TODO || FORCE_ALL) {
|
||||||
|
Logger.todo(LIB_NAME_DRAW, data, objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void verbose(final String data, final Object... objects) {
|
||||||
|
if (PRINT_VERBOSE || FORCE_ALL) {
|
||||||
|
Logger.verbose(LIB_NAME_DRAW, data, objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(final String data, final Object... objects) {
|
||||||
|
if (PRINT_WARNING || FORCE_ALL) {
|
||||||
|
Logger.warning(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user