From 15ed25a13d5f8340dfecef50d23173aef45af125 Mon Sep 17 00:00:00 2001 From: ulrich Date: Wed, 31 Mar 2021 19:34:01 +0000 Subject: [PATCH] OMXPlayer Log (in Arbeit) --- src/de/uhilger/avdirektor/Server.java | 2 + src/de/uhilger/avdirektor/handler/PlayHandler.java | 4 ++ src/de/uhilger/avdirektor/OMXLogLeser.java | 51 +++++++++++++++++++++++++ src/de/uhilger/avdirektor/handler/LogHandler.java | 30 +++++++++++++++ 4 files changed, 87 insertions(+), 0 deletions(-) diff --git a/src/de/uhilger/avdirektor/OMXLogLeser.java b/src/de/uhilger/avdirektor/OMXLogLeser.java new file mode 100644 index 0000000..80b2765 --- /dev/null +++ b/src/de/uhilger/avdirektor/OMXLogLeser.java @@ -0,0 +1,51 @@ +package de.uhilger.avdirektor; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.logging.Logger; + +/** + * + * @author ulrich + */ +public class OMXLogLeser { + + private static final Logger logger = Logger.getLogger(OMXLogLeser.class.getName()); + + public String lesen(File logfile) throws FileNotFoundException, IOException { + InputStream is = new FileInputStream(logfile); + BufferedReader r = new BufferedReader(new InputStreamReader(is)); + String firstLine = r.readLine(); + String lastLine = ""; + if(firstLine != null) { + long size = logfile.length(); + long pos = size - (long) 1000; + logger.info("Size: " + size + ", Pos: " + pos); // 2.341.930 Bytes + long skipped = r.skip(pos); + logger.info("skipped: " + skipped); + String line = r.readLine(); + while(line != null) { + lastLine = line; + logger.info(lastLine); + line = r.readLine(); + } + } + r.close(); + is.close(); + StringBuilder sb = new StringBuilder(); + sb.append("\r\n---"); + sb.append("\r\nfirst line:\r\n"); + sb.append(firstLine); + sb.append("\r\n\r\nlastLine\r\n"); + sb.append(lastLine); + String lines = sb.toString(); + logger.info(lines); + return lines; + } + +} diff --git a/src/de/uhilger/avdirektor/Server.java b/src/de/uhilger/avdirektor/Server.java index e768c81..fd02b99 100644 --- a/src/de/uhilger/avdirektor/Server.java +++ b/src/de/uhilger/avdirektor/Server.java @@ -21,6 +21,7 @@ import com.sun.net.httpserver.HttpServer; import de.uhilger.avdirektor.handler.CmdHandler; import de.uhilger.avdirektor.handler.FileHandler; +import de.uhilger.avdirektor.handler.LogHandler; import de.uhilger.avdirektor.handler.OMXPlayer; import de.uhilger.avdirektor.handler.PingHandler; import de.uhilger.avdirektor.handler.PlayHandler; @@ -61,6 +62,7 @@ server.createContext("/avd/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); server.createContext("/avd/ping", new PingHandler(OMXPlayer.F_PING)); server.createContext("/avd/server/stop", new StopServerHandler()); + server.createContext("/avd/log", new LogHandler()); server.createContext("/avd/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); //server.setExecutor(null); // creates a default executor server.setExecutor(Executors.newFixedThreadPool(20)); diff --git a/src/de/uhilger/avdirektor/handler/LogHandler.java b/src/de/uhilger/avdirektor/handler/LogHandler.java new file mode 100644 index 0000000..8d49d27 --- /dev/null +++ b/src/de/uhilger/avdirektor/handler/LogHandler.java @@ -0,0 +1,30 @@ +package de.uhilger.avdirektor.handler; + +import com.sun.net.httpserver.HttpExchange; +import de.uhilger.avdirektor.OMXLogLeser; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author ulrich + */ +public class LogHandler extends AbstractHandler { + + private static final Logger logger = Logger.getLogger(LogHandler.class.getName()); + + @Override + protected String process(HttpExchange t, String params) { + OMXLogLeser leser = new OMXLogLeser(); + String lines = "Log nicht lesbar."; + try { + lines = leser.lesen(new File("/home/ulrich/work/avd/omxplayer.log")); + } catch (IOException ex) { + Logger.getLogger(LogHandler.class.getName()).log(Level.SEVERE, null, ex); + } + return lines; + } + +} diff --git a/src/de/uhilger/avdirektor/handler/PlayHandler.java b/src/de/uhilger/avdirektor/handler/PlayHandler.java index 61658bd..aa32fcd 100644 --- a/src/de/uhilger/avdirektor/handler/PlayHandler.java +++ b/src/de/uhilger/avdirektor/handler/PlayHandler.java @@ -67,6 +67,10 @@ params.append(getParam(map, "th")); params.append(" --timeout "); params.append(getParam(map, "ti")); + String log = getParam(map, "log"); + if(log != null && log.equalsIgnoreCase("true")) { + params.append(" --genlog"); + } return params; } -- Gitblit v1.9.3