This repository has been archived by the owner on Feb 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.jsp
116 lines (96 loc) · 3.49 KB
/
logs.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!--
Copyright (C) 2020 Bonitasoft S.A.
Bonitasoft is a trademark of Bonitasoft SA.
This software file is BONITASOFT CONFIDENTIAL. Not For Distribution.
For commercial licensing information, contact:
Bonitasoft, 32 rue Gustave Eiffel – 38000 Grenoble
or Bonitasoft US, 51 Federal Street, Suite 305, San Francisco, CA 94107
-->
<%@page import="java.net.InetAddress" %>
<%@page import="java.util.List" %>
<%@page import="java.util.logging.Level" %>
<%@page import="java.util.logging.Logger" %>
<%@page import="org.bonitasoft.engine.session.*" %>
<%!
private String getHostname() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (final Exception ignored) {
return "UNKNOWN";
}
}
%>
<%
Logger jspLogger = Logger.getLogger("org.bonitasoft.tooling.log.jsp");
jspLogger.setLevel(Level.INFO); // ensure logs are generated
// Authorization checks
APISession apiSession = (APISession) session.getAttribute("apiSession");
if (apiSession == null) {
jspLogger.log(Level.WARNING, "Unauthenticated user tried to access to the Logger Level configuration");
response.sendError(403);
return;
}
String userName = (String) session.getAttribute("username");
List<String> profiles = apiSession.getProfiles();
boolean isAdministrator = profiles.contains("Administrator");
boolean isTechnicalUser = apiSession.isTechnicalUser();
if (!isAdministrator && !isTechnicalUser) {
jspLogger.log(Level.WARNING, "Non Administrator '" + userName + "' user tried to access to the Logger Level configuration");
response.sendError(403);
return;
}
String loggerName = request.getParameter("loggerName");
if (loggerName == null) {
response.sendError(400, "The loggerName parameter is mandatory");
return;
}
String loggerLevel = request.getParameter("loggerLevel");
Logger logger = Logger.getLogger(loggerName);
Level originalLogLevel = logger.getLevel();
boolean isLoggerInfoOnly = loggerLevel == null;
%>
<!DOCTYPE html>
<html>
<head>
<title>Bonita Live Logger Level Configuration</title>
</head>
<body>
<h1>Bonita Live Logger Level Configuration</h1>
Host: <b><%= getHostname() %></b><br/>
User: <b><%= userName %></b><br/>
<p>
<% if (isLoggerInfoOnly) {
jspLogger.log(Level.INFO, "User '" + userName + "' accessed to the Logger Level configuration - Information only");
%>
<b>Providing logger info only</b>
<p/>
Logger: <b><%= loggerName %></b><br/>
Log level: <b><%= originalLogLevel %></b><br/>
<% } else {
logger.setLevel(Level.parse(loggerLevel));
Level newLogLevel = logger.getLevel();
String actualLoggerName = logger.getName();
jspLogger.log(Level.INFO, "User '" + userName + "' set the log level of logger " + actualLoggerName + " from " + originalLogLevel + " to " + newLogLevel);
%>
<b>Logger Level change</b>
<p/>
Requested logger: <b><%= loggerName %></b><br/>
Requested level: <b><%= loggerLevel %></b>
<p/>
Actual logger: <b><%= actualLoggerName %></b><br/>
Orig log level: <b><%= originalLogLevel %></b><br/>
New log level: <b><%= newLogLevel %></b>
<% } %>
<p/>
Loggable levels:
<ul>
<li><%= Level.SEVERE %>: <%= logger.isLoggable(Level.SEVERE) %>
<li><%= Level.WARNING %>: <%= logger.isLoggable(Level.WARNING) %>
<li><%= Level.INFO %>: <%= logger.isLoggable(Level.INFO) %>
<li><%= Level.CONFIG %>: <%= logger.isLoggable(Level.CONFIG) %>
<li><%= Level.FINE %>: <%= logger.isLoggable(Level.FINE) %>
<li><%= Level.FINER %>: <%= logger.isLoggable(Level.FINER) %>
<li><%= Level.FINEST %>: <%= logger.isLoggable(Level.FINEST) %>
</ul>
</body>
</html>