我可以在 HTML5 中实现这一点吗?其他网络技术?

发布于 2024-10-20 22:11:24 字数 1058 浏览 6 评论 0原文

大约 6 个月前,我在 stackoverflow 上问了一个问题“帮助进行日志分析的软件?< /a>”

在继续阅读之前请先看一下这个问题。

事实证明,目前还没有好的软件可以根据时间戳混合日志文件并以良好的 UI 呈现它们。

我想主动开发一些东西,并在完成后将其开源。

早些时候,我通过在 C++ 中编写一段快速而肮脏的代码来解决这个问题,这将生成一个制表符分隔的文件(类似于 csv,但制表符分隔),稍后我将在 Excel 中打开该文件。

我对我的 C++ 代码不满意,原因如下: 1. 后面查看输出文件完全依赖Excel。 2. 由于没有涉及UI,所以每次都编写其命令行并不容易。 3. 由于命令行的学习曲线,它不太能与其他团队成员(和世界)共享。

由于上述原因(以及其他一些原因),我正在考虑将其开发为网络解决方案。这样我就可以与大家分享工作实例。

我想到的是一个基于网络的解决方案,如下所示:

  • 用户将能够使用 HTML5 的文件 API 提供输入日志文件。
  • 然后用户可能会告诉每个日志文件关联的时间戳的格式。
  • 此后,JavaScript 会将这些日志文件处理为表格中的混合 HTML 输出。

我只是网络技术的初学者。所以我需要你的帮助来确定这是否是最好的解决办法?

我想要一个网络解决方案,但这并不意味着我希望用户上传他的日志文件以进行后端处理。我想要一个基于网络的客户端解决方案。

感谢您的投入。

编辑:基于 Raynos 下面的评论

@bits 你确实意识到浏览器 不适合处理大件 的数据。有 stackoverflow.com/questions/4833480/… 这表明这可能会导致 问题。

我觉得在浏览器中这样做并不是最好的选择。也许,我应该探索基于后端的解决方案。 有什么想法或建议吗?

Almost 6 months ago, I asked a question on stackoverflow "Software to help in log analysis?"

Please look at that question before reading ahead.

It turned out that there is no good software available currently that can intermix log files based on timestamps and present them in a good UI.

I wanted to take initiative and develop something and open source it once its completed.

Earlier, I worked around by writing a quick and dirty piece of code in c++, that would generate a tab separated file (like csv but tab separated) which I would later opened in Excel.

I am not satisfied with my c++ code for the following reasons:
1. It totally depends on Excel to view the output file later.
2. Since there is no UI involved, its not easy to write its commandline everytime.
3. Because of the learning curve of the commandline, its not so much sharable with other team members (and the world).

For the above reasons (and a few more), I was thinking to develop that as a web solution. That way I can share the working instance with everyone.

What I have in mind is a web based solution something like this:

  • The user will be able to give the input log files using HTML5's File API.
  • And then user would probably tell the format of the timestamp associated with each log file.
  • Thereafter, the javascript would process those log files into intermixed HTML output in a table.

I am just a beginner in web based technologies. So I need your help in determining if this would be the best way to go about it?

I want a web solution, but that doesn't mean I want user to upload his log files for backend processing. I want a web-based client only solution.

Thanks for your inputs.

EDIT: Based on comment below by Raynos

@bits You do realise that browsers
were not meant to handle large pieces
of data. There was
stackoverflow.com/questions/4833480/…
which shows that this can cause
problems.

I feel that doing this in browsers isn't the best deal. Probably, I should explore backend based solutions.
Any ideas or suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

绝影如岚 2024-10-27 22:11:24

您正在寻找一个在线比较工具,该工具需要 n 个文件,其中包含按某种顺序的时间戳列表,包括要在适当位置显示但不在比较中解析的额外数据。

文件上传将涉及

以及 javascript 片段

$("#upload").change(function(files) {
    var files = this.files;
    for (var i = 0; i < files.length; i++) {
        (function() {
            var file = files[i]; 
            var reader = new FileReader;
            reader.onload = function(e) {
                var text = reader.result;
                console.log(text);
            };
            reader.readAsText(file);
        }());
    }
});

请参阅实时 示例

这样您就拥有了解析器所需的所有文本。我希望这能有所帮助。

至于差异的标记,我建议如下:

