Skip to content

Commit 6ceaec4

Browse files
committed
simplify SearchRequest logging with shared format strings
1 parent 7002a4b commit 6ceaec4

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

core/pva/src/main/java/org/epics/pva/common/SearchRequest.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
@SuppressWarnings("nls")
2727
public class SearchRequest
2828
{
29-
private static final String LOG_PVA_CLIENT = "PVA Client ";
30-
private static final String LOG_SENT_SEARCH = " sent search #";
29+
private static final String LOG_SHORT_SEARCH_FORMAT = "PVA client %s sent only %d bytes for search request";
30+
private static final String LOG_SENT_SEARCH_FORMAT = "PVA Client %s sent search #%d";
31+
private static final String LOG_DAMAGED_SEARCH_FORMAT = "PVA Client %s sent damaged search #%d";
32+
33+
private static String searchPrefix(final InetSocketAddress from, final int seq)
34+
{
35+
return String.format(LOG_SENT_SEARCH_FORMAT, from, seq);
36+
}
3137

3238
/** Channel with CID to be searched */
3339
public static class Channel
@@ -128,7 +134,7 @@ public static SearchRequest decode(final OriginTag origin, final InetSocketAddre
128134
// plus the list of names.
129135
if (payload < 4+1+3+16+2+1+2)
130136
{
131-
logger.log(Level.WARNING, () -> "PVA client " + from + " sent only " + payload + " bytes for search request");
137+
logger.log(Level.WARNING, () -> String.format(LOG_SHORT_SEARCH_FORMAT, from, payload));
132138
return null;
133139
}
134140
final SearchRequest search = new SearchRequest();
@@ -154,7 +160,7 @@ public static SearchRequest decode(final OriginTag origin, final InetSocketAddre
154160
}
155161
catch (Exception ex)
156162
{
157-
logger.log(Level.WARNING, () -> LOG_PVA_CLIENT + from + LOG_SENT_SEARCH + search.seq + " with invalid address");
163+
logger.log(Level.WARNING, () -> searchPrefix(from, search.seq) + " with invalid address");
158164
return null;
159165
}
160166
int port = Short.toUnsignedInt(buffer.getShort());
@@ -191,7 +197,7 @@ else if ("tcp".equals(protocol))
191197
}
192198
catch (Exception ex)
193199
{
194-
logger.log(Level.WARNING, ex, () -> LOG_PVA_CLIENT + from + LOG_SENT_SEARCH + search.seq + " with invalid protocol");
200+
logger.log(Level.WARNING, ex, () -> searchPrefix(from, search.seq) + " with invalid protocol");
195201
return null;
196202
}
197203

@@ -201,14 +207,14 @@ else if ("tcp".equals(protocol))
201207
if (count == 0)
202208
{ // pvlist request
203209
search.channels = null;
204-
logger.log(Level.FINER, () -> LOG_PVA_CLIENT + from + LOG_SENT_SEARCH + search.seq + " to list servers");
210+
logger.log(Level.FINER, () -> searchPrefix(from, search.seq) + " to list servers");
205211
}
206212
else
207213
{ // Channel search request
208214
if (! (tcp || search.tls))
209215
{
210216
final String unsupported_protocol = unknown_protocol;
211-
logger.log(Level.WARNING, () -> LOG_PVA_CLIENT + from + LOG_SENT_SEARCH + search.seq + " for protocol '" + unsupported_protocol + "', need 'tcp' or 'tls'");
217+
logger.log(Level.WARNING, () -> searchPrefix(from, search.seq) + " for protocol '" + unsupported_protocol + "', need 'tcp' or 'tls'");
212218
return null;
213219
}
214220
search.channels = new ArrayList<>(count);
@@ -218,7 +224,7 @@ else if ("tcp".equals(protocol))
218224
{
219225
final int cid = buffer.getInt();
220226
final String name = PVAString.decodeString(buffer);
221-
logger.log(Level.FINER, () -> LOG_PVA_CLIENT + from + LOG_SENT_SEARCH + search.seq + " for " + name + " [cid " + cid + "]"
227+
logger.log(Level.FINER, () -> searchPrefix(from, search.seq) + " for " + name + " [cid " + cid + "]"
222228
+ ", reply addr " + orig_response_addr
223229
+ (orig_response_addr.equals(search.client) ? "" : ", using " + search.client)
224230
+ (search.tls ? " (TLS)" : "")
@@ -230,7 +236,7 @@ else if ("tcp".equals(protocol))
230236
}
231237
catch (Exception ex)
232238
{
233-
logger.log(Level.WARNING, ex, () -> LOG_PVA_CLIENT + from + " sent damaged search #" + search.seq);
239+
logger.log(Level.WARNING, ex, () -> String.format(LOG_DAMAGED_SEARCH_FORMAT, from, search.seq));
234240
return null;
235241
}
236242
}

0 commit comments

Comments
 (0)