* updated Log class to set Log level
This commit is contained in:
parent
4563b8d407
commit
96e000fccf
13
.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_6_1.xml
generated
Normal file
13
.idea/libraries/Maven__com_google_protobuf_protobuf_java_3_6_1.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: com.google.protobuf:protobuf-java:3.6.1">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/protobuf/protobuf-java/3.6.1/protobuf-java-3.6.1.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/protobuf/protobuf-java/3.6.1/protobuf-java-3.6.1-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/com/google/protobuf/protobuf-java/3.6.1/protobuf-java-3.6.1-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
13
.idea/libraries/Maven__mysql_mysql_connector_java_8_0_18.xml
generated
Normal file
13
.idea/libraries/Maven__mysql_mysql_connector_java_8_0_18.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: mysql:mysql-connector-java:8.0.18">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/8.0.18/mysql-connector-java-8.0.18.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/8.0.18/mysql-connector-java-8.0.18-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/mysql/mysql-connector-java/8.0.18/mysql-connector-java-8.0.18-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
13
.idea/libraries/Maven__org_eclipse_paho_org_eclipse_paho_client_mqttv3_1_2_2.xml
generated
Normal file
13
.idea/libraries/Maven__org_eclipse_paho_org_eclipse_paho_client_mqttv3_1_2_2.xml
generated
Normal file
@ -0,0 +1,13 @@
|
||||
<component name="libraryTable">
|
||||
<library name="Maven: org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2">
|
||||
<CLASSES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/paho/org.eclipse.paho.client.mqttv3/1.2.2/org.eclipse.paho.client.mqttv3-1.2.2.jar!/" />
|
||||
</CLASSES>
|
||||
<JAVADOC>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/paho/org.eclipse.paho.client.mqttv3/1.2.2/org.eclipse.paho.client.mqttv3-1.2.2-javadoc.jar!/" />
|
||||
</JAVADOC>
|
||||
<SOURCES>
|
||||
<root url="jar://$MAVEN_REPOSITORY$/org/eclipse/paho/org.eclipse.paho.client.mqttv3/1.2.2/org.eclipse.paho.client.mqttv3-1.2.2-sources.jar!/" />
|
||||
</SOURCES>
|
||||
</library>
|
||||
</component>
|
@ -17,5 +17,8 @@
|
||||
<orderEntry type="library" name="Maven: org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.18" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
|
||||
<orderEntry type="library" name="Maven: org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.2" level="project" />
|
||||
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.18" level="project" />
|
||||
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.6.1" level="project" />
|
||||
</component>
|
||||
</module>
|
@ -24,57 +24,65 @@ public class Log {
|
||||
public static final int MESSAGE = 2;
|
||||
public static final int DEBUG = 1;
|
||||
|
||||
private static int Loglevel = 0;
|
||||
|
||||
private static ArrayList<String> colors = new ArrayList<String>(Arrays.asList("", "DEBUG", "MESSAGE", "INFO", "WARNING", "ERROR", "CRITICAL_ERROR"));
|
||||
|
||||
public static void criticalerror(Object msg) {
|
||||
log(msg, CRITICAL_ERROR);
|
||||
if (Loglevel <= CRITICAL_ERROR)
|
||||
log(msg, CRITICAL_ERROR);
|
||||
}
|
||||
|
||||
public static void error(Object msg) {
|
||||
log(msg, ERROR);
|
||||
if (Loglevel <= ERROR)
|
||||
log(msg, ERROR);
|
||||
}
|
||||
|
||||
public static void warning(Object msg) {
|
||||
log(msg, WARNING);
|
||||
if (Loglevel <= WARNING)
|
||||
log(msg, WARNING);
|
||||
}
|
||||
|
||||
public static void info(Object msg) {
|
||||
log(msg, INFO);
|
||||
if (Loglevel <= INFO)
|
||||
log(msg, INFO);
|
||||
}
|
||||
|
||||
public static void message(Object msg) {
|
||||
log(msg, MESSAGE);
|
||||
if (Loglevel <= MESSAGE)
|
||||
log(msg, MESSAGE);
|
||||
}
|
||||
|
||||
public static void debug(Object msg) {
|
||||
log(msg, DEBUG);
|
||||
if (Loglevel <= DEBUG)
|
||||
log(msg, DEBUG);
|
||||
}
|
||||
|
||||
|
||||
public static void log(Object msg, int level) {
|
||||
boolean iswindows = System.getProperty("os.name").contains("Windows");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (!iswindows){
|
||||
switch (level) {
|
||||
case INFO:
|
||||
builder.append(ANSI_CYAN);
|
||||
break;
|
||||
case WARNING:
|
||||
builder.append(ANSI_YELLOW);
|
||||
break;
|
||||
case ERROR:
|
||||
builder.append(ANSI_RED);
|
||||
break;
|
||||
case CRITICAL_ERROR:
|
||||
builder.append(ANSI_RED);
|
||||
break;
|
||||
case MESSAGE:
|
||||
builder.append(ANSI_WHITE);
|
||||
break;
|
||||
case DEBUG:
|
||||
builder.append(ANSI_BLUE);
|
||||
break;
|
||||
}
|
||||
if (!iswindows) {
|
||||
switch (level) {
|
||||
case INFO:
|
||||
builder.append(ANSI_CYAN);
|
||||
break;
|
||||
case WARNING:
|
||||
builder.append(ANSI_YELLOW);
|
||||
break;
|
||||
case ERROR:
|
||||
builder.append(ANSI_RED);
|
||||
break;
|
||||
case CRITICAL_ERROR:
|
||||
builder.append(ANSI_RED);
|
||||
break;
|
||||
case MESSAGE:
|
||||
builder.append(ANSI_WHITE);
|
||||
break;
|
||||
case DEBUG:
|
||||
builder.append(ANSI_BLUE);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
builder.append("[");
|
||||
@ -89,14 +97,14 @@ public class Log {
|
||||
builder.append(colors.get(level));
|
||||
builder.append("]");
|
||||
|
||||
if (!iswindows){
|
||||
if (!iswindows) {
|
||||
builder.append(ANSI_WHITE);
|
||||
}
|
||||
|
||||
builder.append(" - ");
|
||||
builder.append(msg.toString());
|
||||
|
||||
if (!iswindows){
|
||||
if (!iswindows) {
|
||||
builder.append(ANSI_RESET);
|
||||
}
|
||||
System.out.println(builder.toString());
|
||||
@ -108,4 +116,8 @@ public class Log {
|
||||
return date_format.format(resultdate);
|
||||
}
|
||||
|
||||
public static void setLevel(int level) {
|
||||
Loglevel = level;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import java.io.IOException;
|
||||
public class main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
Log.setLevel(Log.DEBUG);
|
||||
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
|
||||
|
Loading…
Reference in New Issue
Block a user