如何在.txt日志文件上执行报告 [英] How to do a report on a .txt log file

查看:77
本文介绍了如何在.txt日志文件上执行报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.txt日志文件,必须是废话。但是有些部分会在用户登录时显示,并在登录的时间显示。下面是日志文件的一部分。例如,mwoelk和mwoelk。是登录的用户和dcurtin。是另一个用户登录。到目前为止,我已经创建了一个python应用程序,计算用户登录的次数,但我对用户登录时如何拉动一点也不知道。对我能做什么的任何帮助都会有所帮助很多。


172.16.9.206 - mwoelk [01 / Feb / 2008:04:32:12 -0500]" GET / controller?method = getUser HTTP / 1.0" 200 305

172.16.9.166 - - [01 / Feb / 2008:04:57:38 -0500]" HEAD /images/DCI.gif HTTP / 1.1" 200 -
172.16.9.166 - - [01 / Feb / 2008:04:57:38 -0500]" HEAD /eagent.jnlp HTTP / 1.1" 200 -

172.16.9.166 - - [01 / Feb / 2008:04:57:38 -0500]" HEAD /jh.jnlp HTTP / 1.1" 200 -

172.16.9.166 - - [01 / Feb / 2008:04:57:38 -0500]" HEAD /smack.jar HTTP / 1.1" 200 -

172.16.9.166 - - [01 / Feb / 2008:04:57:38 -0500]" HEAD /jh.jar HTTP / 1.1" 200 -
172.16.9.166 - - [01 / Feb / 2008:04:57:39 -0500]" HEAD /images/DCI.gif HTTP / 1.1" 200 -

172.16.9.166 - noone [01 / Feb / 2008:04:57:40 -0500]" GET / controller?method = getNode& name = S14000068 HTTP / 1.0" 200 499

172.16.9.166 - - [01 / Feb / 2008:04:57:40 -0500]" GET /help/helpset.hs HTTP / 1.1" 200 547

172.16.9.166 - - [01 / Feb / 2008:04:57:43 -0500]" GET /help/map.jhm HTTP / 1.1" 200 59650

172.16.9.162 - dcurtin [01 / Feb / 2008:00:19:16 -0500]" GET / controller?method = getUser HTTP / 1.0" 200 307


以下是我到目前为止计算用户登录频率的工作。

I have a .txt log file and must of it is crap. But there are parts that display when a user logs in, and at what time the logged in. Below is a portion of the log file. For example, "mwoelk" is a user logging in and "dcurtin" is another user logging in. So far I have created a python app that counts how many times a user logged in, but I''m a little clueless on how to pull when the user logged in. Any help on what I could do would help a lot.

172.16.9.206 - mwoelk [01/Feb/2008:04:32:12 -0500] "GET /controller?method=getUser HTTP/1.0" 200 305
172.16.9.166 - - [01/Feb/2008:04:57:38 -0500] "HEAD /images/DCI.gif HTTP/1.1" 200 -
172.16.9.166 - - [01/Feb/2008:04:57:38 -0500] "HEAD /eagent.jnlp HTTP/1.1" 200 -
172.16.9.166 - - [01/Feb/2008:04:57:38 -0500] "HEAD /jh.jnlp HTTP/1.1" 200 -
172.16.9.166 - - [01/Feb/2008:04:57:38 -0500] "HEAD /smack.jar HTTP/1.1" 200 -
172.16.9.166 - - [01/Feb/2008:04:57:38 -0500] "HEAD /jh.jar HTTP/1.1" 200 -
172.16.9.166 - - [01/Feb/2008:04:57:39 -0500] "HEAD /images/DCI.gif HTTP/1.1" 200 -
172.16.9.166 - noone [01/Feb/2008:04:57:40 -0500] "GET /controller?method=getNode&name=S14000068 HTTP/1.0" 200 499
172.16.9.166 - - [01/Feb/2008:04:57:40 -0500] "GET /help/helpset.hs HTTP/1.1" 200 547
172.16.9.166 - - [01/Feb/2008:04:57:43 -0500] "GET /help/map.jhm HTTP/1.1" 200 59650
172.16.9.162 - dcurtin [01/Feb/2008:00:19:16 -0500] "GET /controller?method=getUser HTTP/1.0" 200 307

Here is what I have done so far to count the frequency of a user logging in.

展开 | 选择 | Wrap | 行号

推荐答案

alexphd,


这是你迄今为止做得非常好的工作。实际上,数据的排序非常适合解析。由于登录时间括在括号中,您可以通过获取括号的索引(使用字符串方法index())并切割字符串(the_string[[start:end])来查找日志时间。您也可以使用正则表达式执行此操作。虽然我们正在使用它,但为什么不同时获取用户名?我们假设用户名只能包含字母数字字符。
alexphd,

That''s pretty good work you have done so far. The data is actually ordered very well for parsing. Since the log in time is enclosed in brackets, you can find the log in times by getting the index of the brackets (using the string method index()) and slicing the string ("the_string"[start:end]). You can also do it with a regular expression. While we''re at it, why not get the user name at the same time? Let''s assume the user name can only contain alphanumeric characters.
展开 | 选择 | Wrap | 行号



alexphd,


那个到目前为止,你做的工作非常好。实际上,数据的排序非常适合解析。由于登录时间括在括号中,您可以通过获取括号的索引(使用字符串方法index())并切割字符串(the_string[[start:end])来查找日志时间。您也可以使用正则表达式执行此操作。虽然我们正在使用它,但为什么不同时获取用户名?我们假设用户名只能包含字母数字字符。
alexphd,

That''s pretty good work you have done so far. The data is actually ordered very well for parsing. Since the log in time is enclosed in brackets, you can find the log in times by getting the index of the brackets (using the string method index()) and slicing the string ("the_string"[start:end]). You can also do it with a regular expression. While we''re at it, why not get the user name at the same time? Let''s assume the user name can only contain alphanumeric characters.
展开 | 选择 | Wrap | 行号



好​​的,我看到你在做什么,但我有一些的问题。 logdict = {}到底做了什么。在这个代码中你写的这段代码
Okay, I see what you''re doing but I have a few questions. What does logdict={} exactly do. Baiscally this code block of code that you wrote
展开 | 选择 | Wrap | 行号


这篇关于如何在.txt日志文件上执行报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