diff --git a/CHANGELOG.md b/CHANGELOG.md index ef24190d..1376d774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e - `HttpHandler` now supports `HttpEntity` instances returned from `RestHandler#handle`. This allows to define handlers that directly return a valid `HttpEntity` (e.g. the content of an HTML page). In this case, the `RestHandler` implementation is responsible of the `HttpEntity` creation. - `RestHandler` instances can now throw a `RestHandlerException` to notify the server that an error occurred when handling the request. For now this exception is used to return a *404* status code instead of *200*. +- Change log level of non-critical messages in `XatkitServer` this reduces the amount of noise in Xatkit logs. ## Removed @@ -26,6 +27,7 @@ The changelog format is based on [Keep a Changelog](https://keepachangelog.com/e - [#251](https://github.com/xatkit-bot-platform/xatkit-runtime/issues/251): *AdminHttpHandler should be moved to react platform* - The `XatkitServer` now correctly returns a `404` error if there is no `RestHandler` associated to a requested URI. +- [#267](https://github.com/xatkit-bot-platform/xatkit-runtime/issues/267): *Change log level of XatkitServer logs to debug* ## [4.0.0] - 2019-12-01 diff --git a/core/src/main/java/com/xatkit/core/server/ContentHttpHandler.java b/core/src/main/java/com/xatkit/core/server/ContentHttpHandler.java index 01fdb068..3ae7643c 100644 --- a/core/src/main/java/com/xatkit/core/server/ContentHttpHandler.java +++ b/core/src/main/java/com/xatkit/core/server/ContentHttpHandler.java @@ -59,7 +59,7 @@ public void handle(final HttpRequest request, final HttpResponse response, final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT); String target = request.getRequestLine().getUri(); - Log.info("{0} - Received a {1} query on {2}", this.getClass().getSimpleName(), method, target); + Log.debug("{0} - Received a {1} query on {2}", this.getClass().getSimpleName(), method, target); /* * Ignore the parameters, they are not used for now. @@ -67,14 +67,15 @@ public void handle(final HttpRequest request, final HttpResponse response, final if (method.equals("GET")) { if (target.startsWith(XatkitServerUtils.PUBLIC_CONTENT_URL_FRAGMENT)) { String filePath = target.replaceFirst(XatkitServerUtils.PUBLIC_CONTENT_URL_FRAGMENT, ""); - Log.info("File Path: {0}", filePath); + Log.debug("File Path: {0}", filePath); File file = xatkitServer.getPublicFile(filePath); if (nonNull(file) && file.exists() && !file.isDirectory()) { FileInputStream fis; try { fis = new FileInputStream(file); } catch (IOException e) { - Log.error("Cannot retrieve the file {0}", file.getAbsolutePath()); + Log.error("{0} Cannot retrieve the file {1}", this.getClass().getSimpleName(), + file.getAbsolutePath()); response.setStatusCode(HttpStatus.SC_NOT_FOUND); return; } @@ -86,7 +87,7 @@ public void handle(final HttpRequest request, final HttpResponse response, final } } } - Log.warn("Cannot server content {0}", target); + Log.error("Cannot server content {0}, unsupported method {1}", target, method); response.setStatusCode(HttpStatus.SC_NOT_FOUND); } } diff --git a/core/src/main/java/com/xatkit/core/server/HttpHandler.java b/core/src/main/java/com/xatkit/core/server/HttpHandler.java index aa45d9c4..99b3bf74 100644 --- a/core/src/main/java/com/xatkit/core/server/HttpHandler.java +++ b/core/src/main/java/com/xatkit/core/server/HttpHandler.java @@ -118,18 +118,16 @@ public void handle(final HttpRequest request, final HttpResponse response, final request.getRequestLine().getUri()), e); } - Log.info("Received a {0} query on {1}", method, path); + Log.debug("Received a {0} query on {1}", method, path); - parameters.forEach(p -> Log.info("Query parameter: {0}={1}", p.getName(), p.getValue())); + parameters.forEach(p -> Log.debug("Query parameter: {0}={1}", p.getName(), p.getValue())); List
headers = Arrays.asList(request.getAllHeaders()); - headers.forEach(h -> Log.info("Header {0}={1}", h.getName(), h.getValue())); + headers.forEach(h -> Log.debug("Header {0}={1}", h.getName(), h.getValue())); Object content = null; String contentType = null; - Log.info("Request type {0}", request.getClass().getSimpleName()); - /* * The access control headers that will be returned in the response. */ @@ -143,19 +141,19 @@ public void handle(final HttpRequest request, final HttpResponse response, final Header encodingHeader = entity.getContentEncoding(); if (nonNull(encodingHeader) && encodingHeader.getElements().length > 0) { contentEncoding = encodingHeader.getElements()[0].getName(); - Log.info("Query content encoding: {0}", contentEncoding); + Log.debug("Query content encoding: {0}", contentEncoding); } else { Log.warn("Unknown query content encoding"); } Header contentTypeHeader = entity.getContentType(); if (nonNull(contentTypeHeader) && contentTypeHeader.getElements().length > 0) { contentType = contentTypeHeader.getElements()[0].getName(); - Log.info("Query content type: {0}", contentType); + Log.debug("Query content type: {0}", contentType); } else { Log.warn("Unknown query content type"); } Long contentLength = entity.getContentLength(); - Log.info("Query content length: {0}", contentLength); + Log.debug("Query content length: {0}", contentLength); try { BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); @@ -200,7 +198,7 @@ public void handle(final HttpRequest request, final HttpResponse response, final response.setEntity(resultEntity); } } else { - Log.warn("Cannot embed the provided json element {0}", result); + Log.warn("Cannot embed the handler's result {0}", result); } response.setHeader("Access-Control-Allow-Headers", "content-type"); response.setStatusCode(HttpStatus.SC_OK); diff --git a/core/src/main/java/com/xatkit/core/server/XatkitServer.java b/core/src/main/java/com/xatkit/core/server/XatkitServer.java index ac50c758..df8ce5fb 100644 --- a/core/src/main/java/com/xatkit/core/server/XatkitServer.java +++ b/core/src/main/java/com/xatkit/core/server/XatkitServer.java @@ -122,7 +122,6 @@ public class XatkitServer { public XatkitServer(Configuration configuration) { checkNotNull(configuration, "Cannot start the %s with the provided %s: %s", this.getClass().getSimpleName (), Configuration.class.getSimpleName(), configuration); - Log.info("Creating {0}", this.getClass().getSimpleName()); this.isStarted = false; if (configuration.containsKey(XatkitServerUtils.SERVER_KEYSTORE_LOCATION_KEY) && !configuration.containsKey(XatkitServerUtils.SERVER_PUBLIC_URL_KEY)) { @@ -164,10 +163,13 @@ public XatkitServer(Configuration configuration) { .setSslContext(sslContext) .setSocketConfig(socketConfig) .setExceptionLogger(e -> { - if (e instanceof SocketTimeoutException) { + if(e instanceof SocketTimeoutException || (e instanceof IOException && e.getMessage().equals( + "Connection reset by peer"))) { /* * SocketTimeoutExceptions are thrown after each query, we can log them as debug to avoid * polluting the application log. + * Connection reset by peer is thrown when a remote client closes the connection, this + * happens quite often and can be logged as debug too. */ Log.debug(e); } else { @@ -175,7 +177,6 @@ public XatkitServer(Configuration configuration) { } }) .registerHandler("/content*", new ContentHttpHandler(this)) -// .registerHandler("/admin*", new AdminHttpHandler(configuration)) .registerHandler("*", new HttpHandler(this)) .create(); } @@ -197,7 +198,7 @@ SSLContext createSSLContext(@Nonnull Configuration configuration) { Configuration.class.getSimpleName(), configuration); String keystorePath = configuration.getString(XatkitServerUtils.SERVER_KEYSTORE_LOCATION_KEY); if (isNull(keystorePath)) { - Log.info("No SSL context to load"); + Log.debug("No SSL context to load"); return null; } File keystoreFile = FileUtils.getFile(keystorePath, configuration); @@ -583,7 +584,7 @@ String getPublicURL(File file) { try { filePath = Paths.get(file.getAbsolutePath()).toRealPath(LinkOption.NOFOLLOW_LINKS); } catch (NoSuchFileException e) { - Log.info("Cannot retrieve the public URL for the provided file {0}, the file does not exist", + Log.error("Cannot retrieve the public URL for the provided file {0}, the file does not exist", file.getAbsolutePath()); return null; } catch (IOException e) { @@ -645,7 +646,7 @@ File getPublicFile(String filePath) { try { p = p.toRealPath(LinkOption.NOFOLLOW_LINKS); } catch (NoSuchFileException e) { - Log.warn("The public file {0} does not exist", p); + Log.error("The public file {0} does not exist", p); return null; } catch (IOException e) { throw new XatkitException(e);