久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

瀏覽器中的tail -f

tail -f in a webbrowser(瀏覽器中的tail -f)
本文介紹了瀏覽器中的tail -f的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我創(chuàng)建了一個 Python 腳本,用于監(jiān)視日志文件的更改(如 tail -f)并將其顯示在控制臺上.我想在網(wǎng)絡(luò)瀏覽器中訪問 Python 腳本的輸出.我需要什么來創(chuàng)建這個?我正在考慮使用 Django 和 jQuery.非常感謝任何提示或示例.

I've created a Python script that monitors a logfile for changes (like tail -f) and displays it on a console. I would like to access the output of the Python script in a webbrowser. What would I need to create this? I was thinking about using Django and jQuery. Any tips or examples are greatly appreciated.

推薦答案

首先創(chuàng)建一個python腳本來監(jiān)控日志文件的變化.如果您只需要它來進行調(diào)試 - 測試目的,那么使用 Django 或其他 Web 框架就有點過頭了.使用套接字實現(xiàn) Http Web 服務(wù)器功能非常容易.每當一個 Http GET 請求到來時,只提供來自不同請求的差異.為了實現(xiàn)這一點,您需要在內(nèi)存中存儲每個請求的狀態(tài)(例如文件中最后一行的編號).

First create a python script that monitors the log file for changes. If you only need this for debugging - testing purposes, then it is an overkill to use Django or another web framework. It is very easy to implement Http Web server functionality using sockets. Whenever an Http GET request is coming, serve only the difference from the different request. In order to achieve this you need to store in memory the status of every request coming (e.g.number of last line in the file).

jQuery 部分實際上非常簡單.使用 setTimeout 函數(shù)設(shè)置定時器.這樣的事情會做:

The jQuery part is actually quite easy. Set up a timer with setTimeout function. Something like this will do:

function doUpdate() {
  $.ajax({type: "GET", url : tailServiceUrl,
          success: function (data) {
             if (data.length > 4)
             {
                // Data are assumed to be in HTML format
                // Return something like <p/> in case of no updates
                $("#logOutputDiv").append(data);
             }
             setTimeout("doUpdate()", 2000);
           }});
}

setTimeout("doUpdate()", 2000);

您還可以為錯誤和超時創(chuàng)建回調(diào),以報告服務(wù)器問題.

You can also create callbacks for error and timeout to report a problem with the server.

這篇關(guān)于瀏覽器中的tail -f的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How to fix BrowserWindow is not a constructor error when creating child window in Electron renderer process(在 Electron 渲染器進程中創(chuàng)建子窗口時如何修復(fù) BrowserWindow 不是構(gòu)造函數(shù)錯誤) - IT屋-程序員軟件開發(fā)技術(shù)
mainWindow.loadURL(quot;https://localhost:3000/quot;) show white screen on Electron app(mainWindow.loadURL(https://localhost:3000/) 在 Electron 應(yīng)用程序上顯示白屏)
Electron webContents executeJavaScript : Cannot execute script on second on loadURL(Electron webContents executeJavaScript:無法在第二個 loadURL 上執(zhí)行腳本)
how to use electron browser window inside components in angular-cli?(如何在angular-cli的組件內(nèi)使用電子瀏覽器窗口?)
ElectronJS - sharing redux store between windows?(ElectronJS - 在 Windows 之間共享 redux 存儲?)
How to access camera/webcamera inside electron app?(如何在電子應(yīng)用程序中訪問相機/網(wǎng)絡(luò)攝像頭?)
主站蜘蛛池模板: 日韩欧美在线一区 | 精品一区二区三区在线视频 | 国产精品毛片一区二区三区 | 久久久久久黄 | 成人精品视频在线观看 | 91精品久久久久久久久久入口 | 色综合99| 欧美不卡视频一区发布 | 国产成人精品免高潮在线观看 | 欧美一区永久视频免费观看 | 伊人免费网 | 黄色精品视频网站 | 国产观看 | 中文字幕的av | 97免费视频在线观看 | 成人精品一区亚洲午夜久久久 | 色综合美女 | 男人午夜视频 | 国产亚洲一级 | 国产成人91视频 | 精品中文字幕视频 | 欧美二区在线 | 欧美日韩免费 | 午夜国产羞羞视频免费网站 | 色久伊人| 亚洲视频欧美视频 | 国产精品视频一区二区三区 | 自拍中文字幕 | 日韩电影中文字幕在线观看 | av网站在线看 | 成人免费小视频 | 精品国产31久久久久久 | 亚洲精品久久久 | 欧美综合一区二区三区 | 操视频网站 | 亚洲一区二区久久久 | 亚洲二区在线观看 | 午夜看电影在线观看 | 亚洲看片| 久久五月婷 | 夜夜操天天艹 |