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
=== modified file 'analyze_log.py'
--- analyze_log.py 2011-07-16 09:41:49 +0000
+++ analyze_log.py 2011-09-05 07:49:22 +0000
@@ -2,6 +2,14 @@
2"""Analyzes the package importer log files collecting various historical data.2"""Analyzes the package importer log files collecting various historical data.
33
4This may need to be tweaked as the logger usage evolves.4This may need to be tweaked as the logger usage evolves.
5
6Roughly speaking, it works by matching lines in a log file, attributing them to
7an ActorParser which see().
8
9There are currently 3 actors all writing to the log: ControllerParser,
10DriverParser and PackageParser.
11
12The Log object defines which actors are expected and which lines they claim.
5"""13"""
614
7import datetime15import datetime
@@ -138,6 +146,11 @@
138146
139147
140class ControllerParser(ActorParser):148class ControllerParser(ActorParser):
149 """ImportController parser active during one mass_import run.
150
151 It could happen that a log file encompass several runs or starts/ends
152 during a run.
153 """
141154
142 def __init__(self):155 def __init__(self):
143 super(ControllerParser, self).__init__('controller')156 super(ControllerParser, self).__init__('controller')
@@ -176,6 +189,11 @@
176189
177190
178class DriverParser(ActorParser):191class DriverParser(ActorParser):
192 """ImportDriver parser active during one mass_import run.
193
194 It could happen that a log file encompass several runs or starts/ends
195 during a run.
196 """
179197
180 def __init__(self):198 def __init__(self):
181 super(DriverParser, self).__init__('driver')199 super(DriverParser, self).__init__('driver')
@@ -221,6 +239,7 @@
221239
222240
223class PackageParser(ActorParser):241class PackageParser(ActorParser):
242 """Parser active during one package import for a given package"""
224243
225 def __init__(self, name):244 def __init__(self, name):
226 super(PackageParser, self).__init__(name)245 super(PackageParser, self).__init__(name)
@@ -244,9 +263,12 @@
244263
245class Log(object):264class Log(object):
246265
247 def __init__(self, path):266 def __init__(self, path, f=None):
248 self.path = path267 self.path = path
249 self.stream = iter(open(self.path))268 if f is None:
269 self.stream = open(self.path)
270 else:
271 self.stream = f
250 self.out = sys.stdout272 self.out = sys.stdout
251 self.lineno = 0273 self.lineno = 0
252 self.pushed_back_line = None274 self.pushed_back_line = None
@@ -347,7 +369,9 @@
347 line = self.pushed_back_line369 line = self.pushed_back_line
348 self.pushed_back_line = None370 self.pushed_back_line = None
349 else:371 else:
350 line = self.stream.next()372 line = self.stream.readline()
373 if not line:
374 raise StopIteration
351 self.lineno +=1375 self.lineno +=1
352 return self.lineno, line376 return self.lineno, line
353377
@@ -466,11 +490,15 @@
466 exit(1)490 exit(1)
467491
468 log_path = args[1]492 log_path = args[1]
469 if not os.path.exists(log_path):493 if log_path == '-':
470 print '%s does not exist' % (log_path,)494 f = sys.stdin
471 exit(1)495 else:
496 f = None
497 if not os.path.exists(log_path):
498 print '%s does not exist' % (log_path,)
499 exit(1)
472500
473 log = Log(log_path)501 log = Log(log_path, f)
474 log.parse()502 log.parse()
475503
476504

Subscribers

People subscribed via source and target branches