Skip to content
Snippets Groups Projects
Commit f671efb6 authored by Hendrik Buschmeier's avatar Hendrik Buschmeier
Browse files

ipaaca-java: IpaacaLogger now sends/logs callers fully qualified name.

parent 72ff3421
No related branches found
No related tags found
No related merge requests found
...@@ -44,10 +44,10 @@ public class IpaacaLogger { ...@@ -44,10 +44,10 @@ public class IpaacaLogger {
private static OutputBuffer ob; private static OutputBuffer ob;
private static final Object lock = new Object(); private static final Object lock = new Object();
private static boolean SEND_IPAACA_LOGS = true; private static boolean SEND_IPAACA_LOGS = true;
private static String MODULE_NAME = "???"; private static String MODULE_NAME = "???";
private static void initializeOutBuffer() { private static void initializeOutBuffer() {
synchronized (lock) { synchronized (lock) {
if (ob == null) { if (ob == null) {
...@@ -55,13 +55,13 @@ public class IpaacaLogger { ...@@ -55,13 +55,13 @@ public class IpaacaLogger {
} }
} }
} }
public static void setModuleName(String name) { public static void setModuleName(String name) {
synchronized (lock) { synchronized (lock) {
MODULE_NAME = name; MODULE_NAME = name;
} }
} }
public static void setLogFileName(String fileName, String logMode) { public static void setLogFileName(String fileName, String logMode) {
initializeOutBuffer(); initializeOutBuffer();
LocalMessageIU msg = new LocalMessageIU("log"); LocalMessageIU msg = new LocalMessageIU("log");
...@@ -74,19 +74,19 @@ public class IpaacaLogger { ...@@ -74,19 +74,19 @@ public class IpaacaLogger {
logMode.equals("timestamp")) { logMode.equals("timestamp")) {
pl.put("existing", logMode); pl.put("existing", logMode);
} else { } else {
return; return;
} }
} }
ob.add(msg); ob.add(msg);
} }
public static void sendIpaacaLogs(boolean flag) { public static void sendIpaacaLogs(boolean flag) {
synchronized (lock) { synchronized (lock) {
SEND_IPAACA_LOGS = flag; SEND_IPAACA_LOGS = flag;
} }
} }
private static void logConsole(String level, String text, float now, String function, String thread) { private static void logConsole(String level, String text, float now, String function, String thread) {
for(String line: text.split("\n")) { for(String line: text.split("\n")) {
System.out.println("[" + level + "] " + thread + " " + function + " " + line); System.out.println("[" + level + "] " + thread + " " + function + " " + line);
...@@ -94,7 +94,7 @@ public class IpaacaLogger { ...@@ -94,7 +94,7 @@ public class IpaacaLogger {
thread = StringUtils.leftPad("", thread.length(), ' '); thread = StringUtils.leftPad("", thread.length(), ' ');
} }
} }
private static void logIpaaca(String level, String text, float now, String function, String thread) { private static void logIpaaca(String level, String text, float now, String function, String thread) {
initializeOutBuffer(); initializeOutBuffer();
LocalMessageIU msg = new LocalMessageIU("log"); LocalMessageIU msg = new LocalMessageIU("log");
...@@ -110,16 +110,20 @@ public class IpaacaLogger { ...@@ -110,16 +110,20 @@ public class IpaacaLogger {
ob.add(msg); ob.add(msg);
} }
private static String getCallerName() {
String function = Thread.currentThread().getStackTrace()[3].getClassName();
function += "." + Thread.currentThread().getStackTrace()[3].getMethodName();
return function;
}
public static void logError(String msg) { public static void logError(String msg) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logError(msg, System.currentTimeMillis(), getCallerName());
logError(msg, System.currentTimeMillis(), function);
} }
public static void logError(String msg, float now) { public static void logError(String msg, float now) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logError(msg, now, getCallerName());
logError(msg, now, function);
} }
private static void logError(String msg, float now, String callerName) { private static void logError(String msg, float now, String callerName) {
String thread = Thread.currentThread().getName(); String thread = Thread.currentThread().getName();
if (SEND_IPAACA_LOGS) { if (SEND_IPAACA_LOGS) {
...@@ -127,59 +131,56 @@ public class IpaacaLogger { ...@@ -127,59 +131,56 @@ public class IpaacaLogger {
} }
logConsole("ERROR", msg, now, callerName, thread); logConsole("ERROR", msg, now, callerName, thread);
} }
public static void logWarn(String msg) { public static void logWarn(String msg) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logWarn(msg, System.currentTimeMillis(), getCallerName());
logWarn(msg, System.currentTimeMillis(), function);
} }
public static void logWarn(String msg, float now) { public static void logWarn(String msg, float now) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logWarn(msg, now, getCallerName());
logWarn(msg, now, function);
} }
private static void logWarn(String msg, float now, String callerName) { private static void logWarn(String msg, float now, String callerName) {
String thread = Thread.currentThread().getName(); String thread = Thread.currentThread().getName();
if (SEND_IPAACA_LOGS) { if (SEND_IPAACA_LOGS) {
logIpaaca("WARN", msg, now, "???", thread); logIpaaca("WARN", msg, now, callerName, thread);
} }
logConsole("WARN", msg, now, "???", thread); logConsole("WARN", msg, now, callerName, thread);
} }
public static void logInfo(String msg) { public static void logInfo(String msg) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logInfo(msg, System.currentTimeMillis(), getCallerName());
logInfo(msg, System.currentTimeMillis(), function);
} }
public static void logInfo(String msg, float now) { public static void logInfo(String msg, float now) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logInfo(msg, now, getCallerName());
logInfo(msg, now, function);
} }
private static void logInfo(String msg, float now, String callerName) { private static void logInfo(String msg, float now, String callerName) {
String thread = Thread.currentThread().getName(); String thread = Thread.currentThread().getName();
if (SEND_IPAACA_LOGS) { if (SEND_IPAACA_LOGS) {
logIpaaca("INFO", msg, now, "???", thread); logIpaaca("INFO", msg, now, callerName, thread);
} }
logConsole("INFO", msg, now, "???", thread); logConsole("INFO", msg, now, callerName, thread);
} }
public static void logDebug(String msg) { public static void logDebug(String msg) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logDebug(msg, System.currentTimeMillis(), getCallerName());
logDebug(msg, System.currentTimeMillis(), function);
} }
public static void logDebug(String msg, float now) { public static void logDebug(String msg, float now) {
String function = Thread.currentThread().getStackTrace()[2].getMethodName(); logDebug(msg, now, getCallerName());
logDebug(msg, now, function);
} }
private static void logDebug(String msg, float now, String callerName) { private static void logDebug(String msg, float now, String callerName) {
String thread = Thread.currentThread().getName(); String thread = Thread.currentThread().getName();
if (SEND_IPAACA_LOGS) { if (SEND_IPAACA_LOGS) {
logIpaaca("DEBUG", msg, now, "???", thread); logIpaaca("DEBUG", msg, now, callerName, thread);
} }
logConsole("DEBUG", msg, now, "???", thread); logConsole("DEBUG", msg, now, callerName, thread);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment