1
2
3
4
5
6
7
8
9
10
11 package psiprobe.controllers.logs;
12
13 import jakarta.servlet.http.HttpServletRequest;
14 import jakarta.servlet.http.HttpServletResponse;
15
16 import java.util.Arrays;
17
18 import org.springframework.beans.factory.annotation.Value;
19 import org.springframework.stereotype.Controller;
20 import org.springframework.web.bind.ServletRequestUtils;
21 import org.springframework.web.bind.annotation.RequestMapping;
22 import org.springframework.web.servlet.ModelAndView;
23
24 import psiprobe.tools.logging.LogDestination;
25 import psiprobe.tools.logging.jdk.Jdk14HandlerAccessor;
26 import psiprobe.tools.logging.log4j.Log4JAppenderAccessor;
27 import psiprobe.tools.logging.log4j2.Log4J2AppenderAccessor;
28 import psiprobe.tools.logging.logback.LogbackAppenderAccessor;
29 import psiprobe.tools.logging.logback13.Logback13AppenderAccessor;
30 import psiprobe.tools.logging.slf4jlogback.TomcatSlf4jLogbackAppenderAccessor;
31 import psiprobe.tools.logging.slf4jlogback13.TomcatSlf4jLogback13AppenderAccessor;
32
33
34
35
36 @Controller
37 public class ChangeLogLevelController extends AbstractLogHandlerController {
38
39 @RequestMapping(path = "/adm/changeloglevel.ajax")
40 @Override
41 public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
42 throws Exception {
43 return super.handleRequest(request, response);
44 }
45
46 @Override
47 protected ModelAndView handleLogFile(HttpServletRequest request, HttpServletResponse response,
48 LogDestination logDest) throws Exception {
49
50 String level = ServletRequestUtils.getRequiredStringParameter(request, "level");
51 if (Arrays.asList(logDest.getValidLevels()).contains(level)) {
52 if (logDest instanceof Log4JAppenderAccessor) {
53 Log4JAppenderAccessor accessor = (Log4JAppenderAccessor) logDest;
54 accessor.getLoggerAccessor().setLevel(level);
55 } else if (logDest instanceof Log4J2AppenderAccessor) {
56 Log4J2AppenderAccessor accessor = (Log4J2AppenderAccessor) logDest;
57 accessor.getLoggerAccessor().setLevel(level);
58 } else if (logDest instanceof Jdk14HandlerAccessor) {
59 Jdk14HandlerAccessor accessor = (Jdk14HandlerAccessor) logDest;
60 accessor.getLoggerAccessor().setLevel(level);
61 } else if (logDest instanceof LogbackAppenderAccessor) {
62 LogbackAppenderAccessor accessor = (LogbackAppenderAccessor) logDest;
63 accessor.getLoggerAccessor().setLevel(level);
64 } else if (logDest instanceof Logback13AppenderAccessor) {
65 Logback13AppenderAccessor accessor = (Logback13AppenderAccessor) logDest;
66 accessor.getLoggerAccessor().setLevel(level);
67 } else if (logDest instanceof TomcatSlf4jLogbackAppenderAccessor) {
68 TomcatSlf4jLogbackAppenderAccessor accessor = (TomcatSlf4jLogbackAppenderAccessor) logDest;
69 accessor.getLoggerAccessor().setLevel(level);
70 } else if (logDest instanceof TomcatSlf4jLogback13AppenderAccessor) {
71 TomcatSlf4jLogback13AppenderAccessor accessor =
72 (TomcatSlf4jLogback13AppenderAccessor) logDest;
73 accessor.getLoggerAccessor().setLevel(level);
74 }
75 }
76 return null;
77 }
78
79 @Value("")
80 @Override
81 public void setViewName(String viewName) {
82 super.setViewName(viewName);
83 }
84
85 }