Commit cfe09784 authored by Alexander Basov's avatar Alexander Basov Committed by Matija Obreza
Browse files

Adjust Logger configuration (+1 squashed commit)

Squashed commits:
[7e0dffc] made task
parent d0013079
......@@ -16,26 +16,23 @@
package org.genesys2.server.servlet.controller;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hazelcast.core.DistributedObject;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.monitor.LocalMapStats;
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.genesys2.server.model.genesys.Accession;
import org.genesys2.server.persistence.domain.GenesysLowlevelRepository;
import org.genesys2.server.service.CountryNamesUpdater;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.MappingService;
import org.genesys2.server.service.*;
import org.genesys2.server.service.impl.ContentSanitizer;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
import org.genesys2.server.service.worker.ElasticUpdater;
......@@ -43,6 +40,7 @@ import org.genesys2.server.service.worker.ITPGRFAStatusUpdater;
import org.genesys2.server.service.worker.InstituteUpdater;
import org.genesys2.server.service.worker.SGSVUpdate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.core.task.TaskExecutor;
......@@ -50,23 +48,21 @@ import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hazelcast.core.DistributedObject;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import com.hazelcast.monitor.LocalMapStats;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
@Controller
@RequestMapping("/admin")
@PreAuthorize("hasRole('ADMINISTRATOR')")
public class AdminController {
public static final Log LOG = LogFactory.getLog(AdminController.class);
@Autowired
InstituteUpdater instituteUpdater;
......@@ -109,6 +105,11 @@ public class AdminController {
@Autowired
private GenesysFilterService filterService;
@Value("${list.logger.pagination.size}")
int size;
private Logger logger;
@RequestMapping("/")
public String root(Model model) {
return "/admin/index";
......@@ -200,6 +201,95 @@ public class AdminController {
return "redirect:/admin/";
}
@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:/admin/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";
}
@RequestMapping(method = RequestMethod.POST, value = "/convertNames")
public String convertNames() {
// Convert {@link AllAccenames} to Aliases
......@@ -250,7 +340,7 @@ public class AdminController {
aliases.clear();
prevAccnId = rs.getLong(1);
}
aliases.add(new Object[] { rs.getLong(7), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getString(5) });
aliases.add(new Object[]{rs.getLong(7), rs.getString(2), rs.getString(3), rs.getInt(4), rs.getString(5)});
}
private void cleanup(long accessionId, List<Object[]> existingAliases) {
......@@ -453,4 +543,6 @@ public class AdminController {
return mapStats;
}
}
}
......@@ -392,6 +392,8 @@ 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
......@@ -408,6 +410,8 @@ 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
......
......@@ -71,6 +71,8 @@ mail.smtp.starttls.enable=true
mail.smtp.auth=true
mail.transport.protocol=smtp
list.logger.pagination.size=50
mail.async=true
mail.debug.message= Email has been sent succesfully\n\
Details:\n\
......@@ -126,6 +128,8 @@ cache.tileserver.eviction-policy=LRU
# Connection to Elasticsearch
elasticsearch.url=http://localhost:9200/
transifex.project=genesys-dev
transifex.username=Alexandr19011990
transifex.password=Alexandr19011990
......
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<html>
<head>
<title><spring:message code="adjust.logger.edit.page"/></title>
</head>
<body>
<h1><spring:message code="adjust.logger.edit.page"/></h1>
<div class="logger-detail">
<div class="logger-name">
<div>Loger name - ${logger.name}</div>
</div>
<div class="logger-level">
<div>Loger level - ${logger.level}</div>
</div>
<div class="all-appenders">
Appenders:
<ul>
<c:forEach items="${appenders}" var="appender">
<li>
${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/changeLoger"/> >
<input type="hidden" name="loggerName" value="${logger.name}"/>
<div class="form-group">
<select class="form-control" name="loggerLevel">
<c:forTokens items="all,debug,info,warn,error,fatal,off,trace" delims="," var="level">
<option value="${level}">
${level}
</option>
</c:forTokens>
</select>
</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>
<div class="form-group">
<a class="btn btn-default" href="<c:url value="/admin/adjustLogger" />">Cancel</a>
</div>
</form>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<%@include file="/WEB-INF/jsp/init.jsp" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<html>
<head>
<title><spring:message code="adjust.loggers.list.page"/></title>
</head>
<body>
<h1><spring:message code="adjust.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="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>
</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/addLoger"/> >
<div class="form-group col-sm-3">
<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>
</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/adjustLoggerPage/${logger.name}." />">${logger.name}</a></td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
......@@ -126,5 +126,9 @@
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
</form>
<div class="adjust-logger-block">
<a class="btn btn-default" href="<c:url value="/admin/adjustLogger" />">Adjust logger</a>
</div>
</body>
</html>
\ No newline at end of file
......@@ -22,6 +22,16 @@ summary {
display: block;
}
.change-level-label{
background: #A3A3A3;
color: #fff;
font-size: 14px;
font-weight: bold;
margin-bottom: 3px;
padding: 2px 10px;
text-transform: uppercase;
}
audio,
canvas,
video {
......
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