ecology9二开显性展示日志信息在菜单页面当中

在泛微ecology9的二次开发中,我们经常需要借助打印日志排查程序运行状况,但每次打开日志都很浪费时间,我们可以把日志展示到页面中,优化本就繁琐的排查过程。 

效果图

 后端代码

@Path("/user")
public class UserApi {

    @GET
    @Path("/getCache")
    @Produces(MediaType.APPLICATION_JSON)
    public String getCache(@QueryParam("type")String type) {
        String path;
        if ("ecology".equals(type)){
            path = System.getProperty("user.dir").replace("Resin","ecology") + "\\log\\ecology";
        }else{
            path = System.getProperty("user.dir") + "\\log\\jvm-app-0.log";
        }
        String str = null;
        InputStream in = null;
        try {
            File file = new File(path);
            in = new FileInputStream(file);
            byte[] bytes = new byte[(int) file.length()];
            in.read(bytes);
            str = new String(bytes,"GB2312");
            if (str.length()>50000){
                str = str.substring(str.length() - 50000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return str;
    }
}

前端代码(将该Acache.html文件放入ecology根目录下)

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="utf-8" />
    <title>ecology日志</title>
</head>
<body>
<pre id="pre1"></pre>
<button onclick="flush()">刷新</button>
<select id="select">
    <option value="ecology">ecology</option>
    <option value="resin">resin</option>
</select>
<input type="text" id="word">
<button onclick="search()">搜索</button>
<script>
    flush()
    let content;
    function flush(){
        const pre = document.getElementById('pre1');
        pre.innerHTML = '...正在加载中';
        const myselect = document.getElementById("select")
        let index = myselect.selectedIndex;
        let value = myselect.options[index].value;
        fetch(`/api/user/getCache?type=${value}`,
            { method: 'GET',headers: new Headers({'Accept': 'application/json'})}
        ).then(res => {
            return res.text()
        }).then(res => {
            content = res
            pre.innerHTML = res;
            window.scrollTo(0, document.body.scrollHeight);
        })
    }
    function search(){
        let word = document.getElementById('word').value;
        if (word){
            const pre = document.getElementById('pre1');
            pre.innerHTML = content
            pre.innerHTML = pre.innerHTML.replaceAll(word, `<span style="background-color: yellow">${word}</span>`)
        }
    }
</script>
<style>
    @import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');
    @import url('https://fonts.googleapis.com/css?family=Roboto+Mono&display=swap');
    html {
        font-family: 'Roboto', sans-serif;
    }
    pre {
        font-family: 'Roboto mono', monospace;
        font-size: 0.9rem;
        background-color: #D6EAF8;
        padding: 10px;
    }
</style>
</body>
</html>

系统配置

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值