updated logger formatting
This commit is contained in:
parent
2cce380f20
commit
80c0e0bb30
9 changed files with 134 additions and 7 deletions
|
@ -4,17 +4,19 @@ import client.commandline.CommandLineHandler;
|
||||||
import client.commandline.pdcommands.PeopleDatabaseCommands;
|
import client.commandline.pdcommands.PeopleDatabaseCommands;
|
||||||
import common.collection.Database;
|
import common.collection.Database;
|
||||||
import common.collection.PeopleDatabase;
|
import common.collection.PeopleDatabase;
|
||||||
|
import common.util.UtilFunctions;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Lab5Client {
|
public class Lab5Client {
|
||||||
|
|
||||||
|
public final static Logger LOGGER = UtilFunctions.getLogger(Lab5Client.class, "client");
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Logger logger = Logger.getLogger("Lab5Client");
|
|
||||||
CommandLineHandler cmd = CommandLineHandler.getInstance();
|
CommandLineHandler cmd = CommandLineHandler.getInstance();
|
||||||
|
|
||||||
PeopleDatabaseCommands.registerDatabaseCommands();
|
PeopleDatabaseCommands.registerDatabaseCommands();
|
||||||
PeopleDatabase peopleDatabase = new PeopleDatabase(logger);
|
PeopleDatabase peopleDatabase = new PeopleDatabase(LOGGER);
|
||||||
try {
|
try {
|
||||||
peopleDatabase.load();
|
peopleDatabase.load();
|
||||||
} catch (Database.DatabaseLoadFailedException e) {
|
} catch (Database.DatabaseLoadFailedException e) {
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -11,7 +11,7 @@ import java.util.stream.Collectors;
|
||||||
public final class ConnectionProperties {
|
public final class ConnectionProperties {
|
||||||
|
|
||||||
private static final Properties properties = new Properties();
|
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 int DEFAULT_PORT = 1234;
|
||||||
private static final String DEFAULT_HOST = "localhost";
|
private static final String DEFAULT_HOST = "localhost";
|
||||||
private static final String FILE_NAME = "connection.properties";
|
private static final String FILE_NAME = "connection.properties";
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
package common.util;
|
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;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,94 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
|
<peopleDatabase>
|
||||||
|
<person>
|
||||||
|
<name>Gena</name>
|
||||||
|
<coordinates>
|
||||||
|
<x>5.0</x>
|
||||||
|
<y>6.0</y>
|
||||||
|
</coordinates>
|
||||||
|
<creationDate>2022-05-10</creationDate>
|
||||||
|
<height>124</height>
|
||||||
|
<passportID>231323232</passportID>
|
||||||
|
<eyeColor>BLACK</eyeColor>
|
||||||
|
<nationality>JAPAN</nationality>
|
||||||
|
<location>
|
||||||
|
<x>2.0</x>
|
||||||
|
<y>3.0</y>
|
||||||
|
<z>4</z>
|
||||||
|
<name>Tokyo</name>
|
||||||
|
</location>
|
||||||
|
</person>
|
||||||
|
<person>
|
||||||
|
<name>Gena</name>
|
||||||
|
<coordinates>
|
||||||
|
<x>5.0</x>
|
||||||
|
<y>6.0</y>
|
||||||
|
</coordinates>
|
||||||
|
<creationDate>2022-05-10</creationDate>
|
||||||
|
<height>124</height>
|
||||||
|
<passportID>231323232</passportID>
|
||||||
|
<eyeColor>BLACK</eyeColor>
|
||||||
|
<nationality>JAPAN</nationality>
|
||||||
|
<location>
|
||||||
|
<x>2.0</x>
|
||||||
|
<y>3.0</y>
|
||||||
|
<z>4</z>
|
||||||
|
<name>Tokyo</name>
|
||||||
|
</location>
|
||||||
|
</person>
|
||||||
|
<person>
|
||||||
|
<name>Sasha</name>
|
||||||
|
<coordinates>
|
||||||
|
<x>3.4</x>
|
||||||
|
<y>-2.0</y>
|
||||||
|
</coordinates>
|
||||||
|
<creationDate>2022-05-10</creationDate>
|
||||||
|
<height>175</height>
|
||||||
|
<passportID>2312131231</passportID>
|
||||||
|
<eyeColor>BROWN</eyeColor>
|
||||||
|
<nationality>JAPAN</nationality>
|
||||||
|
<location>
|
||||||
|
<x>2323.0</x>
|
||||||
|
<y>443.0</y>
|
||||||
|
<z>2</z>
|
||||||
|
<name>Tokyo</name>
|
||||||
|
</location>
|
||||||
|
</person>
|
||||||
|
<person>
|
||||||
|
<name>Sasha</name>
|
||||||
|
<coordinates>
|
||||||
|
<x>3.4</x>
|
||||||
|
<y>-2.0</y>
|
||||||
|
</coordinates>
|
||||||
|
<creationDate>2022-05-10</creationDate>
|
||||||
|
<height>175</height>
|
||||||
|
<passportID>2312131231</passportID>
|
||||||
|
<eyeColor>BROWN</eyeColor>
|
||||||
|
<nationality>JAPAN</nationality>
|
||||||
|
<location>
|
||||||
|
<x>2323.0</x>
|
||||||
|
<y>443.0</y>
|
||||||
|
<z>2</z>
|
||||||
|
<name>Tokyo</name>
|
||||||
|
</location>
|
||||||
|
</person>
|
||||||
|
<person>
|
||||||
|
<name>wasd</name>
|
||||||
|
<coordinates>
|
||||||
|
<x>2.0</x>
|
||||||
|
<y>3.0</y>
|
||||||
|
</coordinates>
|
||||||
|
<creationDate>2022-05-10</creationDate>
|
||||||
|
<height>2</height>
|
||||||
|
<passportID>321312312</passportID>
|
||||||
|
<eyeColor>BLACK</eyeColor>
|
||||||
|
<nationality>CHINA</nationality>
|
||||||
|
<location>
|
||||||
|
<x>2.0</x>
|
||||||
|
<y>2.0</y>
|
||||||
|
<z>2</z>
|
||||||
|
<name>wasd</name>
|
||||||
|
</location>
|
||||||
|
</person>
|
||||||
|
<initDate>2022-05-10</initDate>
|
||||||
|
</peopleDatabase>
|
|
@ -3,24 +3,25 @@ package server;
|
||||||
import common.collection.Database;
|
import common.collection.Database;
|
||||||
import common.collection.PeopleDatabase;
|
import common.collection.PeopleDatabase;
|
||||||
import common.parser.ConnectionProperties;
|
import common.parser.ConnectionProperties;
|
||||||
|
import common.util.UtilFunctions;
|
||||||
import server.net.UDPServer;
|
import server.net.UDPServer;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Lab5Server {
|
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) {
|
public static void main(String[] args) {
|
||||||
PeopleDatabase peopleDatabase = new PeopleDatabase(logger);
|
LOGGER.info("wasd");
|
||||||
|
PeopleDatabase peopleDatabase = new PeopleDatabase(LOGGER);
|
||||||
try {
|
try {
|
||||||
peopleDatabase.load();
|
peopleDatabase.load();
|
||||||
} catch (Database.DatabaseLoadFailedException e) {
|
} catch (Database.DatabaseLoadFailedException e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
UDPServer udp = new UDPServer(ConnectionProperties.getPort(), logger);
|
UDPServer udp = new UDPServer(ConnectionProperties.getPort(), LOGGER);
|
||||||
if (!udp.connect()) System.exit(-1);
|
if (!udp.connect()) System.exit(-1);
|
||||||
while (true)
|
while (true)
|
||||||
udp.receive(peopleDatabase);
|
udp.receive(peopleDatabase);
|
||||||
|
|
Loading…
Reference in a new issue