Added data logger with a bit of implementation in ObjectManager

This commit is contained in:
Obique
2015-05-21 23:37:15 -05:00
parent d9e55ae365
commit d63bf34e0b
5 changed files with 83 additions and 14 deletions
+18 -1
View File
@@ -27,6 +27,9 @@
***********************************************************************************/
package resources.control;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import network.OutboundPacketService;
import network.packets.Packet;
import resources.config.ConfigFile;
@@ -42,6 +45,7 @@ import resources.services.Config;
public class Service implements IntentReceiver {
private static final OutboundPacketService outboundPacketService = new OutboundPacketService();
private static final DateFormat LOG_FORMAT = new SimpleDateFormat("dd-mm-yy HH:mm:ss.SSS");
/**
* Initializes this service. If the service returns false on this method
@@ -160,6 +164,19 @@ public class Service implements IntentReceiver {
return DataManager.getInstance().getLocalDatabase();
}
/**
* Logs the string to the server log file, formatted to display the time,
* tag and message.
* @param tag the tag to use for the log
* @param str the format string for the log
* @param args the string format arguments, if specified
*/
public synchronized final void log(String tag, String str, Object ... args) {
if (getConfig(ConfigFile.PRIMARY).getBoolean("DEBUG-SERVICES", true)) {
String logStr = String.format(str, args);
String log = String.format("%s [%s]: %s", LOG_FORMAT.format(System.currentTimeMillis()), tag, logStr);
DataManager.getInstance().log(log);
}
}
}