diff --git a/src/main/java/envoy/server/Startup.java b/src/main/java/envoy/server/Startup.java
index bdcac7d..c14423f 100755
--- a/src/main/java/envoy/server/Startup.java
+++ b/src/main/java/envoy/server/Startup.java
@@ -1,26 +1,22 @@
package envoy.server;
+import java.io.File;
import java.io.IOException;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
+import java.util.logging.Level;
import com.jenkov.nioserver.Server;
-import envoy.server.data.ConfigItem;
+import envoy.data.Config;
+import envoy.data.ConfigItem;
import envoy.server.data.PersistenceManager;
import envoy.server.net.ConnectionManager;
import envoy.server.net.ObjectMessageProcessor;
import envoy.server.net.ObjectMessageReader;
-import envoy.server.processors.ContactOperationProcessor;
-import envoy.server.processors.ContactsRequestEventProcessor;
-import envoy.server.processors.GroupCreationProcessor;
-import envoy.server.processors.GroupMessageProcessor;
-import envoy.server.processors.IDGeneratorRequestProcessor;
-import envoy.server.processors.LoginCredentialProcessor;
-import envoy.server.processors.MessageProcessor;
-import envoy.server.processors.MessageStatusChangeProcessor;
-import envoy.server.processors.ObjectProcessor;
-import envoy.server.processors.UserStatusChangeProcessor;
+import envoy.server.processors.*;
+import envoy.util.EnvoyLog;
/**
* Starts the server.
@@ -34,6 +30,25 @@ import envoy.server.processors.UserStatusChangeProcessor;
*/
public class Startup {
+ /**
+ * Initializes the logger with a new config instance.
+ *
+ * @since Envoy Server Standalone v0.1-beta
+ */
+ private static void initLogging() {
+ final var items = new HashMap>();
+ items.put("homeDirectory",
+ new ConfigItem<>("homeDirectory", "h", File::new, new File(System.getProperty("user.home"), ".envoy-server"), true));
+ items.put("fileLevelBarrier", new ConfigItem<>("fileLevelBarrier", "fb", Level::parse, Level.SEVERE, true));
+ items.put("consoleLevelBarrier", new ConfigItem<>("consoleLevelBarrier", "cb", Level::parse, Level.INFO, true));
+
+ final var config = new Config();
+ config.load(items);
+
+ EnvoyLog.initialize(config);
+ EnvoyLog.attach("");
+ }
+
/**
* Starts the server.
*
@@ -42,6 +57,8 @@ public class Startup {
* @since Envoy Server Standalone v0.1-alpha
*/
public static void main(String[] args) throws IOException {
+ initLogging();
+
Set> processors = new HashSet<>();
processors.add(new LoginCredentialProcessor());
processors.add(new MessageProcessor());
@@ -52,12 +69,12 @@ public class Startup {
processors.add(new IDGeneratorRequestProcessor());
processors.add(new ContactsRequestEventProcessor());
processors.add(new ContactOperationProcessor());
- Server server = new Server(8080, () -> new ObjectMessageReader(), new ObjectMessageProcessor(processors));
+ Server server = new Server(8080, ObjectMessageReader::new, new ObjectMessageProcessor(processors));
// Initialize the current message ID
PersistenceManager persistenceManager = PersistenceManager.getInstance();
if (persistenceManager.getConfigItemByID("currentMessageId") == null)
- persistenceManager.addConfigItem(new ConfigItem("currentMessageId", "0"));
+ persistenceManager.addConfigItem(new envoy.server.data.ConfigItem("currentMessageId", "0"));
server.start();
server.getSocketProcessor().registerSocketIdListener(ConnectionManager.getInstance());