forked from clusterbench/clusterbench
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request clusterbench#531 from rhusar/397-logger-servlet
chore: expand LoggerServlet to accept a log level defaulting to INFO, add a default message 'ping', fix formatter, expand test, update readme (resolves clusterbench#397)
- Loading branch information
Showing
5 changed files
with
105 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 46 additions & 15 deletions
61
clusterbench-ee10-web/src/main/java/org/jboss/test/clusterbench/web/debug/LoggerServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,56 @@ | ||
/* | ||
* Copyright The ClusterBench Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.jboss.test.clusterbench.web.debug; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import jakarta.servlet.annotation.WebServlet; | ||
import jakarta.servlet.http.HttpServlet; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
import org.jboss.test.clusterbench.common.ClusterBenchConstants; | ||
|
||
@WebServlet("/log") | ||
/** | ||
* Logging servlet that logs provided message in 'msg' parameter. | ||
* Can also be called without parameters as a 'ping' mechanism which | ||
* Optionally, log level can be provided in the 'level' parameter. | ||
* The default level is INFO. | ||
* | ||
* @author Tommaso Borgato | ||
* @author Radoslav Husar | ||
*/ | ||
@WebServlet(name = "LoggerServlet", urlPatterns = {"/log"}) | ||
public class LoggerServlet extends HttpServlet { | ||
private static final Logger LOG = Logger.getLogger(LoggerServlet.class.getCanonicalName()); | ||
|
||
private void logMarker(String msg) { | ||
LOG.info(msg); | ||
} | ||
|
||
public void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws IOException { | ||
String msg = request.getParameter("msg"); | ||
logMarker(msg); | ||
response.getWriter().print("Success"); | ||
} | ||
|
||
// Servlet parameters and their default values | ||
public static final String MESSAGE_PARAM = "msg"; | ||
public static final String DEFAULT_MESSAGE = "ping"; | ||
public static final String LEVEL_PARAM = "level"; | ||
public static final Level DEFAULT_LEVEL = Level.INFO; | ||
|
||
private static final Logger LOG = Logger.getLogger(LoggerServlet.class.getCanonicalName()); | ||
|
||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
String requestLevel = request.getParameter(LEVEL_PARAM); | ||
String message = request.getParameter(MESSAGE_PARAM); | ||
|
||
Level level = null; | ||
if (requestLevel != null) { | ||
try { | ||
level = Level.parse(requestLevel); | ||
} catch (Exception ignored) { | ||
// Ignore silently and use default. | ||
} | ||
} | ||
|
||
LOG.log(level == null ? DEFAULT_LEVEL : level, message == null ? DEFAULT_MESSAGE : message); | ||
|
||
response.getWriter().print(ClusterBenchConstants.SUCCESS); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters