improved data encapsulation
This commit is contained in:
lukas-heiligenbrunner
2020-01-23 18:32:29 +01:00
parent cdb03ada81
commit 10058b24a7
6 changed files with 113 additions and 21 deletions

View File

@ -8,37 +8,58 @@ import java.util.Date;
import java.util.Properties;
public class Info {
private static String version="not init";
private static String builddate="not init";
private static String starttime="not init";
private static String version = "not init";
private static String builddate = "not init";
private static String starttime = "not init";
/**
* get Software Version (defined in gradle build file)
*
* @return Version as string
*/
public static String getVersion() {
return version;
}
/**
* get Software build date
*
* @return Date as string
*/
public static String getBuilddate() {
return builddate;
}
/**
* get Server start time
*
* @return start time
*/
public static String getStarttime() {
return starttime;
}
public static void init(){
/**
* initialize the version and builddate variables
*/
public static void init() {
starttime = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
Properties prop = new Properties();
try {
URL url = Info.class.getResource("/version.properties");
prop.load(url.openStream());
version=(String)prop.get("version");
builddate=(String)prop.get("buildtime");
version = (String) prop.get("version");
builddate = (String) prop.get("buildtime");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void getMemoryUsage(){
/**
* print memory utilization
*/
public static void getMemoryUsage() {
Runtime runtime = Runtime.getRuntime();
NumberFormat format = NumberFormat.getInstance();

View File

@ -28,37 +28,72 @@ public class Log {
private static ArrayList<String> colors = new ArrayList<String>(Arrays.asList("", "DEBUG", "MESSAGE", "INFO", "WARNING", "ERROR", "CRITICAL_ERROR"));
/**
* Log critical Error
*
* @param msg message
*/
public static void criticalerror(Object msg) {
if (Loglevel <= CRITICAL_ERROR)
log(msg, CRITICAL_ERROR);
}
/**
* Log basic Error
*
* @param msg message
*/
public static void error(Object msg) {
if (Loglevel <= ERROR)
log(msg, ERROR);
}
/**
* Log warning
*
* @param msg message
*/
public static void warning(Object msg) {
if (Loglevel <= WARNING)
log(msg, WARNING);
}
/**
* Log info
*
* @param msg message
*/
public static void info(Object msg) {
if (Loglevel <= INFO)
log(msg, INFO);
}
/**
* Log basic message
*
* @param msg message
*/
public static void message(Object msg) {
if (Loglevel <= MESSAGE)
log(msg, MESSAGE);
}
/**
* Log debug Message
*
* @param msg message
*/
public static void debug(Object msg) {
if (Loglevel <= DEBUG)
log(msg, DEBUG);
}
/**
* Log as defined
*
* @param msg message
* @param level Loglevel --> static vals defined
*/
public static void log(Object msg, int level) {
boolean iswindows = System.getProperty("os.name").contains("Windows");
StringBuilder builder = new StringBuilder();
@ -116,6 +151,12 @@ public class Log {
return date_format.format(resultdate);
}
/**
* define Loglevel call on startup or at runtime
* default: 0[DEBUG] --> Max logging
*
* @param level Loglevel --> static vals defined
*/
public static void setLevel(int level) {
Loglevel = level;
}