Commit c3af6ac7 authored by Matija Obreza's avatar Matija Obreza

Loggers layout and using PageImpl

parent de55d192
......@@ -13,6 +13,8 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.genesys2.server.servlet.controller.AdminController;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -26,100 +28,98 @@ import org.springframework.web.bind.annotation.RequestParam;
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class LoggerController {
public static final Log LOG = LogFactory.getLog(AdminController.class);
@Value("${list.logger.pagination.size}")
int size;
private Logger logger;
@RequestMapping(method = RequestMethod.GET, value = "/adjustLogger")
public String adjustLogger(Model model, @RequestParam(value = "page", defaultValue = "1") Integer page){
int size = this.size;
//first element on page
int firstelement = (page==null)?0:(page-1) * size;
List<Logger> allLoggers = getAllLoggers();
int totalPage = allLoggers.size()/size + 1;
List<Logger> loggers = new ArrayList<>();
if(size > (allLoggers.size() - firstelement)){
size = allLoggers.size() - firstelement;
}
//copy part of array
for(int i = 0; i<size; i++){
loggers.add(allLoggers.get(firstelement+i));
}
model.addAttribute("loggers", loggers);
model.addAttribute("pageNumber", page);
model.addAttribute("totalPage", totalPage);
return "/admin/adjust-logger/loggersList";
}
@RequestMapping(method = RequestMethod.GET, value = "/adjustLoggerPage/{loggerName}")
public String adjustLoggerPage(Model model, @PathVariable(value = "loggerName")String loggerName){
if (loggerName != null && "root".equalsIgnoreCase(loggerName))
logger = LogManager.getRootLogger();
else
logger = LogManager.getLogger(loggerName);
model.addAttribute("logger", logger);
model.addAttribute("appenders", logger.getRootLogger().getAllAppenders());
return "/admin/adjust-logger/adjustLoggerPage";
}
@RequestMapping(method = RequestMethod.POST, value = "/changeLoger")
public String changeLogger(@RequestParam(value = "loggerLevel") String loggerLevel,
@RequestParam(value = "loggerName") String loggerName){
if (loggerName != null && "root".equalsIgnoreCase(loggerName))
logger = LogManager.getRootLogger();
else
logger = LogManager.getLogger(loggerName);
if (logger != null) {
LOG.debug("Got logger: " + logger.getName());
logger.setLevel(loggerLevel == null ? null : Level.toLevel(loggerLevel));
}
return "redirect:/logger/adjustLoggerPage/" + loggerName+".";
}
private List<Logger> getAllLoggers(){
Enumeration<Logger> en = LogManager.getCurrentLoggers();
List<Logger> loggers = new ArrayList<>();
while (en.hasMoreElements()) {
loggers.add(en.nextElement());
}
loggers.add(LogManager.getRootLogger());
Collections.sort(loggers, new Comparator<Logger>() {
@Override
public int compare(Logger o1, Logger o2) {
// root logger is on the top
if (LogManager.getRootLogger() == o1) {
return -1;
}
if (LogManager.getRootLogger() == o2) {
return 1;
}
// otherwise sort by name
return o1.getName().compareTo(o2.getName());
}
});
return loggers;
}
@RequestMapping(method = RequestMethod.POST, value = "/addLoger")
public String addLogger(@RequestParam(value = "nameNewLogger") String nameNewLogger, Model model){
Logger.getLogger(nameNewLogger);
return "redirect:/admin/adjustLogger";
}
public static final Log LOG = LogFactory.getLog(AdminController.class);
@Value("${paginator.default.pageSize}")
int defaultPageSize;
@RequestMapping(method = RequestMethod.GET, value = "/adjustLogger")
public String adjustLogger(Model model, @RequestParam(value = "page", defaultValue = "1") int page) {
// first element on page
int firstelement = (page - 1) * defaultPageSize;
List<Logger> allLoggers = getAllLoggers();
List<Logger> loggers = new ArrayList<>();
// copy part of array
for (int i = 0; i < defaultPageSize && i < allLoggers.size(); i++) {
loggers.add(allLoggers.get(firstelement + i));
}
PageImpl<Logger> pagedData = new PageImpl<Logger>(loggers, new PageRequest(page, defaultPageSize), allLoggers.size());
model.addAttribute("loggers", pagedData);
return "/admin/adjust-logger/loggersList";
}
@RequestMapping(method = RequestMethod.GET, value = "/adjustLoggerPage/{loggerName}")
public String adjustLoggerPage(Model model, @PathVariable(value = "loggerName") String loggerName) {
Logger logger;
if (loggerName != null && "root".equalsIgnoreCase(loggerName))
logger = LogManager.getRootLogger();
else
logger = LogManager.getLogger(loggerName);
model.addAttribute("logger", logger);
model.addAttribute("appenders", logger.getRootLogger().getAllAppenders());
return "/admin/adjust-logger/adjustLoggerPage";
}
@RequestMapping(method = RequestMethod.POST, value = "/changeLoger")
public String changeLogger(@RequestParam(value = "loggerLevel") String loggerLevel, @RequestParam(value = "loggerName") String loggerName) {
Logger logger;
if (loggerName == null || "root".equalsIgnoreCase(loggerName)) {
logger = LogManager.getRootLogger();
} else {
logger = LogManager.getLogger(loggerName);
}
if (logger != null) {
LOG.debug("Got logger: " + logger.getName());
logger.setLevel(loggerLevel == null ? null : Level.toLevel(loggerLevel));
}
return "redirect:/admin/logger/adjustLoggerPage/" + loggerName + ".";
}
private List<Logger> getAllLoggers() {
Enumeration<Logger> en = LogManager.getCurrentLoggers();
List<Logger> loggers = new ArrayList<>();
while (en.hasMoreElements()) {
Logger logger = en.nextElement();
if (logger.getLevel() != null)
loggers.add(logger);
}
loggers.add(LogManager.getRootLogger());
Collections.sort(loggers, new Comparator<Logger>() {
@Override
public int compare(Logger o1, Logger o2) {
// root logger is on the top
if (LogManager.getRootLogger() == o1) {
return -1;
}
if (LogManager.getRootLogger() == o2) {
return 1;
}
// otherwise sort by name
return o1.getName().compareTo(o2.getName());
}
});
return loggers;
}
@RequestMapping(method = RequestMethod.POST, value = "/addLoger")
public String addLogger(@RequestParam(value = "nameNewLogger") String nameNewLogger, Model model) {
Logger logger = Logger.getLogger(nameNewLogger);
logger.setLevel(Level.INFO);
return "redirect:/admin/logger/adjustLogger";
}
}
......@@ -15,7 +15,7 @@
#-------------------------------------------------------------------------------
#Paginator
paginator.default.pageSize=2
paginator.default.pageSize=50
paginator.default.fastStep=3
paginator.default.maxPage=4
......
......@@ -392,8 +392,6 @@ metadata.page.title=Datasets
metadata.page.view.title=Dataset details
metadata.download-dwca=Download ZIP
page.login=Login
adjust.loggers.list.page=List of loggers
adjust.logger.edit.page=Adjust logger configuration page
traits.page.title=Descriptors
trait-list=Descriptors
......@@ -410,8 +408,6 @@ menu.report-an-issue=Report an issue
menu.scm=Source code
menu.translate=Translate Genesys
logger.name=Logger name
article.edit-article=Editing article
article.slug=Article slug (URL)
article.title=Article title
......@@ -582,3 +578,11 @@ cache.stat.map.ownedEntryCount=Owned cache entries
cache.stat.map.lockedEntryCount=Locked cache entries
cache.stat.map.puts=Number of writes to cache
cache.stat.map.hits=Number of cache hits
loggers.list.page=List of configured loggers
logger.add-logger=Add logger
logger.edit.page=Logger configuration page
logger.name=Logger name
logger.log-level=Log level
logger.appenders=Log appenders
......@@ -5,60 +5,55 @@
<html>
<head>
<title><spring:message code="adjust.logger.edit.page"/></title>
<title><spring:message code="logger.edit.page"/></title>
</head>
<body>
<h1><spring:message code="adjust.logger.edit.page"/></h1>
<h1><spring:message code="logger.edit.page"/></h1>
<div class="logger-detail">
<div class="logger-name">
<div>Loger name - ${logger.name}</div>
<div class="row">
<div class="col-sm-4"><label><spring:message code="logger.name" /></label></div>
<div class="col-sm-8"><p class=".form-control-static">${logger.name}</p></div>
</div>
<div class="logger-level">
<div>Loger level - ${logger.level}</div>
<div class="row">
<div class="col-sm-4"><label><spring:message code="logger.log-level" /><label></div>
<div class="col-sm-8 control-label"><p class=".form-control-static">${logger.level}</p></div>
</div>
<div class="all-appenders">
Appenders:
<ul>
<ul class="funny-list">
<c:forEach items="${appenders}" var="appender">
<li>
${appender.name}
<c:out value="${appender.name}" />
</li>
</c:forEach>
</ul>
</div>
<div>
<div class="change-level-label">Change level</div>
<form method="post" class="form-change-level form-inline" action=<c:url value="/admin/logger/changeLoger"/> >
</ul>
<form method="post" class="form-horizontal" action=<c:url value="/admin/logger/changeLoger"/> >
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="hidden" name="loggerName" value="${logger.name}"/>
<div class="form-group">
<label class="col-sm-4 control-label"><spring:message code="logger.log-level" /></label>
<div class="col-sm-8">
<select class="form-control" name="loggerLevel">
<c:forTokens items="all,debug,info,warn,error,fatal,off,trace" delims="," var="level">
<option value="${level}">
<option value="${level}" ${level == logger.level.toString().toLowerCase() ? "selected" : ""}>
${level}
</option>
</c:forTokens>
</select>
</div>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="form-group">
<input type="submit" class="btn btn-group-sm">
<div class="col-sm-offset-4 col-sm-8">
<input type="submit" class="btn btn-group-sm" value="<spring:message code="save" />">
<a class="btn btn-default" href="<c:url value="/admin/logger/adjustLogger" />"><spring:message code="cancel" /></a>
</div>
<div class="form-group">
<a class="btn btn-default" href="<c:url value="/admin/logger/adjustLogger" />">Cancel</a>
</div>
</form>
</div>
</div>
</body>
</html>
......@@ -5,54 +5,43 @@
<html>
<head>
<title><spring:message code="adjust.loggers.list.page"/></title>
<title><spring:message code="loggers.list.page"/></title>
</head>
<body>
<h1><spring:message code="adjust.loggers.list.page"/></h1>
<h1><spring:message code="loggers.list.page"/></h1>
<div class="main-col-header clearfix">
<div class="nav-header pull-left">
<div class="results"><spring:message code="paged.totalElements" arguments="${totalPage}" /></div>
<div class="results"><spring:message code="paged.totalElements" arguments="${loggers.totalElements}" /></div>
<div class="pagination">
<spring:message code="paged.pageOfPages" arguments="${pageNumber},${totalPage}" />
<a class="${pageNumber-1 eq 0 ? 'disabled' :''}" href="?page=${pageNumber-1 eq 0 ? 1 : pageNumber-1}"><spring:message code="pagination.previous-page" /></a> <a href="?page=${pageNumber + 1}"><spring:message code="pagination.next-page" /></a>
<spring:message code="paged.pageOfPages" arguments="${loggers.number},${loggers.totalPages}" />
<a class="${pageNumber-1 eq 0 ? 'disabled' :''}" href="?page=${loggers.number-1 eq 0 ? 1 : loggers.number-1}"><spring:message code="pagination.previous-page" /></a> <a href="?page=${loggers.number + 1}"><spring:message code="pagination.next-page" /></a>
</div>
</div>
</div>
<div>
<div class="change-level-label">Add logger</div>
<form method="post" class="form-change-level form-inline" action=<c:url value="/admin/logger/addLoger"/> >
<div class="form-group col-sm-3">
<div class="row">
<form method="post" action=<c:url value="/admin/logger/addLoger"/> >
<div class="form-group col-sm-10">
<input class="form-control" type="text" name="nameNewLogger" placeholder="com.example.package.Class"/>
</div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="form-group col-sm-3">
<input type="submit" class="btn btn-group-sm">
<div class="form-group col-sm-2">
<input type="submit" class="btn" value="<spring:message code="logger.add-logger" />" />
</div>
</form>
</div>
<table class="all-loggers">
<thead>
<tr>
<td><spring:message code="logger.name" /></td>
</tr>
</thead>
<tbody>
<c:forEach items="${loggers}" var="logger" varStatus="status">
<tr class="${status.count % 2 == 0 ? 'even' : 'odd'} particular-logger">
<td><a class="adjust-logger-config" href="<c:url value="/admin/logger/adjustLoggerPage/${logger.name}." />">${logger.name}</a></td>
</tr>
<ul class="funny-list">
<c:forEach items="${loggers.content}" var="logger" varStatus="status">
<li class="${status.count % 2 == 0 ? 'even' : 'odd'}">
<a class="adjust-logger-config" href="<c:url value="/admin/logger/adjustLoggerPage/${logger.name}." />">${logger.name}</a>
<div class="pull-right"><c:out value="${logger.level}" /></div>
</li>
</c:forEach>
</tbody>
</table>
</ul>
</body>
</html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment