Skip to content

Commit 278d2b3

Browse files
committed
Implemented old ServerLogItem + an attributes map
Signed-off-by: Nico Piel <nico.piel@hotmail.de>
1 parent 53a85d9 commit 278d2b3

File tree

5 files changed

+50
-81
lines changed

5 files changed

+50
-81
lines changed

client/src/com/mirth/connect/plugins/serverlog/ServerLogClient.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
public class ServerLogClient extends DashboardTabPlugin {
2525
private ServerLogPanel serverLogPanel;
2626
private LinkedList<ServerLogItem> serverLogs;
27-
private static final ServerLogItem unauthorizedLog = new ServerLogItem(new HashMap<String, Object>(){{
28-
put("message", "You are not authorized to view the server log.");
29-
}});
27+
private static final ServerLogItem unauthorizedLog = new ServerLogItem("You are not authorized to view the server log.");
3028
private int currentServerLogSize;
3129
private boolean receivedNewLogs;
3230
private Long lastLogId;

server/src/com/mirth/connect/plugins/serverlog/ArrayAppender.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,6 @@ public void append(LogEvent logEvent) {
3838
return;
3939
}
4040

41-
String channelId = null;
42-
String channelName = null;
43-
44-
if (logEvent.getContextData() != null) {
45-
channelId = logEvent.getContextData().getValue("channelId");
46-
channelName = logEvent.getContextData().getValue("channelName");
47-
}
48-
4941
String level = String.valueOf(logEvent.getLevel());
5042
Date date = new Date(logEvent.getTimeMillis());
5143
String threadName = logEvent.getThreadName();
@@ -71,17 +63,6 @@ public void append(LogEvent logEvent) {
7163
throwableInformation = logText.toString();
7264
}
7365

74-
Map<String, Object> properties = new HashMap<>();
75-
properties.put("channelId", channelId);
76-
properties.put("channelName", channelName);
77-
properties.put("level", level);
78-
properties.put("date", date);
79-
properties.put("threadName", threadName);
80-
properties.put("category", category);
81-
properties.put("lineNumber", lineNumber);
82-
properties.put("message", message);
83-
properties.put("throwableInformation", throwableInformation);
84-
85-
serverLogProvider.newServerLogReceived(new ServerLogItem(properties));
66+
serverLogProvider.newServerLogReceived(level, date, threadName, category, lineNumber, message, throwableInformation, logEvent.getContextData().toMap());
8667
}
8768
}

