= Updated utils and logging subsystem formatting

This commit is contained in:
Matthew Cech
2019-06-19 22:14:13 -07:00
parent 5e531a19b7
commit 06317a4528
58 changed files with 205 additions and 202 deletions
+2 -2
View File
@@ -38,7 +38,7 @@ public class BaseKeyValueFile
File f = new File(filename);
if(f.isFile() && f.canRead())
{
String content = FileUtils.ReadContent(f).trim();
String content = FileUtils.readContent(f).trim();
String[] lines = content.split("" + pairSeparator);
for(int i = 0; i < lines.length; ++i)
@@ -84,7 +84,7 @@ public class BaseKeyValueFile
}
catch (IOException e)
{
GlobalLog.Error(LogFilter.Core, "Issue writing file " + filename + ": " + e.getMessage());
GlobalLog.error(LogFilter.Core, "Issue writing file " + filename + ": " + e.getMessage());
}
}
}
+6 -6
View File
@@ -30,9 +30,9 @@ public abstract class BaseLocFile
protected TaggedPairStore stringStore;
// Logging
private void log(String str) { GlobalLog.Log(LogFilter.Strings, str); }
private void warn(String str) { GlobalLog.Warn(LogFilter.Strings, str); }
private void error(String str) { GlobalLog.Error(LogFilter.Strings, str); }
private void log(String str) { GlobalLog.log(LogFilter.Strings, str); }
private void warn(String str) { GlobalLog.warn(LogFilter.Strings, str); }
private void error(String str) { GlobalLog.error(LogFilter.Strings, str); }
// File monitoring
protected FileMonitor fileMonitor;
@@ -49,7 +49,7 @@ public abstract class BaseLocFile
{
synchronized(stringStore)
{
fileMonitor.Update(this::onFileChange);
fileMonitor.update(this::onFileChange);
}
}
@@ -80,7 +80,7 @@ public abstract class BaseLocFile
String filename = path.getFileName().toString();
if(filename.contains(".java"))
{
String contents = FileUtils.ReadContent(path);
String contents = FileUtils.readContent(path);
String[] split = contents.split(functionName);
// Identify all localizer function calls
@@ -203,7 +203,7 @@ public abstract class BaseLocFile
public void scrapeAll()
{
ArrayList<LocInfo> localizeList = new ArrayList<LocInfo>();
FileUtils.AcquireAllFiles(KittySourceDirectory).forEach((path) -> tryStripSpecified(path, localizeList));
FileUtils.acquireAllFiles(KittySourceDirectory).forEach((path) -> tryStripSpecified(path, localizeList));
for(LocInfo toStub : localizeList)
stringStore.addKeyValue(toStub.file, toStub.phrase, toStub.phrase);
+1 -1
View File
@@ -24,7 +24,7 @@ public class CharacterManager
}
else
{
GlobalLog.Error(LogFilter.Core, "Attempted to create a second CharacterManager singleton!");
GlobalLog.error(LogFilter.Core, "Attempted to create a second CharacterManager singleton!");
return;
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ public abstract class Command
private void reject(KittyUser user, String reason)
{
GlobalLog.Warn(LogFilter.Command, this.getClass().getSimpleName() + " from " + user.name + " rejected due to command's " + reason);
GlobalLog.warn(LogFilter.Command, this.getClass().getSimpleName() + " from " + user.name + " rejected due to command's " + reason);
}
// Determine if we're exclusive enough for this command and
+2 -2
View File
@@ -30,7 +30,7 @@ public class CommandEnabler extends BaseKeyValueFile
super(name);
// Create/Init variables
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
enabledMap = new HashMap<>();
keyList = new ArrayList<>();
@@ -68,7 +68,7 @@ public class CommandEnabler extends BaseKeyValueFile
if(enabledMap.putIfAbsent(command, defaultEnabledState) == null)
{
GlobalLog.Log(LogFilter.Strings, "Identified new toggleable raw command: " + command);
GlobalLog.log(LogFilter.Strings, "Identified new toggleable raw command: " + command);
keyList.add(command);
}
}
+3 -3
View File
@@ -59,11 +59,11 @@ public class CommandManager
if(old != null)
{
GlobalLog.Warn(LogFilter.Core, "Writing over a command with the key " + key);
GlobalLog.warn(LogFilter.Core, "Writing over a command with the key " + key);
return;
}
GlobalLog.Log(LogFilter.Core, "Command registered under key " + key);
GlobalLog.log(LogFilter.Core, "Command registered under key " + key);
}
// Registers a command under multiple names!
@@ -91,7 +91,7 @@ public class CommandManager
}
else
{
GlobalLog.Warn(LogFilter.Command, "User " + user.name + " tried to invoke command that doesn't exist: " + input.key);
GlobalLog.warn(LogFilter.Command, "User " + user.name + " tried to invoke command that doesn't exist: " + input.key);
return false;
}
}
+12 -12
View File
@@ -38,14 +38,14 @@ public class DatabaseDriverKeyValue
public void ensureTableExists(String tableName, String keyName, String valueName)
{
// Require a global table if it doesn't exist already
driver.ExecuteStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
driver.executeStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
}
// Set up and create a table in the database
public boolean connect()
{
driver = new JDBCDriverSQLite();
if(driver.Connect() == false)
if(driver.connect() == false)
{
return false;
}
@@ -59,7 +59,7 @@ public class DatabaseDriverKeyValue
// The key will be created if it doesn't exist and the value specified will be stored.
public void createSetKey(String key, String value)
{
GlobalLog.Log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
GlobalLog.log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
if(hasKey(key))
{
@@ -74,7 +74,7 @@ public class DatabaseDriverKeyValue
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
public String createGetKey(String key)
{
GlobalLog.Log(LogFilter.Database, "CreateGetKey: " + key);
GlobalLog.log(LogFilter.Database, "CreateGetKey: " + key);
if(hasKey(key))
{
@@ -92,15 +92,15 @@ public class DatabaseDriverKeyValue
private void updateKey(String key, String value)
{
String command = "UPDATE " + tableName + " SET " + valueColumnName + " = ? WHERE " + keyColumnName + " = ?";
boolean status = driver.ExecuteStatement(JDBCStatementType.Update, command, new String[] { value, key });
GlobalLog.Log(LogFilter.Database, "UpdateKey status: " + status);
boolean status = driver.executeStatement(JDBCStatementType.Update, command, new String[] { value, key });
GlobalLog.log(LogFilter.Database, "UpdateKey status: " + status);
}
// Protoype updating for seeing if a key exists
private boolean hasKey(String key)
{
String command = "SELECT COUNT(1) as count FROM " + tableName + " WHERE " + keyColumnName + " = ?";
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
ResultSet set = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { key });
String out = resultAsString(set, "count");
return out.charAt(0) == '1';
}
@@ -109,7 +109,7 @@ public class DatabaseDriverKeyValue
private String getKey(String key)
{
String command = "SELECT " + valueColumnName + " as searchedKey FROM " + tableName +" WHERE " + keyColumnName + " = ?";
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
ResultSet set = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { key });
return resultAsString(set, "searchedKey");
}
@@ -117,15 +117,15 @@ public class DatabaseDriverKeyValue
private void createKey(String key, String value)
{
String command = "INSERT INTO " + tableName + " (GlobalKey, GlobalValue) VALUES (?, ?)";
boolean status = driver.ExecuteStatement(JDBCStatementType.Insert, command, new String[] { key, value });
GlobalLog.Log(LogFilter.Database, "CreateKey status: " + status);
boolean status = driver.executeStatement(JDBCStatementType.Insert, command, new String[] { key, value });
GlobalLog.log(LogFilter.Database, "CreateKey status: " + status);
}
// Get all keys containing a substring
public List<String> getKeysWith(String keySubstring)
{
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
ResultSet result = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
ResultSet result = driver.executeReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
List<String> keys = new ArrayList<String>();
@@ -165,7 +165,7 @@ public class DatabaseDriverKeyValue
}
catch (SQLException e)
{
GlobalLog.Error(LogFilter.Database, e.toString());
GlobalLog.error(LogFilter.Database, e.toString());
return null;
}
}
+4 -4
View File
@@ -35,7 +35,7 @@ public class DatabaseManager
// Constructor to enforce singleton.
public DatabaseManager()
{
GlobalLog.Log(LogFilter.Database, "Creating database manager");
GlobalLog.log(LogFilter.Database, "Creating database manager");
if(instance == null)
{
@@ -43,7 +43,7 @@ public class DatabaseManager
}
else
{
GlobalLog.Error(LogFilter.Database, "Attempted to register a second DataBase manager!");
GlobalLog.error(LogFilter.Database, "Attempted to register a second DataBase manager!");
return;
}
@@ -59,13 +59,13 @@ public class DatabaseManager
// Connect data sets
if(globalDataDriver.connect() == false)
{
GlobalLog.Error("Global database failed to connect. Without this DB, this bot can not run.");
GlobalLog.error("Global database failed to connect. Without this DB, this bot can not run.");
System.exit(1);
}
if(characterDataDriver.connect() == false)
{
GlobalLog.Error("Character database failed to connect. Without this DB, this bot can not run.");
GlobalLog.error("Character database failed to connect. Without this DB, this bot can not run.");
System.exit(1);
}
}
+2 -2
View File
@@ -19,7 +19,7 @@ public class LocCommands extends BaseLocFile
{
super(fileName, function);
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
if(instance == null)
{
@@ -33,7 +33,7 @@ public class LocCommands extends BaseLocFile
}
else
{
GlobalLog.Error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
}
}
+2 -2
View File
@@ -18,7 +18,7 @@ public class LocStrings extends BaseLocFile
{
super(fileName, function);
GlobalLog.Log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
if(instance == null)
{
@@ -32,7 +32,7 @@ public class LocStrings extends BaseLocFile
}
else
{
GlobalLog.Error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
}
}
+1 -1
View File
@@ -99,7 +99,7 @@ public class ObjectBuilderFactory
}
catch(InterruptedException ie)
{
GlobalLog.Error(LogFilter.Core, "Issue during object builder lazy initialization."
GlobalLog.error(LogFilter.Core, "Issue during object builder lazy initialization."
+ " The factory was not initialized, and kitty will not be able to continue functionally.");
}
}
+1 -1
View File
@@ -23,7 +23,7 @@ public class RPManager
}
else
{
GlobalLog.Error(LogFilter.Core, "Attempted to create a second RP Manager!");
GlobalLog.error(LogFilter.Core, "Attempted to create a second RP Manager!");
return;
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ public class Stats
}
else
{
GlobalLog.Error(LogFilter.Core, "Attempted to create a second Stats singleton!");
GlobalLog.error(LogFilter.Core, "Attempted to create a second Stats singleton!");
return;
}
+1 -1
View File
@@ -19,7 +19,7 @@ public class BenchmarkInput
return;
raw = raw.trim();
int whitespacePos = StringUtils.FindFirstWhitespace(raw);
int whitespacePos = StringUtils.findFirstWhitespace(raw);
if(whitespacePos == -1)
{
+3 -3
View File
@@ -5,7 +5,7 @@ import utils.GlobalLog;
//Logging shim
public class BenchmarkLog
{
public static void log(String str) { GlobalLog.Log("[Benchmark] " + str); }
public static void warn(String str) { GlobalLog.Warn("[Benchmark] " + str); }
public static void error(String str) { GlobalLog.Error(" [Benchmark] " + str); }
public static void log(String str) { GlobalLog.log("[Benchmark] " + str); }
public static void warn(String str) { GlobalLog.warn("[Benchmark] " + str); }
public static void error(String str) { GlobalLog.error(" [Benchmark] " + str); }
}
+4 -4
View File
@@ -35,7 +35,7 @@ public class BenchmarkManager
rebuildLookup();
BenchmarkLog.log("Took " + (Instant.now().toEpochMilli() - start) + " ms to load " + raw.size() + " entries from " + directoryMonitor.GetCurrentFiles().size() + " file" + (raw.size() > 1 ? "s" : ""));
BenchmarkLog.log("Took " + (Instant.now().toEpochMilli() - start) + " ms to load " + raw.size() + " entries from " + directoryMonitor.getCurrentFiles().size() + " file" + (raw.size() > 1 ? "s" : ""));
}
// Rebuilds the files being monitored
@@ -50,14 +50,14 @@ public class BenchmarkManager
synchronized(directoryMonitor)
{
files = directoryMonitor.GetCurrentFiles();
files = directoryMonitor.getCurrentFiles();
}
if(files != null)
{
for(MonitoredFile mf : files)
{
String contents = FileUtils.ReadContent(mf.path);
String contents = FileUtils.readContent(mf.path);
String[] lines = contents.split(lineDelimiter);
for(int i = 1; i < lines.length; ++i)
@@ -169,7 +169,7 @@ public class BenchmarkManager
public void update()
{
needsUpdate = false;
directoryMonitor.Update(this::onRescan, this::onRescan, this::onRescan);
directoryMonitor.update(this::onRescan, this::onRescan, this::onRescan);
if(needsUpdate)
rebuildLookup();
+3 -3
View File
@@ -5,7 +5,7 @@ import utils.LogFilter;
public class PluginLog
{
public static void log(String s) { GlobalLog.Log(LogFilter.Plugin, s); }
public static void warn(String s) { GlobalLog.Warn(LogFilter.Plugin, s); }
public static void error(String s) { GlobalLog.Error(LogFilter.Plugin, s); }
public static void log(String s) { GlobalLog.log(LogFilter.Plugin, s); }
public static void warn(String s) { GlobalLog.warn(LogFilter.Plugin, s); }
public static void error(String s) { GlobalLog.error(LogFilter.Plugin, s); }
}
+1 -1
View File
@@ -18,7 +18,7 @@ public class RPGInput
return;
raw = raw.trim();
int whitespacePos = StringUtils.FindFirstWhitespace(raw);
int whitespacePos = StringUtils.findFirstWhitespace(raw);
if(whitespacePos == -1)
{
+1 -1
View File
@@ -7,6 +7,6 @@ public class RPGLog
{
public static void log(String toWrite)
{
GlobalLog.Log(LogFilter.Command, "[RPG] " + toWrite);
GlobalLog.log(LogFilter.Command, "[RPG] " + toWrite);
}
}