diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java index f70d7def670250..0bdbe363922f0e 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java @@ -37,7 +37,6 @@ import io.netty.handler.codec.http.HttpHeaderNames; import io.quarkus.bootstrap.classloading.ClassPathElement; import io.quarkus.bootstrap.classloading.QuarkusClassLoader; -import io.quarkus.builder.item.SimpleBuildItem; import io.quarkus.deployment.IsDevelopment; import io.quarkus.deployment.annotations.BuildProducer; import io.quarkus.deployment.annotations.BuildStep; @@ -49,7 +48,6 @@ import io.quarkus.deployment.builditem.LaunchModeBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; -import io.quarkus.deployment.builditem.WebSocketLogHandlerBuildItem; import io.quarkus.deployment.console.ConsoleCommand; import io.quarkus.deployment.console.ConsoleStateManager; import io.quarkus.deployment.dev.devservices.DevServiceDescriptionBuildItem; @@ -87,7 +85,6 @@ import io.quarkus.qute.ValueResolver; import io.quarkus.qute.ValueResolvers; import io.quarkus.qute.Variant; -import io.quarkus.runtime.RuntimeValue; import io.quarkus.runtime.TemplateHtmlBuilder; import io.quarkus.utilities.OS; import io.quarkus.vertx.http.deployment.BodyHandlerBuildItem; @@ -102,8 +99,6 @@ import io.quarkus.vertx.http.runtime.devmode.DevConsoleRecorder; import io.quarkus.vertx.http.runtime.devmode.RedirectHandler; import io.quarkus.vertx.http.runtime.devmode.RuntimeDevConsoleRoute; -import io.quarkus.vertx.http.runtime.logstream.LogStreamRecorder; -import io.quarkus.vertx.http.runtime.logstream.WebSocketLogHandler; import io.quarkus.vertx.http.runtime.management.ManagementInterfaceBuildTimeConfig; import io.smallrye.common.vertx.VertxContext; import io.smallrye.config.common.utils.StringUtil; @@ -323,17 +318,6 @@ public void runtimeTemplates(List items, recorder.initConfigFun(); } - @BuildStep(onlyIf = IsDevelopment.class) - @Record(ExecutionTime.STATIC_INIT) - public void handler(BuildProducer historyProducer, - BuildProducer webSocketLogHandlerBuildItem, - LogStreamRecorder recorder, DevUIConfig devUiConfig) { - RuntimeValue> handler = recorder.logHandler(devUiConfig.historySize); - - webSocketLogHandlerBuildItem.produce(new WebSocketLogHandlerBuildItem((RuntimeValue) handler)); - historyProducer.produce(new HistoryHandlerBuildItem(handler)); - } - @Consume(LoggingSetupBuildItem.class) @BuildStep(onlyIf = IsDevelopment.class) public ServiceStartBuildItem setupDeploymentSideHandling(List devTemplatePaths, @@ -446,9 +430,7 @@ public DevConsoleTemplateInfoBuildItem config(List routes, - HistoryHandlerBuildItem historyHandlerBuildItem, NonApplicationRootPathBuildItem nonApplicationRootPathBuildItem, ShutdownContextBuildItem shutdownContext, BuildProducer routeBuildItemBuildProducer, @@ -468,12 +450,6 @@ public void setupDevConsoleRoutes( result.getWebRootConfigurations(), shutdownContext)) .build()); - // Add the log stream - routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() - .route("dev-v1/logstream") - .handler(logStreamRecorder.websocketHandler(historyHandlerBuildItem.value)) - .build()); - for (DevConsoleRouteBuildItem i : routes) { Entry groupAndArtifact = i.groupIdAndArtifactId(curateOutcomeBuildItem); // if the handler is a proxy, then that means it's been produced by a recorder and therefore belongs in the regular runtime Vert.x instance @@ -883,14 +859,6 @@ public CompletionStage resolve(EvalContext context) { } } - public static final class HistoryHandlerBuildItem extends SimpleBuildItem { - final RuntimeValue> value; - - public HistoryHandlerBuildItem(RuntimeValue> value) { - this.value = value; - } - } - private static class DetectPackageFileVisitor extends SimpleFileVisitor { private final List paths; diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-static/css/logstream.css b/extensions/vertx-http/deployment/src/main/resources/dev-static/css/logstream.css deleted file mode 100644 index 10815eed730e69..00000000000000 --- a/extensions/vertx-http/deployment/src/main/resources/dev-static/css/logstream.css +++ /dev/null @@ -1,50 +0,0 @@ - -.logstreamIcon { - color: #9a9da0 !important; -} - -.logstreamIcon:hover { - color: #3366ac !important; - cursor: pointer; -} - -.logstreamFilteredOut { - display: none; -} - -#logstreamLogTerminalText { - font-size: 0.9em; -} - -#logstreamLogTerminal { - padding-bottom: 5px; - line-height: 1.00; - padding-left: 6px; - padding-right: 6px; - padding-bottom: 6px; -} - -#logstreamFollowLogButton { - position: fixed; - color: green; - margin-top: 5px; - right: 23px; - cursor: pointer; -} - -#logstreamInformationSection { - position: fixed; - color: white; - font-size: 1.6em; - right: 23px; - bottom: 5px; -} - -.logstreamStopLogHr { - margin-top: 10px; - border-top: 1px dashed #3366ac; -} - -.clickable-app-class:hover { - cursor:pointer; -} diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-static/js/logstream.js b/extensions/vertx-http/deployment/src/main/resources/dev-static/js/logstream.js deleted file mode 100644 index bdb7fbdccc2ab3..00000000000000 --- a/extensions/vertx-http/deployment/src/main/resources/dev-static/js/logstream.js +++ /dev/null @@ -1,794 +0,0 @@ -var myself = $('script[src*=logstream]'); - -// Get the non application root path -var frameworkRootPath = myself.attr('data-frameworkRootPath'); -if (typeof frameworkRootPath === "undefined" ) { - var pathname = window.location.pathname; - var frameworkRootPath = pathname.substr(0, pathname.indexOf('/dev-v1/')); -} -// Get the streaming path -var streamingPath = myself.attr('data-streamingPath'); -if (typeof streamingPath === "undefined" ) { - var streamingPath = "/dev-v1/logstream"; -} - -var zoom = 0.90; -var linespace = 1.00; -var tabspace = 1; -var increment = 0.05; - -var webSocket; -var tab = " "; -var space = " "; - -var isRunning = true; -var logScrolling = true; - -var logfilter = ""; - -var localstoragekey = "quarkus_logging_manager_state"; - -$('document').ready(function () { - loadSettings(); - - openSocket(); - // Make sure we stop the connection when the browser close - window.onbeforeunload = function () { - closeSocket(); - }; - - logstreamStopStartButton.addEventListener("click", stopStartEvent); - logstreamClearLogButton.addEventListener("click", clearScreenEvent); - logstreamZoomOutButton.addEventListener("click", zoomOutEvent); - logstreamZoomInButton.addEventListener("click", zoomInEvent); - logstreamFollowLogButton.addEventListener("click", followLogEvent); - logstreamFilterModalInputButton.addEventListener("click", applyLogFilter); - - addControlCListener(); - addEnterListener(); - addScrollListener(); - addLineSpaceListener(); - addTabSizeListener(); - - $('[data-toggle="tooltip"]').tooltip(); - - logstreamFilterModalInput.addEventListener("keyup", function(event) { - if (event.keyCode === 13) { - event.preventDefault(); - logstreamFilterModalInputButton.click(); - } - }); - - $("#logLevelFilterInput").on("keyup", function() { - var value = $(this).val().toLowerCase(); - $("#logstreamLogLevelsModalTableBody tr").filter(function() { - $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1); - }); - }); - - $('#logstreamFilterModal').on('shown.bs.modal', function () { - $('#logstreamFilterModalInput').trigger('focus'); - }); - - // save settings on hide - document.addEventListener('visibilitychange', function() { - if (document.visibilityState == 'hidden') { - saveSettings(); - } - }); - -}); - -function loadSettings(){ - if (localstoragekey in localStorage) { - var state = JSON.parse(localStorage.getItem(localstoragekey)); - - zoom = state.zoom; - applyZoom(); - - linespace = state.linespace; - applyLineSpacing(); - - tabspace = state.tabspace; - applyTabSpacing(); - - logScrolling = state.logScrolling; - applyFollowLog(); - - $("#logstreamFilterModalInput").val(state.filter); - applyLogFilter(); - - $('#logstreamColumnsModalLevelIconSwitch').prop('checked', state.levelIconSwitch); - $('#logstreamColumnsModalSequenceNumberSwitch').prop('checked', state.sequenceNumberSwitch); - $('#logstreamColumnsModalDateSwitch').prop('checked', state.dateSwitch); - $('#logstreamColumnsModalTimeSwitch').prop('checked', state.timeSwitch); - $('#logstreamColumnsModalLevelSwitch').prop('checked', state.levelSwitch); - $('#logstreamColumnsModalSourceClassFullAbbreviatedSwitch').prop('checked', state.sourceClassFullAbbreviatedSwitch); - $('#logstreamColumnsModalSourceClassFullSwitch').prop('checked', state.sourceClassFullSwitch); - $('#logstreamColumnsModalSourceClassSwitch').prop('checked', state.sourceClassSwitch); - $('#logstreamColumnsModalSourceMethodNameSwitch').prop('checked', state.sourceMethodNameSwitch); - $('#logstreamColumnsModalThreadIdSwitch').prop('checked', state.threadIdSwitch); - $('#logstreamColumnsModalThreadNameSwitch').prop('checked', state.threadNameSwitch); - $('#logstreamColumnsModalMessageSwitch').prop('checked', state.messageSwitch); - $('#logstreamColumnsModalHostNameSwitch').prop("checked", state.hostNameSwitch); - $('#logstreamColumnsModalLoggerNameAbbreviatedSwitch').prop("checked", state.loggerNameAbbreviatedSwitch); - $('#logstreamColumnsModalLoggerNameSwitch').prop("checked", state.loggerNameSwitch); - $('#logstreamColumnsModalLoggerClassNameSwitch').prop("checked", state.loggerClassNameSwitch); - $('#logstreamColumnsModalSourceFileNameSwitch').prop("checked", state.sourceFileNameSwitch); - $('#logstreamColumnsModalSourceLineNumberSwitch').prop("checked", state.sourceLineNumberSwitch); - $('#logstreamColumnsModalProcessIdSwitch').prop("checked", state.processIdSwitch); - $('#logstreamColumnsModalProcessNameSwitch').prop("checked", state.processNameSwitch); - } -} - -function saveSettings(){ - // Running state - var state = { - "zoom": zoom, - "linespace": linespace, - "tabspace": tabspace, - "logScrolling": logScrolling, - "filter": logfilter, - "levelIconSwitch": $('#logstreamColumnsModalLevelIconSwitch').is(":checked"), - "sequenceNumberSwitch": $('#logstreamColumnsModalSequenceNumberSwitch').is(":checked"), - "dateSwitch": $('#logstreamColumnsModalDateSwitch').is(":checked"), - "timeSwitch": $('#logstreamColumnsModalTimeSwitch').is(":checked"), - "levelSwitch": $('#logstreamColumnsModalLevelSwitch').is(":checked"), - "sourceClassFullAbbreviatedSwitch": $('#logstreamColumnsModalSourceClassFullAbbreviatedSwitch').is(":checked"), - "sourceClassFullSwitch": $('#logstreamColumnsModalSourceClassFullSwitch').is(":checked"), - "sourceClassSwitch": $('#logstreamColumnsModalSourceClassSwitch').is(":checked"), - "sourceMethodNameSwitch": $('#logstreamColumnsModalSourceMethodNameSwitch').is(":checked"), - "threadIdSwitch": $('#logstreamColumnsModalThreadIdSwitch').is(":checked"), - "threadNameSwitch": $('#logstreamColumnsModalThreadNameSwitch').is(":checked"), - "messageSwitch": $('#logstreamColumnsModalMessageSwitch').is(":checked"), - "hostNameSwitch": $('#logstreamColumnsModalHostNameSwitch').is(":checked"), - "loggerNameAbbreviatedSwitch": $('#logstreamColumnsModalLoggerNameAbbreviatedSwitch').is(":checked"), - "loggerNameSwitch": $('#logstreamColumnsModalLoggerNameSwitch').is(":checked"), - "loggerClassNameSwitch": $('#logstreamColumnsModalLoggerClassNameSwitch').is(":checked"), - "sourceFileNameSwitch": $('#logstreamColumnsModalSourceFileNameSwitch').is(":checked"), - "sourceLineNumberSwitch": $('#logstreamColumnsModalSourceLineNumberSwitch').is(":checked"), - "processIdSwitch": $('#logstreamColumnsModalProcessIdSwitch').is(":checked"), - "processNameSwitch": $('#logstreamColumnsModalProcessNameSwitch').is(":checked") - }; - - localStorage.setItem(localstoragekey, JSON.stringify(state)); -} - -function addControlCListener(){ - // Add listener to stop - var ctrlDown = false, - ctrlKey = 17, - cmdKey = 91, - cKey = 67; - - $(document).keydown(function (e) { - if (e.keyCode === ctrlKey || e.keyCode === cmdKey) - ctrlDown = true; - }).keyup(function (e) { - if (e.keyCode === ctrlKey || e.keyCode === cmdKey) - ctrlDown = false; - }); - - $(document).keydown(function (e) { - if (e.target.tagName === "BODY") { - if (ctrlDown && (e.keyCode === cKey))stopLog(); - } - }); -} - -function addScrollListener(){ - $(document).on('mousewheel DOMMouseScroll', function(event) { - if (event.shiftKey) { - if( event.originalEvent.detail > 0 || event.originalEvent.wheelDelta < 0 ) { - zoomOutEvent(); - } else { - zoomInEvent(); - } - return false; - } - }); -} - -function addLineSpaceListener(){ - $(document).keydown(function (e) { - if (e.target.tagName === "BODY") { - if (e.shiftKey && e.keyCode === 38) { - lineSpaceIncreaseEvent(); - }else if (e.shiftKey && e.keyCode === 40) { - lineSpaceDecreaseEvent(); - } - } - }); -} - -function addTabSizeListener(){ - $(document).keydown(function (e) { - if (e.target.tagName === "BODY") { - if (e.shiftKey && e.keyCode === 39) { - tabSpaceIncreaseEvent(); - }else if (e.shiftKey && e.keyCode === 37) { - tabSpaceDecreaseEvent(); - } - } - }); -} - -function addEnterListener(){ - $(document).keydown(function (e) { - if (e.target.tagName === "BODY") { - if (e.keyCode === 13 && !$('#logstreamFilterModal').hasClass('show')){ - writeResponse("
"); - var element = document.getElementById("logstreamLogTerminal"); - element.scrollIntoView({block: "end"}); - } - } - }); -} - -function stopStartEvent() { - if (isRunning) { - stopLog(); - } else { - startLog(); - } -} - -function stopLog() { - webSocket.send("stop"); - writeResponse("
"); - - logstreamStopStartButton.innerHTML = ""; - $("#logstreamFollowLogButton").hide(); - isRunning = false; -} - -function startLog() { - webSocket.send("start"); - - logstreamStopStartButton.innerHTML = ""; - $("#logstreamFollowLogButton").show(); - isRunning = true; -} - -function clearScreenEvent() { - logstreamLogTerminalText.innerHTML = ""; -} - -function applyLineSpacing(){ - $('#logstreamLogTerminal').css("line-height", linespace); -} - -function applyTabSpacing(){ - if(tabspace === null || isNaN(tabspace))tabspace = 1; - tab = ""; - for (i = 0; i < tabspace; i++) { - tab = tab + space; - }; -} - -function lineSpaceDecreaseEvent() { - linespace = parseFloat(linespace) - parseFloat(increment); - linespace = parseFloat(linespace).toFixed(2); - showInfoMessage("" + space + linespace); - applyLineSpacing(); -} - -function lineSpaceIncreaseEvent() { - linespace = parseFloat(linespace) + parseFloat(increment); - linespace = parseFloat(linespace).toFixed(2); - showInfoMessage("" + space + linespace); - applyLineSpacing(); -} - -function tabSpaceDecreaseEvent() { - if(tabspace>1){ - tabspace = tabspace - 1; - showInfoMessage("" + space + tabspace); - applyTabSpacing(); - } -} - -function tabSpaceIncreaseEvent() { - tabspace = tabspace + 1; - showInfoMessage("" + space + tabspace); - applyTabSpacing(); -} - -function applyZoom(){ - $('#logstreamLogTerminalText').css("font-size", zoom + "em"); -} - -function zoomOutEvent() { - zoom = parseFloat(zoom) - parseFloat(increment); - zoom = parseFloat(zoom).toFixed(2); - showInfoMessage("" + space + zoom); - applyZoom(); -} - -function zoomInEvent() { - zoom = parseFloat(zoom) + parseFloat(increment); - zoom = parseFloat(zoom).toFixed(2); - showInfoMessage("" + space + zoom); - applyZoom(); -} - -function showInfoMessage(msg){ - $('#logstreamInformationSection').empty().show().html(msg).delay(3000).fadeOut(300); -} - -function followLogEvent() { - logScrolling = !logScrolling; - applyFollowLog(); -} - -function applyFollowLog(){ - if (logScrolling) { - $("#logstreamFollowLogButtonIcon").addClass("text-success"); - $("#logstreamFollowLogButtonIcon").addClass("fa-spin"); - showInfoMessage("" + space + "Autoscroll ON"); - }else{ - $("#logstreamFollowLogButtonIcon").removeClass("text-success"); - $("#logstreamFollowLogButtonIcon").removeClass("fa-spin"); - showInfoMessage("" + space + "Autoscroll OFF"); - } -} - -function scrollToTop() { - logScrolling = false; -} - -function scrollToBottom() { - logScrolling = true; -} - -function applyLogFilter(){ - logfilter = $("#logstreamFilterModalInput").val(); - if(logfilter===""){ - clearLogFilter(); - }else{ - logstreamCurrentFilter.innerHTML = "" + logfilter + " "; - - var currentlines = $("#logstreamLogTerminalText").html().split(''); - - var filteredHtml = ""; - var i; - for (i = 0; i < currentlines.length; i++) { - var htmlline = currentlines[i]; - filteredHtml = filteredHtml + getLogLine(htmlline) + ""; - } - - logstreamLogTerminalText.innerHTML = ""; - writeResponse(filteredHtml); - } - $('#logstreamFilterModal').modal('hide'); -} - -function getLogLine(htmlline){ - if(logfilter===""){ - return htmlline; - }else{ - - var textline = $(htmlline).text(); - if(textline.includes(logfilter)){ - return htmlline; - }else{ - return htmlline.replace('', ''); - } - } -} - -function clearLogFilter(){ - logfilter = ""; - $("#logstreamFilterModalInput").val(""); - logstreamCurrentFilter.innerHTML = ""; - - var currentlines = $("#logstreamLogTerminalText").html().split(''); - - var filteredHtml = ""; - var i; - for (i = 0; i < currentlines.length; i++) { - var htmlline = currentlines[i].replace('', ''); - filteredHtml = filteredHtml + htmlline + ""; - } - - logstreamLogTerminalText.innerHTML = ""; - writeResponse(filteredHtml); -} - -function getLevelIcon(level) { - if($('#logstreamColumnsModalLevelIconSwitch').is(":checked")){ - level = level.toUpperCase(); - if (level === "WARNING" || level === "WARN") - return "" + tab; - if (level === "SEVERE" || level === "ERROR") - return "" + tab; - if (level === "INFO") - return "" + tab; - if (level === "DEBUG") - return "" + tab; - - return "" + tab; - } - return ""; -} - -function getHostName(hostName) { - if($('#logstreamColumnsModalHostNameSwitch').is(":checked")){ - return hostName + tab; - } - return ""; -} - -function getSequenceNumber(sequenceNumber){ - if($('#logstreamColumnsModalSequenceNumberSwitch').is(":checked")){ - return "" + sequenceNumber + "" + tab; - } - return ""; -} - -function getDateString(timestamp){ - if($('#logstreamColumnsModalDateSwitch').is(":checked")){ - return timestamp.slice(0, 10) + space; - } - return ""; -} - -function getTimeString(timestamp){ - if($('#logstreamColumnsModalTimeSwitch').is(":checked")){ - return timestamp.slice(11, 23).replace(".", ",") + tab; - } - return ""; -} - -function getLevelText(level) { - if($('#logstreamColumnsModalLevelSwitch').is(":checked")){ - level = level.toUpperCase(); - if (level === "WARNING" || level === "WARN") - return "WARN" + space + "" + tab; - if (level === "SEVERE" || level === "ERROR") - return "ERROR" + tab; - if (level === "INFO") - return "INFO" + space + "" + tab; - if (level === "DEBUG") - return "DEBUG" + tab; - - return level + tab; - } - return ""; -} - -function getLoggerNameAbbreviated(loggerNameAbbreviated){ - if($('#logstreamColumnsModalLoggerNameAbbreviatedSwitch').is(":checked")){ - return "[" + loggerNameAbbreviated + "]" + tab; - } - return ""; -} - -function getLoggerName(loggerName){ - if($('#logstreamColumnsModalLoggerNameSwitch').is(":checked")){ - return "[" + loggerName + "]" + tab; - } - return ""; -} - -function getLoggerClassName(loggerClassName){ - if($('#logstreamColumnsModalLoggerClassNameSwitch').is(":checked")){ - return "[" + loggerClassName + "]" + tab; - } - return ""; -} - -function getClassFullAbbreviatedName(sourceClassNameFull, lineNumber, sourceClassNameFullShort) { - if($('#logstreamColumnsModalSourceClassFullAbbreviatedSwitch').is(":checked")){ - if (isClickableClassName(sourceClassNameFull, lineNumber)) { - return makeClickableClassNameLink(sourceClassNameFull, lineNumber, sourceClassNameFullShort); - } - return "[" + sourceClassNameFullShort + "]" + tab; - } - return ""; -} - -function getFullClassName(sourceClassNameFull, lineNumber) { - if($('#logstreamColumnsModalSourceClassFullSwitch').is(":checked")){ - if (isClickableClassName(sourceClassNameFull, lineNumber)) { - return makeClickableClassNameLink(sourceClassNameFull, lineNumber, sourceClassNameFull); - } - return "[" + sourceClassNameFull + "]" + tab; - } - return ""; -} - -function getClassName(sourceClassNameFull, lineNumber, className) { - if($('#logstreamColumnsModalSourceClassSwitch').is(":checked")){ - if (isClickableClassName(sourceClassNameFull, lineNumber)) { - return makeClickableClassNameLink(sourceClassNameFull, lineNumber, className); - } - return "[" + className + "]" + tab; - } - return ""; -} - -function isClickableClassName(className, lineNumber){ - if (lineNumber !== undefined && lineNumber && lineNumber !== "" && className !== undefined && appClassLocation(className) && ideKnown()) { - return true; - } - return false; -} - -function makeClickableClassNameLink(className, lineNumber, display){ - return "[" + display + "]" + tab; -} - -function getMethodName(methodName) { - if($('#logstreamColumnsModalSourceMethodNameSwitch').is(":checked")){ - return methodName + tab; - } - return ""; -} - -function getFileName(fileName){ - if($('#logstreamColumnsModalSourceFileNameSwitch').is(":checked")){ - return "" + fileName + "" + space; - } - return ""; -} - -function getLineNumber(lineNumber){ - if($('#logstreamColumnsModalSourceLineNumberSwitch').is(":checked")){ - return "(line: " + lineNumber + ")" + tab; - } - return ""; -} - -function getProcessId(processName, processId) { - if($('#logstreamColumnsModalProcessIdSwitch').is(":checked")){ - return "(" + processId + ")" + tab; - } - return ""; -} - -function getProcessName(processName, processId) { - if($('#logstreamColumnsModalProcessNameSwitch').is(":checked")){ - return "(" + processName + ")" + tab; - } - return ""; -} - -function getThreadId(threadName, threadId) { - if($('#logstreamColumnsModalThreadIdSwitch').is(":checked")){ - return "(" + threadId + ")" + tab; - } - return ""; -} - -function getThreadName(threadName, threadId) { - if($('#logstreamColumnsModalThreadNameSwitch').is(":checked")){ - return "(" + threadName + ")" + tab; - } - return ""; -} - -function getLogMessage(message){ - if($('#logstreamColumnsModalMessageSwitch').is(":checked")){ - // Make links clickable - if(message.includes("http://")){ - message = makeLink(message, "http://"); - } - if(message.includes("https://")){ - message = makeLink(message, "https://"); - } - // Make sure multi line is supported - if(message.includes('\n')){ - var htmlifiedLines = []; - var lines = message.split('\n'); - for (var i = 0; i < lines.length; i++) { - var line = lines[i]; - line = line.replace(/ /g, '\u00a0'); - if(i === lines.length-1){ - htmlifiedLines.push(line); - }else{ - htmlifiedLines.push(line + '
'); - } - } - message = htmlifiedLines.join(''); - } - return message; - } - return ""; -} - -function makeLink(message, protocol){ - var url = message.substring(message.indexOf(protocol)); - if(url.includes(" ")){ - url = url.substr(0,url.indexOf(' ')); - } - var link = "" + url + ""; - - return message.replace(url, link); -} - -function enhanceStacktrace(stacktrace) { - var enhanceStacktrace = []; - var lines = stacktrace.split('\n'); - for (var i = 0; i < lines.length; i++) { - var line = lines[i].trim(); - if (line) { - var startWithAt = line.startsWith("at "); - if (!startWithAt) { - var parts = line.split(":"); - line = "" + parts[0] + ":" + parts[1]; - } else { - if(!line.includes(".zig")){ - var parts = line.split(" "); - // Make it clickable - var classMethodFileNumber = parts[1]; - var classMethodFileNumberSplit = classMethodFileNumber.split("("); - var classMethod = classMethodFileNumberSplit[0]; - var fileNumber = classMethodFileNumberSplit[1]; - givenClassName = classMethod.substring(0, classMethod.lastIndexOf('.')); - lineNumber = fileNumber.substring(fileNumber.lastIndexOf(':') + 1, fileNumber.lastIndexOf(')')); - if(isClickableClassName(givenClassName, lineNumber)){ - line = "" + line + ""; - } - } - line = space + space + space + space + space + space + line; - } - } - enhanceStacktrace.push(line + '
'); - } - var newStacktrace = enhanceStacktrace.join(''); - return "" + newStacktrace + ""; -} - -function writeResponse(text) { - var logfile = $('#logstreamLogTerminalText'); - logfile.append(text); - if (logScrolling) { - var element = document.getElementById("logstreamLogTerminal"); - element.scrollIntoView({block: "end"}); - } - // TODO: Trim the top if it gets too big ? -} - -function openSocket() { - // Ensures only one connection is open at a time - if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) { - writeResponse("Already connected..."); - return; - } - // Create a new instance of the websocket - var new_uri; - if (window.location.protocol === "https:") { - new_uri = "wss:"; - } else { - new_uri = "ws:"; - } - - new_uri += "//" + window.location.host + frameworkRootPath + streamingPath; - webSocket = new WebSocket(new_uri); - - webSocket.onmessage = function (event) { - var json = JSON.parse(event.data); - - if(json.type === "logLine"){ - messageLog(json); - }else if(json.type === "init"){ - populateLoggerLevelModal(json.loggers,json.levels); - } - }; - - webSocket.onclose = function () { - saveSettings(); - if (isRunning) { - stopLog(); - } - writeResponse("Connection closed
"); - }; - - function messageLog(json) { - - var timestamp = new Date(json.timestamp); - var level = json.level; - var isoDateTime = new Date(timestamp.getTime() - (timestamp.getTimezoneOffset() * 60000)).toISOString(); - - var htmlLine = "" - + getLevelIcon(level) - + getSequenceNumber(json.sequenceNumber) - + getHostName(json.hostName) - + getDateString(isoDateTime) - + getTimeString(isoDateTime) - + getLevelText(level) - + getLoggerNameAbbreviated(json.loggerNameShort) - + getLoggerName(json.loggerName) - + getLoggerClassName(json.loggerClassName) - + getClassFullAbbreviatedName(json.sourceClassNameFull, json.sourceLineNumber,json.sourceClassNameFullShort) - + getFullClassName(json.sourceClassNameFull,json.sourceLineNumber) - + getClassName(json.sourceClassNameFull,json.sourceLineNumber,json.sourceClassName) - + getMethodName(json.sourceMethodName) - + getFileName(json.sourceFileName) - + getLineNumber(json.sourceLineNumber) - + getProcessId(json.processName, json.processId) - + getProcessName(json.processName, json.ProcessId) - + getThreadId(json.threadName, json.threadId) - + getThreadName(json.threadName, json.threadId) - + getLogMessage(json.formattedMessage) + "
"; - - if (json.stacktrace) { - for (var i in json.stacktrace) { - var stacktrace = enhanceStacktrace(json.stacktrace[i]); - htmlLine = htmlLine + stacktrace; - } - } - - htmlLine = htmlLine + "
"; - - if(logfilter!=""){ - writeResponse(getLogLine(htmlLine)); - }else{ - writeResponse(htmlLine); - } - } -} - -function closeSocket() { - webSocket.close(); -} - -function populateLoggerLevelModal(loggerNamesArray, levelNamesArray){ - var tbodyLevels = $('#logstreamLogLevelsModalTableBody'); - - // Populate the dropdown - for (var i = 0; i < loggerNamesArray.length; i++) { - var row = "" + loggerNamesArray[i].name + "" + createDropdown(loggerNamesArray[i].name, loggerNamesArray[i].effectiveLevel,levelNamesArray) + ""; - tbodyLevels.append(row); - } - - $('.logleveldropdown').on('change', function() { - changeLogLevel(this.value, $(this).find('option:selected').text()); - }); - - populated = true; -} - -function createLevelRowId(logger){ - var name = logger + "_row"; - return name.replaceAll(".", "_"); -} - -function getTextClass(level){ - level = level.toUpperCase(); - if (level === "WARNING" || level === "WARN") - return "text-warning"; - if (level === "SEVERE" || level === "ERROR") - return "text-danger"; - if (level === "INFO") - return "text-primary"; - if (level === "DEBUG") - return "text-secondary"; - - return ""; -} - -function createDropdown(name, level, levelNamesArray){ - - var dd = ""; - - return dd; -} - -function changeLogLevel(val,text){ - webSocket.send("update|" + val + "|" + text); - // Also change the style of the row - var id = createLevelRowId(val); - $('#' + id).removeClass(); - $('#' + id).addClass(getTextClass(text)); -} \ No newline at end of file diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerLog.html b/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerLog.html deleted file mode 100644 index 4bcf52bd08eecf..00000000000000 --- a/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerLog.html +++ /dev/null @@ -1,8 +0,0 @@ -
- - -
- - -
-
\ No newline at end of file diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerModals.html b/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerModals.html deleted file mode 100644 index dc6a3e431106e8..00000000000000 --- a/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerModals.html +++ /dev/null @@ -1,161 +0,0 @@ - - - - - - - - diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerNav.html b/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerNav.html deleted file mode 100644 index 474c6784771ad3..00000000000000 --- a/extensions/vertx-http/deployment/src/main/resources/dev-templates/logmanagerNav.html +++ /dev/null @@ -1,30 +0,0 @@ - - \ No newline at end of file diff --git a/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html b/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html index 69e3dd936786ea..e7a873b9482b7d 100644 --- a/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html +++ b/extensions/vertx-http/deployment/src/main/resources/dev-templates/main.html @@ -9,7 +9,6 @@ - {#insert styleref /} @@ -78,49 +77,11 @@ {#insert body/} - - - - {#include logmanagerModals /} {#include testsModals /} - {#insert scriptref /} diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/JsonFormatter.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/JsonFormatter.java deleted file mode 100644 index 4c27991f292a1a..00000000000000 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/JsonFormatter.java +++ /dev/null @@ -1,149 +0,0 @@ -package io.quarkus.vertx.http.runtime.logstream; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.LinkedList; -import java.util.List; - -import org.jboss.logmanager.ExtFormatter; -import org.jboss.logmanager.ExtLogRecord; - -import io.quarkus.vertx.http.runtime.devmode.Json; - -/** - * Formatting log records into a json format - */ -public class JsonFormatter extends ExtFormatter { - - @Override - public String format(final ExtLogRecord logRecord) { - return toJsonObject(logRecord).build(); - } - - private Json.JsonObjectBuilder toJsonObject(ExtLogRecord logRecord) { - String formattedMessage = formatMessage(logRecord); - - Json.JsonObjectBuilder jsonObject = Json.object(); - - jsonObject.put(TYPE, LOG_LINE); - if (logRecord.getLoggerName() != null) { - jsonObject.put(LOGGER_NAME_SHORT, getShortFullClassName(logRecord.getLoggerName(), "")); - jsonObject.put(LOGGER_NAME, logRecord.getLoggerName()); - } - if (logRecord.getLoggerClassName() != null) { - jsonObject.put(LOGGER_CLASS_NAME, logRecord.getLoggerClassName()); - } - if (logRecord.getHostName() != null) { - jsonObject.put(HOST_NAME, logRecord.getHostName()); - } - if (logRecord.getLevel() != null) { - jsonObject.put(LEVEL, logRecord.getLevel().getName()); - } - if (formattedMessage != null) { - jsonObject.put(FORMATTED_MESSAGE, formattedMessage); - } - if (logRecord.getMessage() != null) { - jsonObject.put(MESSAGE, logRecord.getMessage()); - } - jsonObject.put(SOURCE_LINE_NUMBER, logRecord.getSourceLineNumber()); - if (logRecord.getSourceClassName() != null) { - String justClassName = getJustClassName(logRecord.getSourceClassName()); - jsonObject.put(SOURCE_CLASS_NAME_FULL_SHORT, getShortFullClassName(logRecord.getSourceClassName(), justClassName)); - jsonObject.put(SOURCE_CLASS_NAME_FULL, logRecord.getSourceClassName()); - jsonObject.put(SOURCE_CLASS_NAME, justClassName); - } - if (logRecord.getSourceFileName() != null) { - jsonObject.put(SOURCE_FILE_NAME, logRecord.getSourceFileName()); - } - if (logRecord.getSourceMethodName() != null) { - jsonObject.put(SOURCE_METHOD_NAME, logRecord.getSourceMethodName()); - } - if (logRecord.getThrown() != null) { - jsonObject.put(STACKTRACE, getStacktraces(logRecord.getThrown())); - } - jsonObject.put(THREAD_ID, logRecord.getThreadID()); - jsonObject.put(THREAD_NAME, logRecord.getThreadName()); - jsonObject.put(PROCESS_ID, logRecord.getProcessId()); - jsonObject.put(PROCESS_NAME, logRecord.getProcessName()); - jsonObject.put(TIMESTAMP, logRecord.getMillis()); - jsonObject.put(SEQUENCE_NUMBER, logRecord.getSequenceNumber()); - return jsonObject; - } - - private Json.JsonArrayBuilder getStacktraces(Throwable t) { - List traces = new LinkedList<>(); - addStacktrace(traces, t); - - Json.JsonArrayBuilder jsonArray = Json.array(); - - traces.forEach((trace) -> { - jsonArray.add(trace); - }); - return jsonArray; - } - - private void addStacktrace(List traces, Throwable t) { - traces.add(getStacktrace(t)); - if (t.getCause() != null) - addStacktrace(traces, t.getCause()); - } - - private String getStacktrace(Throwable t) { - try (StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw)) { - t.printStackTrace(pw); - return sw.toString(); - } catch (IOException ex) { - return null; - } - } - - private String getJustClassName(String fullName) { - int lastDot = fullName.lastIndexOf(DOT) + 1; - return fullName.substring(lastDot); - } - - private String getShortFullClassName(String fullName, String justClassName) { - String[] parts = fullName.split("\\" + DOT); - try (StringWriter buffer = new StringWriter()) { - for (int i = 0; i < parts.length - 1; i++) { - String part = parts[i]; - if (part.equals(justClassName) || part.length() < 3) { - buffer.write(part); - } else { - buffer.write(part.substring(0, 3)); - } - buffer.write(DOT); - } - buffer.write(parts[parts.length - 1]); - return buffer.toString(); - } catch (IOException ex) { - return fullName; - } - } - - private static final String TYPE = "type"; - private static final String LEVEL = "level"; - private static final String MESSAGE = "message"; - private static final String FORMATTED_MESSAGE = "formattedMessage"; - private static final String LOGGER_NAME_SHORT = "loggerNameShort"; - private static final String LOGGER_NAME = "loggerName"; - private static final String LOGGER_CLASS_NAME = "loggerClassName"; - private static final String HOST_NAME = "hostName"; - private static final String SOURCE_LINE_NUMBER = "sourceLineNumber"; - private static final String SOURCE_CLASS_NAME_FULL = "sourceClassNameFull"; - private static final String SOURCE_CLASS_NAME_FULL_SHORT = "sourceClassNameFullShort"; - private static final String SOURCE_CLASS_NAME = "sourceClassName"; - private static final String SOURCE_FILE_NAME = "sourceFileName"; - private static final String SOURCE_METHOD_NAME = "sourceMethodName"; - private static final String THREAD_ID = "threadId"; - private static final String THREAD_NAME = "threadName"; - private static final String PROCESS_ID = "processId"; - private static final String PROCESS_NAME = "processName"; - private static final String TIMESTAMP = "timestamp"; - private static final String STACKTRACE = "stacktrace"; - private static final String SEQUENCE_NUMBER = "sequenceNumber"; - private static final String DOT = "."; - private static final String LOG_LINE = "logLine"; -} diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogController.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogController.java deleted file mode 100644 index b3894b4eb270e3..00000000000000 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogController.java +++ /dev/null @@ -1,125 +0,0 @@ -package io.quarkus.vertx.http.runtime.logstream; - -import static org.jboss.logmanager.Level.ALL; -import static org.jboss.logmanager.Level.CONFIG; -import static org.jboss.logmanager.Level.DEBUG; -import static org.jboss.logmanager.Level.ERROR; -import static org.jboss.logmanager.Level.FATAL; -import static org.jboss.logmanager.Level.FINE; -import static org.jboss.logmanager.Level.FINER; -import static org.jboss.logmanager.Level.FINEST; -import static org.jboss.logmanager.Level.INFO; -import static org.jboss.logmanager.Level.OFF; -import static org.jboss.logmanager.Level.SEVERE; -import static org.jboss.logmanager.Level.TRACE; -import static org.jboss.logmanager.Level.WARN; -import static org.jboss.logmanager.Level.WARNING; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; -import java.util.TreeMap; -import java.util.logging.Level; - -import org.jboss.logmanager.LogContext; -import org.jboss.logmanager.Logger; - -import io.quarkus.vertx.http.runtime.devmode.Json; - -/** - * Allow controlling to the log levels - */ -public class LogController { - private static final org.jboss.logging.Logger LOG = org.jboss.logging.Logger.getLogger(LogController.class); - - private LogController() { - } - - public static Json.JsonArrayBuilder getLevels() { - Json.JsonArrayBuilder array = Json.array(); - for (String level : LEVELS) { - array.add(level); - } - return array; - } - - public static Json.JsonArrayBuilder getLoggers() { - LogContext logContext = LogContext.getLogContext(); - TreeMap loggerMap = new TreeMap<>(); - - Enumeration loggerNames = logContext.getLoggerNames(); - while (loggerNames.hasMoreElements()) { - String loggerName = loggerNames.nextElement(); - Json.JsonObjectBuilder jsonObject = getLogger(loggerName); - if (jsonObject != null) { - loggerMap.put(loggerName, jsonObject); - } - } - - List orderedLoggers = new ArrayList<>(loggerMap.values()); - Json.JsonArrayBuilder jsonArray = Json.array(); - jsonArray.addAll(orderedLoggers); - return jsonArray; - } - - public static Json.JsonObjectBuilder getLogger(String loggerName) { - LogContext logContext = LogContext.getLogContext(); - if (loggerName != null && !loggerName.isEmpty()) { - Logger logger = logContext.getLogger(loggerName); - Json.JsonObjectBuilder jsonObject = Json.object(); - jsonObject.put("name", loggerName); - jsonObject.put("effectiveLevel", getEffectiveLogLevel(logger)); - jsonObject.put("configuredLevel", getConfiguredLogLevel(logger)); - return jsonObject; - } - return null; - } - - public static void updateLogLevel(String loggerName, String levelValue) { - LogContext logContext = LogContext.getLogContext(); - Logger logger = logContext.getLogger(loggerName); - java.util.logging.Level level; - if (levelValue == null || levelValue.isBlank()) { - if (logger.getParent() != null) { - level = logger.getParent().getLevel(); - } else { - throw new IllegalArgumentException("The level of the root logger cannot be set to null"); - } - } else { - level = Level.parse(levelValue); - } - logger.setLevel(level); - LOG.info("Log level updated [" + loggerName + "] changed to [" + levelValue + "]"); - } - - private static String getConfiguredLogLevel(Logger logger) { - java.util.logging.Level level = logger.getLevel(); - return level != null ? level.getName() : null; - } - - private static String getEffectiveLogLevel(Logger logger) { - if (logger == null) { - return null; - } - if (logger.getLevel() != null) { - return logger.getLevel().getName(); - } - return getEffectiveLogLevel(logger.getParent()); - } - - public static final List LEVELS = List.of( - OFF.getName(), - SEVERE.getName(), - ERROR.getName(), - FATAL.getName(), - WARNING.getName(), - WARN.getName(), - INFO.getName(), - DEBUG.getName(), - TRACE.getName(), - CONFIG.getName(), - FINE.getName(), - FINER.getName(), - FINEST.getName(), - ALL.getName()); -} diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogStreamRecorder.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogStreamRecorder.java deleted file mode 100644 index 9ab22b2071d652..00000000000000 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogStreamRecorder.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.quarkus.vertx.http.runtime.logstream; - -import java.util.Optional; - -import io.quarkus.runtime.RuntimeValue; -import io.quarkus.runtime.annotations.Recorder; -import io.vertx.core.Handler; -import io.vertx.ext.web.RoutingContext; - -@Recorder -public class LogStreamRecorder { - - public RuntimeValue> logHandler(int size) { - return new RuntimeValue<>(Optional.of(new WebSocketLogHandler(size))); - } - - public Handler websocketHandler(RuntimeValue> handler) { - //we need to make sure this is created after logging - //is initialized, as it sets up a handler - return new LogStreamWebSocket(handler.getValue().get()); - } -} diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogStreamWebSocket.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogStreamWebSocket.java deleted file mode 100644 index 9c083adab4f66d..00000000000000 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/LogStreamWebSocket.java +++ /dev/null @@ -1,117 +0,0 @@ -package io.quarkus.vertx.http.runtime.logstream; - -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; - -import io.netty.handler.codec.http.HttpHeaderNames; -import io.quarkus.vertx.http.runtime.devmode.Json; -import io.vertx.core.AsyncResult; -import io.vertx.core.Handler; -import io.vertx.core.http.ServerWebSocket; -import io.vertx.ext.web.RoutingContext; - -/** - * Stream the log in json format over ws - */ -public class LogStreamWebSocket implements Handler { - private static final Logger log = Logger.getLogger(LogStreamWebSocket.class.getName()); - private final WebSocketLogHandler webSocketHandler; - - public LogStreamWebSocket(WebSocketLogHandler webSocketHandler) { - this.webSocketHandler = webSocketHandler; - } - - @Override - public void handle(RoutingContext event) { - if ("websocket".equalsIgnoreCase(event.request().getHeader(HttpHeaderNames.UPGRADE)) && !event.request().isEnded()) { - event.request().toWebSocket(new Handler>() { - @Override - public void handle(AsyncResult event) { - if (event.succeeded()) { - ServerWebSocket socket = event.result(); - SessionState state = new SessionState(socket); - - socket.closeHandler(new Handler() { - @Override - public void handle(Void event) { - stop(state); - } - }); - socket.textMessageHandler(new Handler() { - @Override - public void handle(String event) { - onMessage(event, state); - } - }); - socket.writeTextMessage(createInitMessage()); - start(state); - } else { - log.log(Level.SEVERE, "Failed to connect to log server", event.cause()); - } - } - }); - } else { - event.next(); - } - } - - public void onMessage(String message, SessionState session) { - if (message != null && !message.isEmpty()) { - if (message.equalsIgnoreCase(START)) { - start(session); - } else if (message.equalsIgnoreCase(STOP)) { - stop(session); - } else if (message.startsWith(UPDATE)) { - update(message); - } - } - } - - private void start(SessionState session) { - if (!session.started) { - session.started = true; - webSocketHandler.addSession(session.id, session.session); - } - } - - private void stop(SessionState session) { - webSocketHandler.removeSession(session.id); - session.started = false; - } - - private void update(String message) { - String[] p = message.split("\\|"); - if (p.length == 3) { - String loggerName = p[1]; - String levelVal = p[2]; - LogController.updateLogLevel(loggerName, levelVal); - } - } - - private String createInitMessage() { - Json.JsonObjectBuilder initMessage = Json.object(); - initMessage.put(TYPE, INIT); - initMessage.put("loggers", LogController.getLoggers()); - initMessage.put("levels", LogController.getLevels()); - return initMessage.build(); - } - - static class SessionState { - ServerWebSocket session; - String id; - boolean started; - - public SessionState(ServerWebSocket session) { - this.session = session; - this.id = UUID.randomUUID().toString(); - } - } - - private static final String TYPE = "type"; - private static final String INIT = "init"; - private static final String START = "start"; - private static final String STOP = "stop"; - private static final String UPDATE = "update"; - -} diff --git a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/WebSocketLogHandler.java b/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/WebSocketLogHandler.java deleted file mode 100644 index e9e011b5bf5080..00000000000000 --- a/extensions/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/logstream/WebSocketLogHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -package io.quarkus.vertx.http.runtime.logstream; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.LinkedBlockingQueue; - -import org.jboss.logmanager.ExtHandler; -import org.jboss.logmanager.ExtLogRecord; - -import io.vertx.core.http.ServerWebSocket; - -/** - * Log handler for Logger Manager - */ -public class WebSocketLogHandler extends ExtHandler { - private final LinkedBlockingQueue history; - - private static final Map SESSIONS = new ConcurrentHashMap<>(); - - public WebSocketLogHandler() { - this(50); - } - - public WebSocketLogHandler(int size) { - this.history = new LinkedBlockingQueue<>(size); - setFormatter(new JsonFormatter()); - } - - @Override - public final void doPublish(final ExtLogRecord record) { - // Don't log empty messages - if (record.getMessage() == null || record.getMessage().isEmpty()) { - return; - } - - if (isLoggable(record)) { - recordHistory(record); - streamToWebSocket(record); - } - } - - public void addSession(String id, ServerWebSocket session) { - SESSIONS.put(id, session); - - // Populate history - if (hasHistory()) { - List history = getHistory(); - for (ExtLogRecord lr : history) { - streamToWebSocket(lr); - } - } - } - - public void removeSession(String id) { - if (SESSIONS.containsKey(id)) { - SESSIONS.remove(id); - } - } - - private void recordHistory(final ExtLogRecord record) { - synchronized (this) { - try { - if (history.remainingCapacity() == 0) { - history.take(); - } - history.add(record); - } catch (InterruptedException ex) { - ex.printStackTrace(); - Thread.currentThread().interrupt(); - } - } - } - - private void streamToWebSocket(final ExtLogRecord record) { - if (!SESSIONS.isEmpty()) { - String message = getFormatter().format(record); - - for (ServerWebSocket session : SESSIONS.values()) { - try { - session.writeTextMessage(message); - } catch (Throwable ex) { - session.close(); - } - } - } - } - - public boolean hasHistory() { - return !history.isEmpty(); - } - - public List getHistory() { - return new ArrayList<>(history); - } - - public void clearHistory() { - this.history.clear(); - } -} diff --git a/extensions/vertx-http/runtime/src/test/java/io/quarkus/vertx/http/runtime/logstream/LogControllerTest.java b/extensions/vertx-http/runtime/src/test/java/io/quarkus/vertx/http/runtime/logstream/LogControllerTest.java deleted file mode 100644 index e9987cba0b956b..00000000000000 --- a/extensions/vertx-http/runtime/src/test/java/io/quarkus/vertx/http/runtime/logstream/LogControllerTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.quarkus.vertx.http.runtime.logstream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; - -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.jupiter.api.Test; - -class LogControllerTest { - - @Test - void updateLogLevelShouldUseParentWhenLevelIsNull() { - Logger logger = Logger.getLogger("foo.bar"); - logger.setLevel(Level.CONFIG); - Logger parent = Logger.getLogger("foo"); - LogController.updateLogLevel("foo.bar", null); - assertThat(logger.getLevel()).isEqualTo(parent.getLevel()); - } - - @Test - void updateLogLevelShouldThrowIAEinRootLoggerWhenLevelIsNull() { - assertThatIllegalArgumentException().isThrownBy(() -> LogController.updateLogLevel("", null)) - .withMessage("The level of the root logger cannot be set to null"); - } - -}