资源简介

通过http访问查看tomcat实时日志

资源截图

代码片段和文件信息

package com.xxg.websocket;

import java.io.IOException;
import java.io.InputStream;

import javax.websocket.OnClose;
import javax.websocket.onerror;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;

@ServerEndpoint(“/log“)
public class LogWebSocketHandle {

private Process process;
private InputStream inputStream;

/**
 * 新的WebSocket请求开启
 */
@OnOpen
public void onOpen(Session session) {
try {
// 执行tail -f命令
process = Runtime.getRuntime().exec(“tail -f /home/tomcat/logs/catalina.out“);
inputStream = process.getInputStream();

// 一定要启动新的线程,防止InputStream阻塞处理WebSocket的线程
TailLogThread thread = new TailLogThread(inputStream session);
thread.start();
} catch (IOException e) {
e.printStackTrace();
}
}

/**
 * WebSocket请求关闭
 */
@OnClose
public void onClose() {
try {
if(inputStream != null)
inputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
if(process != null)
process.destroy();
}

@onerror
public void onerror(Throwable thr) {
thr.printStackTrace();
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        293  2020-04-16 18:46  websocket-tail-demo\.git\config

     文件         73  2020-04-16 18:46  websocket-tail-demo\.git\description

     文件        106  2020-04-17 09:30  websocket-tail-demo\.git\FETCH_HEAD

     文件         23  2020-04-16 18:46  websocket-tail-demo\.git\HEAD

     文件        478  2020-04-16 18:46  websocket-tail-demo\.git\hooks\applypatch-msg.sample

     文件        896  2020-04-16 18:46  websocket-tail-demo\.git\hooks\commit-msg.sample

     文件       3327  2020-04-16 18:46  websocket-tail-demo\.git\hooks\fsmonitor-watchman.sample

     文件        189  2020-04-16 18:46  websocket-tail-demo\.git\hooks\post-update.sample

     文件        424  2020-04-16 18:46  websocket-tail-demo\.git\hooks\pre-applypatch.sample

     文件       1638  2020-04-16 18:46  websocket-tail-demo\.git\hooks\pre-commit.sample

     文件       1348  2020-04-16 18:46  websocket-tail-demo\.git\hooks\pre-push.sample

     文件       4898  2020-04-16 18:46  websocket-tail-demo\.git\hooks\pre-rebase.sample

     文件        544  2020-04-16 18:46  websocket-tail-demo\.git\hooks\pre-receive.sample

     文件       1492  2020-04-16 18:46  websocket-tail-demo\.git\hooks\prepare-commit-msg.sample

     文件       3610  2020-04-16 18:46  websocket-tail-demo\.git\hooks\update.sample

     文件        880  2020-04-16 18:47  websocket-tail-demo\.git\index

     文件        240  2020-04-16 18:46  websocket-tail-demo\.git\info\exclude

     文件        204  2020-04-16 18:46  websocket-tail-demo\.git\logs\HEAD

     文件        204  2020-04-16 18:46  websocket-tail-demo\.git\logs\refs\heads\master

     文件        204  2020-04-16 18:46  websocket-tail-demo\.git\logs\refs\remotes\origin\HEAD

     文件         88  2020-04-16 18:46  websocket-tail-demo\.git\objects\07\2feb8748bcefc72be17312343e37dccc964ae6

     文件        116  2020-04-16 18:46  websocket-tail-demo\.git\objects\0c\1be46d7f9126e43610b246fa6ede069630b12e

     文件        561  2020-04-16 18:46  websocket-tail-demo\.git\objects\0d\4be55e5f1065f3225bd5883dc7c5188a6ef8a8

     文件        105  2020-04-16 18:46  websocket-tail-demo\.git\objects\0f\67303b3daf11f9b017551d7851661e508042f3

     文件         51  2020-04-16 18:46  websocket-tail-demo\.git\objects\24\41a953a25a4a3ceb0b1a02bbb6ef5b9a2b7028

     文件         45  2020-04-16 18:46  websocket-tail-demo\.git\objects\35\b10b53a3e75905a9f3b31d438300e836cb1273

     文件        145  2020-04-16 18:46  websocket-tail-demo\.git\objects\42\f3f528f54334ed209759d35ac680c1072bc07c

     文件        561  2020-04-16 18:46  websocket-tail-demo\.git\objects\47\b7e50d8858f750269c0dc2ce56cb534ef034b6

     文件        634  2020-04-16 18:46  websocket-tail-demo\.git\objects\6a\4cf9baea0355c1a591a9b98116c3170a4d4940

     文件         47  2020-04-16 18:46  websocket-tail-demo\.git\objects\73\66e8d9f300d31e2bbac9a68ab0bdb66a9658f8

............此处省略87个文件信息

评论

共有 条评论