基本信息
源码名称:websockets实现tomcat日志在线输出
源码大小:0.03M
文件格式:.rar
开发语言:Java
更新时间:2020-11-20
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元×
微信扫码支付:1 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
通过http访问查看tomcat实时日志
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(); }
【前端代码】
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>tail log</title> <script src="//cdn.bootcss.com/jquery/2.1.4/jquery.js"></script> </head> <body> <div id="log-container" style="height: 450px; overflow-y: scroll; background: #333; color: #aaa; padding: 10px;"> <div> </div> </div> </body> <script> $(document).ready(function() { // 指定websocket路径 var websocket = new WebSocket('ws://47.110.136.161:8080/log'); websocket.onmessage = function(event) { // 接收服务端的实时日志并添加到HTML页面中 $("#log-container div").append(event.data); // 滚动条滚动到最低部 $("#log-container").scrollTop($("#log-container div").height() - $("#log-container").height()); }; }); </script> </body> </html>