Skip to content

Commit c03cb52

Browse files
author
innokenty
committed
fix logging formats
1 parent 8ddf307 commit c03cb52

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

proxy/src/main/java/ru/qatools/gridrouter/ProxyServlet.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ protected void sendProxyRequest(
6868
Request request = getRequestWithoutSessionId(clientRequest, proxyRequest);
6969
super.sendProxyRequest(clientRequest, proxyResponse, request);
7070
} catch (Exception exception) {
71-
LOGGER.error("[{}] [{}] - could not read client request, proxying request as is",
72-
"REQUEST_READ_FAILURE", clientRequest.getRemoteHost(), exception);
71+
LOGGER.error("[REQUEST_READ_FAILURE] [{}] - could not read client request, proxying request as is",
72+
clientRequest.getRemoteHost(), exception);
7373
super.sendProxyRequest(clientRequest, proxyResponse, proxyRequest);
7474
}
7575
}
@@ -81,32 +81,31 @@ protected String rewriteTarget(HttpServletRequest request) {
8181
String remoteHost = getRemoteHost(request);
8282

8383
if (!isUriValid(uri)) {
84-
LOGGER.warn("[{}] [{}] - request uri is {}", "INVALID_SESSION_HASH", remoteHost, uri);
84+
LOGGER.warn("[INVALID_SESSION_HASH] [{}] - request uri is {}", remoteHost, uri);
8585
return null;
8686
}
8787

8888
String route = getRoute(uri);
8989
String command = getCommand(uri);
9090

9191
if (route == null) {
92-
LOGGER.error("[{}] [{}] - request uri is {}", "ROUTE_NOT_FOUND", remoteHost, uri);
92+
LOGGER.error("[ROUTE_NOT_FOUND] [{}] - request uri is {}", remoteHost, uri);
9393
return null;
9494
}
9595

9696
if (isSessionDeleteRequest(request, command)) {
97-
LOGGER.info("[{}] [{}] [{}] [{}]", "SESSION_DELETED", remoteHost, route, command);
97+
LOGGER.info("[SESSION_DELETED] [{}] [{}] [{}]", remoteHost, route, command);
9898
stats.stopSession();
9999
}
100100

101101
try {
102102
return redirectionUrl(route, command);
103103
} catch (Exception exception) {
104-
LOGGER.error("[{}] [{}] - error building redirection uri because of {}\n"
104+
LOGGER.error("[REDIRECTION_URL_ERROR] [{}] - error building redirection uri because of {}\n"
105105
+ " request uri: {}\n"
106106
+ " parsed route: {}\n"
107107
+ " parsed command: {}",
108-
"REDIRECTION_URL_ERROR", remoteHost,
109-
exception.toString(), uri, route, command);
108+
remoteHost, exception.toString(), uri, route, command);
110109
}
111110
return null;
112111
}
@@ -127,11 +126,9 @@ private String removeSessionIdSafe(String content, String remoteHost) {
127126
message.setSessionId(null);
128127
return message.toJson();
129128
} catch (IOException exception) {
130-
LOGGER.error("[{}] [{}] - could not create proxy request without session id, "
129+
LOGGER.error("[UNABLE_TO_REMOVE_SESSION_ID] [{}] - could not create proxy request without session id, "
131130
+ "proxying request as is. Request content is: {}",
132-
"UNABLE_TO_REMOVE_SESSION_ID", remoteHost,
133-
content,
134-
exception);
131+
remoteHost, content, exception);
135132
}
136133
return content;
137134
}
@@ -149,8 +146,7 @@ protected String getCommand(String uri) {
149146
try {
150147
return URLDecoder.decode(encodedCommand, UTF_8.name());
151148
} catch (UnsupportedEncodingException e) {
152-
LOGGER.error("[{}] - could not decode command: {}",
153-
"UNABLE_TO_DECODE_COMMAND", encodedCommand, e);
149+
LOGGER.error("[UNABLE_TO_DECODE_COMMAND] - could not decode command: {}", encodedCommand, e);
154150
return encodedCommand;
155151
}
156152
}

proxy/src/main/java/ru/qatools/gridrouter/RouteServlet.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
8888
Version actualVersion = config.findVersion(user, caps);
8989

9090
if (actualVersion == null) {
91-
LOGGER.warn("[{}] [{}] [{}] [{}]", "UNSUPPORTED_BROWSER", user, remoteHost, browser);
91+
LOGGER.warn("[UNSUPPORTED_BROWSER] [{}] [{}] [{}]", user, remoteHost, browser);
9292
replyWithError(format("Cannot find %s capabilities on any available node",
9393
caps.describe()), response);
9494
return;
@@ -111,7 +111,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
111111

112112
String route = host.getRoute();
113113
try (CloseableHttpClient client = newHttpClient()) {
114-
LOGGER.info("[{}] [{}] [{}] [{}] [{}] [{}]", "SESSION_ATTEMPTED", user, remoteHost, browser, route, attempt);
114+
LOGGER.info("[SESSION_ATTEMPTED] [{}] [{}] [{}] [{}] [{}]", user, remoteHost, browser, route, attempt);
115115

116116
String target = route + request.getRequestURI();
117117
HttpResponse hubResponse = client.execute(post(target, message));
@@ -121,18 +121,18 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
121121
String sessionId = hubMessage.getSessionId();
122122
hubMessage.setSessionId(host.getRouteId() + sessionId);
123123
replyWithOk(hubMessage, response);
124-
LOGGER.info("[{}] [{}] [{}] [{}] [{}] [{}] [{}]",
125-
"SESSION_CREATED", user, remoteHost, browser, route, sessionId, attempt);
124+
LOGGER.info("[SESSION_CREATED] [{}] [{}] [{}] [{}] [{}] [{}]",
125+
user, remoteHost, browser, route, sessionId, attempt);
126126
stats.startSession();
127127
return;
128128
}
129-
LOGGER.warn("[{}] [{}] [{}] [{}] [{}] - {}",
130-
"SESSION_FAILED", user, remoteHost, browser, route, hubMessage.getErrorMessage());
129+
LOGGER.warn("[SESSION_FAILED] [{}] [{}] [{}] [{}] - {}",
130+
user, remoteHost, browser, route, hubMessage.getErrorMessage());
131131
} catch (JsonProcessingException exception) {
132-
LOGGER.error("[{}] [{}] [{}] [{}] - {}", "BAD_HUB_JSON",
132+
LOGGER.error("[BAD_HUB_JSON] [{}] [{}] [{}] - {}", "",
133133
user, remoteHost, browser, route, exception.getMessage());
134134
} catch (IOException exception) {
135-
LOGGER.error("[{}] [{}] [{}] [{}] - {}", "HUB_COMMUNICATION_FAILURE",
135+
LOGGER.error("[HUB_COMMUNICATION_FAILURE] [{}] [{}] [{}] - {}",
136136
user, remoteHost, browser, route, exception.getMessage());
137137
}
138138

@@ -147,7 +147,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
147147
}
148148
}
149149

150-
LOGGER.error("[{}] [{}] [{}] [{}]", "SESSION_NOT_CREATED", user, remoteHost, browser);
150+
LOGGER.error("[SESSION_NOT_CREATED] [{}] [{}] [{}]", user, remoteHost, browser);
151151
replyWithError("Cannot create session on any available node", response);
152152
}
153153

0 commit comments

Comments
 (0)