SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
3.4 KiB

package de.superx.sxrest;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import java.io.File;
import javax.servlet.http.HttpServletRequest;
import de.memtext.util.DateUtils;
import de.memtext.util.FileUtils;
import de.superx.common.SxUser;
import de.superx.servlet.SuperXManager;
@Path("/logs")
public class LogsProvider {
@Context
Request request;
@GET
@Path("/{logtype}")
@Produces(MediaType.TEXT_PLAIN)
public String printLogs(@PathParam("logtype") String logtype,
@QueryParam("loglines") Integer loglines,
@Context HttpServletRequest request) {
String returntext="";
SxUser user = (SxUser) request.getSession().getAttribute("user");
String mandantenid= (String) request.getSession().getAttribute("MandantenID");
if(mandantenid==null || mandantenid.equals(""))
mandantenid="default";
if (user == null || !user.isAdmin()) {
returntext="Fehlende Rechte";
}
else
{
if(logtype.equals("activity")|| logtype.equals("fmsql")|| logtype.equals("sql") || logtype.equals("xml"))
{
returntext = getMaskLogs(mandantenid,logtype);
}
else
returntext=getTomcatLogs(mandantenid,logtype,loglines);
}
return returntext;
}
private String getMaskLogs(String mandantenid,String logtype)
{
String logString;
if(mandantenid.equalsIgnoreCase(SuperXManager.getLastMaskenSqlMandantid()))
{
switch (logtype) {
case "activity" :
logString=SuperXManager.activityLog.toString().replace("<br>", "\n");
break;
case "fmsql" :
logString=SuperXManager.getLastFMMaskenSql();
break;
case "sql" :
logString=SuperXManager.getLastMaskenSql();
break;
case "xml" :
logString=SuperXManager.getLastXml();
break;
default :
logString="Protokoll "+logtype+ " kann nicht gelesen werden";
}
}
else
logString="Bitte wiederholen Sie den Aufruf mit dem jew. Mandant";
return logString;
}
private String getTomcatLogs(String mandantenid,String logtype, Integer loglines)
{
String logFilePath="";
if(loglines==null )
loglines=100;
switch (logtype) {
case "serverlog" :
logFilePath=System.getProperty("catalina.base")+File.separator+ "logs"+File.separator+"catalina.out";
break;
case "serverlogsql" :
logFilePath=System.getProperty("catalina.base")+File.separator+ "logs"+File.separator+"superx_"+mandantenid+".log";
break;
case "serverlogxml" :
logFilePath=System.getProperty("catalina.base")+File.separator+ "logs"+File.separator+"superx_"+mandantenid+"_xml.log";
break;
default:
throw new RuntimeException("Logtype " + logtype + " not supported!");
}
String logString="Protokoll "+logFilePath+ " kann nicht gelesen werden";
File logfile = new File(logFilePath);
if(logfile.exists())
{
try {
logString=FileUtils.tail(logfile,Integer.valueOf(loglines));
}
catch (Exception e)
{
logString+=": "+ e.toString();
}
}
return logString;
}
}