Merge lp:~vila/udd/analyze_log into lp:udd

Proposed by Vincent Ladeuil
Status: Merged
Approved by: John A Meinel
Approved revision: 419
Merged at revision: 509
Proposed branch: lp:~vila/udd/analyze_log
Merge into: lp:udd
Diff against target: 94 lines (+35/-7)
1 file modified
analyze_log.py (+35/-7)
To merge this branch: bzr merge lp:~vila/udd/analyze_log
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+74056@code.launchpad.net

Commit message

Handle stdin by allowing a '-' log path.

Description of the change

While working on jubany, I generally have a

 tail -F logs/driver/progress_log

running.

But there is too much noise there.

This patch add support for a '-' log file argument to accept stdin.

It also documents a bit better how the whole script is designed.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

... sent without the conclusion:

Being able to pipe the tail to 'analyze_log.py -' gives a better view of what is happening on the importer.

Looking to log file itself is still needed in some cases but overall, the filtered view better match my monitoring use case.

Revision history for this message
John A Meinel (jameinel) wrote :

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/05/2011 10:08 AM, Vincent Ladeuil wrote:
> The proposal to merge lp:~vila/udd/analyze_log into lp:udd has been updated.
>
> Commit Message changed to:
>
> Handle stdin by allowing a '-' log path.
>
> For more details, see:
> https://code.launchpad.net/~vila/udd/analyze_log/+merge/74056

Looks reasonable to me.

 merge: approve

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5l1TIACgkQJdeBCYSNAAONcACgsbM2p8aPGFEXYZ995TWHufq6
D+cAn34u5o7qdHh2izJSSzG2ps9/3BWC
=Ianu
-----END PGP SIGNATURE-----

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'analyze_log.py'
2--- analyze_log.py 2011-07-16 09:41:49 +0000
3+++ analyze_log.py 2011-09-05 07:49:22 +0000
4@@ -2,6 +2,14 @@
5 """Analyzes the package importer log files collecting various historical data.
6
7 This may need to be tweaked as the logger usage evolves.
8+
9+Roughly speaking, it works by matching lines in a log file, attributing them to
10+an ActorParser which see().
11+
12+There are currently 3 actors all writing to the log: ControllerParser,
13+DriverParser and PackageParser.
14+
15+The Log object defines which actors are expected and which lines they claim.
16 """
17
18 import datetime
19@@ -138,6 +146,11 @@
20
21
22 class ControllerParser(ActorParser):
23+ """ImportController parser active during one mass_import run.
24+
25+ It could happen that a log file encompass several runs or starts/ends
26+ during a run.
27+ """
28
29 def __init__(self):
30 super(ControllerParser, self).__init__('controller')
31@@ -176,6 +189,11 @@
32
33
34 class DriverParser(ActorParser):
35+ """ImportDriver parser active during one mass_import run.
36+
37+ It could happen that a log file encompass several runs or starts/ends
38+ during a run.
39+ """
40
41 def __init__(self):
42 super(DriverParser, self).__init__('driver')
43@@ -221,6 +239,7 @@
44
45
46 class PackageParser(ActorParser):
47+ """Parser active during one package import for a given package"""
48
49 def __init__(self, name):
50 super(PackageParser, self).__init__(name)
51@@ -244,9 +263,12 @@
52
53 class Log(object):
54
55- def __init__(self, path):
56+ def __init__(self, path, f=None):
57 self.path = path
58- self.stream = iter(open(self.path))
59+ if f is None:
60+ self.stream = open(self.path)
61+ else:
62+ self.stream = f
63 self.out = sys.stdout
64 self.lineno = 0
65 self.pushed_back_line = None
66@@ -347,7 +369,9 @@
67 line = self.pushed_back_line
68 self.pushed_back_line = None
69 else:
70- line = self.stream.next()
71+ line = self.stream.readline()
72+ if not line:
73+ raise StopIteration
74 self.lineno +=1
75 return self.lineno, line
76
77@@ -466,11 +490,15 @@
78 exit(1)
79
80 log_path = args[1]
81- if not os.path.exists(log_path):
82- print '%s does not exist' % (log_path,)
83- exit(1)
84+ if log_path == '-':
85+ f = sys.stdin
86+ else:
87+ f = None
88+ if not os.path.exists(log_path):
89+ print '%s does not exist' % (log_path,)
90+ exit(1)
91
92- log = Log(log_path)
93+ log = Log(log_path, f)
94 log.parse()
95
96

Subscribers

People subscribed via source and target branches