diff --git a/Lab5Client/src/main/java/client/Lab5Client.java b/Lab5Client/src/main/java/client/Lab5Client.java index 20e45ff..b4b36fc 100644 --- a/Lab5Client/src/main/java/client/Lab5Client.java +++ b/Lab5Client/src/main/java/client/Lab5Client.java @@ -4,17 +4,19 @@ import client.commandline.CommandLineHandler; import client.commandline.pdcommands.PeopleDatabaseCommands; import common.collection.Database; import common.collection.PeopleDatabase; +import common.util.UtilFunctions; import java.util.logging.Logger; public class Lab5Client { + public final static Logger LOGGER = UtilFunctions.getLogger(Lab5Client.class, "client"); + public static void main(String[] args) { - Logger logger = Logger.getLogger("Lab5Client"); CommandLineHandler cmd = CommandLineHandler.getInstance(); PeopleDatabaseCommands.registerDatabaseCommands(); - PeopleDatabase peopleDatabase = new PeopleDatabase(logger); + PeopleDatabase peopleDatabase = new PeopleDatabase(LOGGER); try { peopleDatabase.load(); } catch (Database.DatabaseLoadFailedException e) { diff --git a/Lab5Core/build/classes/java/main/common/parser/ConnectionProperties.class b/Lab5Core/build/classes/java/main/common/parser/ConnectionProperties.class index 5f86f73..c9b1f6c 100644 Binary files a/Lab5Core/build/classes/java/main/common/parser/ConnectionProperties.class and b/Lab5Core/build/classes/java/main/common/parser/ConnectionProperties.class differ diff --git a/Lab5Core/build/tmp/compileJava/previous-compilation-data.bin b/Lab5Core/build/tmp/compileJava/previous-compilation-data.bin index 88486f4..ad5ccec 100644 Binary files a/Lab5Core/build/tmp/compileJava/previous-compilation-data.bin and b/Lab5Core/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/Lab5Core/src/main/java/common/parser/ConnectionProperties.java b/Lab5Core/src/main/java/common/parser/ConnectionProperties.java index 3523f3f..90e4204 100644 --- a/Lab5Core/src/main/java/common/parser/ConnectionProperties.java +++ b/Lab5Core/src/main/java/common/parser/ConnectionProperties.java @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public final class ConnectionProperties { private static final Properties properties = new Properties(); - private static final Logger logger = Logger.getLogger("Lab5"); + private static final Logger logger = UtilFunctions.getLogger(ConnectionProperties.class, "common"); private static final int DEFAULT_PORT = 1234; private static final String DEFAULT_HOST = "localhost"; private static final String FILE_NAME = "connection.properties"; diff --git a/Lab5Core/src/main/java/common/util/UtilFunctions.java b/Lab5Core/src/main/java/common/util/UtilFunctions.java index 971b5fe..e420347 100644 --- a/Lab5Core/src/main/java/common/util/UtilFunctions.java +++ b/Lab5Core/src/main/java/common/util/UtilFunctions.java @@ -1,5 +1,11 @@ package common.util; +import java.util.Date; +import java.util.logging.ConsoleHandler; +import java.util.logging.LogRecord; +import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; + /** * Класс функций-утилит для избавления от повторяющихся участков кода и выноса их в методы для общего пользования */ @@ -54,4 +60,28 @@ public final class UtilFunctions { return null; } } + + public static Logger getLogger(Class clazz, String mainLoggerName) { + changeLoggerFormat(mainLoggerName); + return Logger.getLogger(clazz.getName()); + } + + private static void changeLoggerFormat(String mainLoggerName) { + Logger mainLogger = Logger.getLogger(mainLoggerName); + mainLogger.setUseParentHandlers(false); + ConsoleHandler handler = new ConsoleHandler(); + handler.setFormatter(new SimpleFormatter() { + private static final String format = "[%1$tF %1$tT] [%s] %3$s %n"; + + @Override + public synchronized String format(LogRecord record) { + return String.format(format, + new Date(record.getMillis()), + record.getLevel().getLocalizedName(), + record.getMessage() + ); + } + }); + mainLogger.addHandler(handler); + } } diff --git a/Lab5Server/build/classes/java/main/server/Lab5Server.class b/Lab5Server/build/classes/java/main/server/Lab5Server.class index 8dbd6ee..725fef6 100644 Binary files a/Lab5Server/build/classes/java/main/server/Lab5Server.class and b/Lab5Server/build/classes/java/main/server/Lab5Server.class differ diff --git a/Lab5Server/build/libs/Lab5Server-2.0.jar b/Lab5Server/build/libs/Lab5Server-2.0.jar deleted file mode 100644 index e2ebd8f..0000000 Binary files a/Lab5Server/build/libs/Lab5Server-2.0.jar and /dev/null differ diff --git a/Lab5Server/build/libs/lab5.xml b/Lab5Server/build/libs/lab5.xml index e69de29..a87551c 100644 --- a/Lab5Server/build/libs/lab5.xml +++ b/Lab5Server/build/libs/lab5.xml @@ -0,0 +1,94 @@ + + + + Gena + + 5.0 + 6.0 + + 2022-05-10 + 124 + 231323232 + BLACK + JAPAN + + 2.0 + 3.0 + 4 + Tokyo + + + + Gena + + 5.0 + 6.0 + + 2022-05-10 + 124 + 231323232 + BLACK + JAPAN + + 2.0 + 3.0 + 4 + Tokyo + + + + Sasha + + 3.4 + -2.0 + + 2022-05-10 + 175 + 2312131231 + BROWN + JAPAN + + 2323.0 + 443.0 + 2 + Tokyo + + + + Sasha + + 3.4 + -2.0 + + 2022-05-10 + 175 + 2312131231 + BROWN + JAPAN + + 2323.0 + 443.0 + 2 + Tokyo + + + + wasd + + 2.0 + 3.0 + + 2022-05-10 + 2 + 321312312 + BLACK + CHINA + + 2.0 + 2.0 + 2 + wasd + + + 2022-05-10 + diff --git a/Lab5Server/src/main/java/server/Lab5Server.java b/Lab5Server/src/main/java/server/Lab5Server.java index 844b2c7..51680d2 100644 --- a/Lab5Server/src/main/java/server/Lab5Server.java +++ b/Lab5Server/src/main/java/server/Lab5Server.java @@ -3,24 +3,25 @@ package server; import common.collection.Database; import common.collection.PeopleDatabase; import common.parser.ConnectionProperties; +import common.util.UtilFunctions; import server.net.UDPServer; import java.util.logging.Logger; public class Lab5Server { - public final static Logger logger = Logger.getLogger("Lab5Server"); - + public final static Logger LOGGER = UtilFunctions.getLogger(Lab5Server.class, "server"); public static void main(String[] args) { - PeopleDatabase peopleDatabase = new PeopleDatabase(logger); + LOGGER.info("wasd"); + PeopleDatabase peopleDatabase = new PeopleDatabase(LOGGER); try { peopleDatabase.load(); } catch (Database.DatabaseLoadFailedException e) { System.out.println(e.getMessage()); System.exit(-1); } - UDPServer udp = new UDPServer(ConnectionProperties.getPort(), logger); + UDPServer udp = new UDPServer(ConnectionProperties.getPort(), LOGGER); if (!udp.connect()) System.exit(-1); while (true) udp.receive(peopleDatabase);