- Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdatediff.py
More file actions
Latest commit
executable file
·34 lines (27 loc) · 718 Bytes
/
Copy pathdatediff.py
File metadata and controls
executable file
·34 lines (27 loc) · 718 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python
"""
Journalctl output to prepend each line with the numebr of seconds.
"""
fromdatetimeimportdatetime, timedelta
defread_date(line):
"""
Get the datetime corresponding to the log line. Throws ValueError
on failure.
"""
dts=" ".join(line.split(" ")[:3])
returndatetime.strptime(dts, "%m %d %H:%M:%S")
deflineiter():
whileTrue:
try:
l=raw_input()
yield (l, read_date(l))
exceptEOFError:
break
exceptValueError:
pass
defmain():
last_time=None
for (cl, cd) indtl:
print"[%ds] %s"% ((cl- (last_timeorcl)).seconds, cl)
if__name__=='__main__':
main()