Skip to content

Commit

Permalink
root logger
Browse files Browse the repository at this point in the history
  • Loading branch information
turboFei committed Dec 23, 2024
1 parent 82c25af commit 6663cec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class LoggerResource extends ApiRequestContext {
description = "Get the logger level, return all loggers if no name specified.")
@GET
def getLoggerLevel(@QueryParam("name") name: String): LoggerInfos = {
if (StringUtils.isNotBlank(name)) {
if (null != name) {
new LoggerInfos().addLoggersItem(
new LoggerInfo().name(name).level(LogManager.getLogger(name).getLevel.toString))
} else {
Expand All @@ -72,6 +72,6 @@ class LoggerResource extends ApiRequestContext {
val newLevel = Level.toLevel(request.getLevel)
Configurator.setLevel(loggerName, newLevel)
new HandleResponse().success(true).message(
s"Set logger $loggerName level from $originalLevel to $newLevel")
s"Set logger `$loggerName` level from `$originalLevel` to `$newLevel`.`")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,27 @@ abstract class ApiV1BaseResourceSuite extends HttpTestHelper {
assert(loggers.exists(l => l.getName == loggerName && l.getLevel == "DEBUG"))
// root logger
assert(loggers.exists(l => l.getName == "" && l.getLevel == "INFO"))

// update root logger level
val response5 = webTarget.path("loggers").request(MediaType.APPLICATION_JSON).post(Entity.entity(
new LoggerInfo().name("").level("DEBUG"),
MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_OK == response5.getStatus)

// check root logger level is DEBUG
val response6 = webTarget.path("loggers")
.queryParam("name", "")
.request(MediaType.APPLICATION_JSON).get()
assert(HttpServletResponse.SC_OK == response6.getStatus)
val loggerInfo3 = response6.readEntity(classOf[LoggerInfos]).getLoggers.get(0)
assert("" == loggerInfo3.getName)
assert(loggerInfo3.getLevel == "DEBUG")

// reset root logger level
val response7 = webTarget.path("loggers").request(MediaType.APPLICATION_JSON).post(Entity.entity(
new LoggerInfo().name(loggerName).level("INFO"),
MediaType.APPLICATION_JSON))
assert(HttpServletResponse.SC_OK == response7.getStatus)
}

test("thread_dump") {
Expand Down

0 comments on commit 6663cec

Please sign in to comment.