server/src/com/mirth/connect/plugins/serverlog/ServerLogItem.java

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,38 @@ public class ServerLogItem implements Serializable {
2424

2525
private String serverId;
2626
private Long id;
27-
private String channelId;
2827
private String level;
2928
private Date date;
3029
private String threadName;
3130
private String category;
3231
private String lineNumber;
3332
private String message;
3433
private String throwableInformation;
35-
private String channelName;
36-
private HashMap<String, Object> context;
34+
private Map<String, String> attributes;
3735

38-
public ServerLogItem() {}
36+
public ServerLogItem() {
37+
this(null, null, null, null, null, null, null, null, null, new HashMap<>());
38+
}
3939

40-
public ServerLogItem(Map<String, Object> properties) {
41-
if (properties != null) {
42-
this.context = new HashMap<>(properties);
43-
} else {
44-
this.context = new HashMap<>();
45-
}
40+
public ServerLogItem(String message) {
41+
this(null, null, null, null, null, null, null, message, null, new HashMap<>());
42+
}
4643

47-
this.serverId = (String) context.getOrDefault("serverId", "");
48-
this.id = (Long) context.getOrDefault("id", 0L);
49-
this.channelId = (String) context.getOrDefault("channelId", "");
50-
this.channelName = (String) context.getOrDefault("channelName", "");
51-
this.level = (String) context.getOrDefault("level", "");
52-
this.date = (Date) context.getOrDefault("date", Date.from(Instant.now()));
53-
this.threadName = (String) context.getOrDefault("threadName", "");
54-
this.category = (String) context.getOrDefault("category", "");
55-
this.lineNumber = (String) context.getOrDefault("lineNumber", "");
56-
this.message = (String) context.getOrDefault("message", "");
57-
this.throwableInformation = (String) context.getOrDefault("throwableInformation", "");
44+
public ServerLogItem(String serverId, Long id, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation) {
45+
this(serverId, id, level, date, threadName, category, lineNumber, message, throwableInformation, new HashMap<>());
46+
}
47+
48+
public ServerLogItem(String serverId, Long id, String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation, Map<String, String> attributes) {
49+
this.serverId = serverId;
50+
this.id = id;
51+
this.level = level;
52+
this.date = date;
53+
this.threadName = threadName;
54+
this.category = category;
55+
this.lineNumber = lineNumber;
56+
this.message = message;
57+
this.throwableInformation = throwableInformation;
58+
this.attributes = attributes;
5859
}
5960

6061
public String getServerId() {
@@ -72,14 +73,6 @@ public Long getId() {
7273
public void setId(Long id) {
7374
this.id = id;
7475
}
75-
76-
public String getChannelId() {
77-
return channelId;
78-
}
79-
80-
public void setChannelId(String channelId) {
81-
this.channelId = channelId;
82-
}
8376

8477
public String getLevel() {
8578
return level;
@@ -136,21 +129,33 @@ public String getThrowableInformation() {
136129
public void setThrowableInformation(String throwableInformation) {
137130
this.throwableInformation = throwableInformation;
138131
}
139-
140-
public String getChannelName() {
141-
return channelName;
132+
133+
public Map<String, String> getAttributes() {
134+
return attributes;
142135
}
143-
144-
public void setChannelName(String channelName) {
145-
this.channelName = channelName;
136+
137+
public void setAttributes(Map<String, String> attributes) {
138+
if (attributes == null) {
139+
this.attributes = new HashMap<String, String>();
140+
} else {
141+
this.attributes = attributes;
142+
}
146143
}
147-
148-
public Map<String, Object> getContext() {
149-
return context;
144+
145+
public String getChannelId() {
146+
return this.attributes.get("channelId");
147+
}
148+
149+
public void setChannelId(String channelId) {
150+
this.attributes.put("channelId", channelId);
150151
}
151152

152-
public void setContext(Map<String, Object> context) {
153-
this.context = new HashMap<>(context);
153+
public String getChannelName() {
154+
return this.attributes.get("channelName");
155+
}
156+
157+
public void setChannelName(String channelName) {
158+
this.attributes.put("channelName", channelName);
154159
}
155160

156161
@Override

server/src/com/mirth/connect/plugins/serverlog/ServerLogProvider.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,9 @@ public void init(Properties properties) {
5757
initialize();
5858
}
5959

60-
public synchronized void newServerLogReceived(ServerLogItem svi) {
60+
public synchronized void newServerLogReceived(String level, Date date, String threadName, String category, String lineNumber, String message, String throwableInformation, Map<String, String> attributes) {
6161
if (logController != null) {
62-
svi.getContext().put("serverId", serverId);
63-
svi.getContext().put("id", logId);
64-
65-
logController.addLogItem(svi);
62+
logController.addLogItem(new ServerLogItem(serverId, logId, level, date, threadName, category, lineNumber, message, throwableInformation, attributes));
6663
logId++;
6764
}
6865
}

server/src/com/mirth/connect/server/servlets/SwaggerExamplesServlet.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,19 +1286,7 @@ private List<ServerEvent> getServerEventListExample() {
12861286
}
12871287

12881288
private ServerLogItem getServerLogItemExample() {
1289-
// return new ServerLogItem(UUID.randomUUID().toString(), 1L, "INFO", dateNow.getTime(), "Main Server Thread", "com.mirth.connect.server.Mirth", "1", "Example message", "Example throwable information");
1290-
Map<String, Object> properties = new HashMap<>();
1291-
properties.put("serverId", UUID.randomUUID().toString());
1292-
properties.put("id", 1L);
1293-
properties.put("channelId", "INFO");
1294-
properties.put("date", dateNow.getTime());
1295-
properties.put("threadName", "Main Server Thread");
1296-
properties.put("category", "com.mirth.connect.server.Mirth");
1297-
properties.put("lineNumber", "1");
1298-
properties.put("message", "Example Message");
1299-
properties.put("throwableInformation", "Example throwable Information");
1300-
1301-
return new ServerLogItem(properties);
1289+
return new ServerLogItem(UUID.randomUUID().toString(), 1L, "INFO", dateNow.getTime(), "Main Server Thread", "com.mirth.connect.server.Mirth", "1", "Example message", "Example throwable information");
13021290
}
13031291

13041292
private List<ServerLogItem> getServerLogItemListExample() {

0 commit comments

Comments
 (0)