<table>
 <!-- one tr per unique timestamp -->
 <tr>
  <!-- one td/textarea per file -->
  <td> <textarea /> </td>
  <td> <textarea /> </td>
 </tr>
 ...
</table>

我建议将其作为模板并使用模板引擎来完成一些繁重的工作。

假设我们要使用 jquery-tmpl

下面是一个帮助您开始的示例。 (我花零时间让它看起来不错。那是你的工作)。

剩下的就是生成 JSON 数据以插入到模板中。

因此,鉴于您的文件输入,您应该在某处有一个 fileTexts 数组。

我们希望有某种分隔符将其分成单独的时间戳记录。为了简单起见,我们假设新行字符可以工作。

var fileTexts = [file];
var regex = new RegExp("(timestampformat)(.*)");

for (var i = 0; i < fileTexts.length; i++) {
    var text = fileTexts[i];
    var records = text.split("\n");
    for (var j = 0; j < records.length; j++) {
        var match = regex.exec(records[j]);
        addToTimestamps(match[1], match[2], i);
    }
}

function addToTimestamps(timestamp, text, currFileCount) {
    console.log(arguments);
    // implement it.
}

根据示例

这些是基本构建块。从文件 API 获取数据。将数据处理为规范化的数据格式,然后在数据格式上使用某种渲染工具。

Your looking for an online diff tool which takes n files containing a list of timestamps in some order including a extra data to be displayed in place but not parsed in the diffing.

The file upload would involve

<input id="upload" type="file">

Along with snippets of javascript

$("#upload").change(function(files) {
    var files = this.files;
    for (var i = 0; i < files.length; i++) {
        (function() {
            var file = files[i]; 
            var reader = new FileReader;
            reader.onload = function(e) {
                var text = reader.result;
                console.log(text);
            };
            reader.readAsText(file);
        }());
    }
});

See live example.

So you have all the text you just need to work on a parser. I hope that helps a bit.

As for the markup of the diff I would suggest something like:

<table>
 <!-- one tr per unique timestamp -->
 <tr>
  <!-- one td/textarea per file -->
  <td> <textarea /> </td>
  <td> <textarea /> </td>
 </tr>
 ...
</table>

I would recommend making this a template and using a template engine to do some of the heavy lifting.

Let's say we want to use jquery-tmpl.

Here's an example to get you started. (I spend zero time on making it look good. That's your job).

All that's left is generating JSON data to insert into the template.

So given your file input you should have an array of fileTexts somewhere.

We want to have some kind of deliminator to split it up into individual time stamp records. For simplicities sake let's say that the new line character would work.

var fileTexts = [file];
var regex = new RegExp("(timestampformat)(.*)");

for (var i = 0; i < fileTexts.length; i++) {
    var text = fileTexts[i];
    var records = text.split("\n");
    for (var j = 0; j < records.length; j++) {
        var match = regex.exec(records[j]);
        addToTimestamps(match[1], match[2], i);
    }
}

function addToTimestamps(timestamp, text, currFileCount) {
    console.log(arguments);
    // implement it.
}

As per example.

These are the basic building blocks. Get the data from the File API. Manipulate the data into a normalised data format then use some kind of rendering tool on the data format.

娇纵 2024-10-27 22:11:24

使用 javascript 可以很容易地做到这一点。您上面提到使用 html5 文件 api,这是一个很好的起点(html 文件 api ),您可以使用不显眼的 javascript 在上传文件时触发回调。在回调中,您可以使用任何优秀的 javascript 模板库从上传的文件构建元素表。然后,在后续文件上传时,您可以使用它们的时间戳将它们动态地交错到表中。如果您使用编译形式,使用 js 正则表达式检测时间戳将相当简单,并且相当有效。

这是对该问题的相当高水平的回答,如果您对特定细节有任何疑问,我也很乐意回答。

希望这有帮助

This would be fairly easy to do using javascript. You mentioned above using the html5 file api, and that is a great place to start (html file api), you can use unobtrusive javascript to have a callback fire when the a file is uploaded. Inside the callback you could use any of the great javascript templating libraries to construct a table of elements from the uploaded file. Then on subsequent file uploads, you could dynamically interleave them into the table using their timestamp. Detecting the timestamp using js regular expressions would be fairly straightforward, and reasonably efficient if you used a compiled form.

This is a fairly high level answer to the question, and if you have any questions about particular details, I'd be happy to answer those as well.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文