Improved time prefix

This commit is contained in:
Carlos
2020-05-29 16:37:35 +02:00
parent a5335b1e6e
commit 2643999e8d
9 changed files with 46 additions and 25 deletions

View File

@ -11,6 +11,7 @@ import org.java_websocket.handshake.ClientHandshake;
import org.java_websocket.server.WebSocketServer;
import es.mesacarlos.webconsole.WebConsole;
import es.mesacarlos.webconsole.util.DateTimeUtils;
import es.mesacarlos.webconsole.util.Internationalization;
import es.mesacarlos.webconsole.util.LoginManager;
import es.mesacarlos.webconsole.websocket.command.WSCommandFactory;
@ -97,7 +98,7 @@ public class WSServer extends WebSocketServer {
Collection<WebSocket> connections = getConnections();
for (WebSocket connection : connections) {
if (LoginManager.getInstance().isLoggedIn(connection.getRemoteSocketAddress()))
sendToClient(connection, new ConsoleOutput(line));
sendToClient(connection, new ConsoleOutput(line, DateTimeUtils.getTimeAsString()));
}
}

View File

@ -35,7 +35,7 @@ public class ReadLogFileCommand implements WSCommand{
}
for(String line : lines)
wsServer.sendToClient(conn, new ConsoleOutput(line));
wsServer.sendToClient(conn, new ConsoleOutput(line, null));
}
}

View File

@ -4,9 +4,11 @@ import com.google.gson.JsonObject;
public class ConsoleOutput implements JSONOutput{
private String message;
private String time;
public ConsoleOutput(String message) {
public ConsoleOutput(String message, String time) {
this.message = message;
this.time = time;
}
@Override
@ -18,12 +20,17 @@ public class ConsoleOutput implements JSONOutput{
public String getMessage() {
return message;
}
public String getTime() {
return time;
}
@Override
public String toJSON() {
JsonObject object = new JsonObject();
object.addProperty("status", getStatusCode());
object.addProperty("statusDescription", "Console Output");
object.addProperty("time", getTime());
object.addProperty("message", getMessage());
return object.toString();
}