Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
neoppod
Commits
57f6ee3d
Commit
57f6ee3d
authored
Jul 15, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'neolog' can merge several logs
parent
9888e498
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
70 additions
and
35 deletions
+70
-35
neo/scripts/neolog.py
neo/scripts/neolog.py
+70
-35
No files found.
neo/scripts/neolog.py
View file @
57f6ee3d
...
...
@@ -18,47 +18,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
bz2
,
logging
,
optparse
,
os
,
signal
,
sqlite3
,
sys
,
time
from
bi
nascii
import
b2a_hex
from
bi
sect
import
insort
from
logging
import
getLevelName
class
main
(
object
):
class
Log
(
object
):
_log_id
=
_packet_id
=
-
1
_protocol_date
=
None
def
__new__
(
cls
):
self
=
object
.
__new__
(
cls
)
parser
=
optparse
.
OptionParser
()
parser
.
add_option
(
'-f'
,
'--follow'
,
action
=
"store_true"
,
help
=
'output appended data as the file grows'
)
parser
.
add_option
(
'-s'
,
'--sleep-interval'
,
type
=
"float"
,
default
=
1
,
help
=
'with -f, sleep for approximately N seconds (default 1.0)'
' between iterations'
,
metavar
=
'N'
)
parser
.
add_option
(
'-F'
,
'--flush'
,
action
=
"append"
,
type
=
"int"
,
help
=
'with -f, tell process PID to flush logs approximately N'
' seconds (see -s)'
,
metavar
=
'PID'
)
options
,
(
db_path
,)
=
parser
.
parse_args
()
if
options
.
sleep_interval
<=
0
:
parser
.
error
(
"sleep_interval must be positive"
)
self
.
_default_name
,
_
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
db_path
))
def
__init__
(
self
,
db_path
):
self
.
_default_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
db_path
))[
0
]
self
.
_db
=
sqlite3
.
connect
(
db_path
)
if
options
.
follow
:
try
:
pid_list
=
options
.
flush
or
()
while
True
:
self
.
_emit_many
()
for
pid
in
pid_list
:
os
.
kill
(
pid
,
signal
.
SIGRTMIN
)
time
.
sleep
(
options
.
sleep_interval
)
except
KeyboardInterrupt
:
pass
else
:
self
.
_emit_many
()
def
_
emit_many
(
self
):
def
_
_iter__
(
self
):
db
=
self
.
_db
try
:
db
.
execute
(
"BEGIN"
)
yield
nl
=
db
.
execute
(
"SELECT * FROM log WHERE id>?"
,
(
self
.
_log_id
,))
np
=
db
.
execute
(
"SELECT * FROM packet WHERE id>?"
,
...
...
@@ -70,13 +47,13 @@ class main(object):
p
=
None
for
self
.
_log_id
,
date
,
name
,
level
,
pathname
,
lineno
,
msg
in
nl
:
while
p
and
p
[
1
]
<
date
:
self
.
_packet
(
*
p
)
yield
self
.
_packet
(
*
p
)
p
=
np
.
fetchone
()
self
.
_emit
(
date
,
name
,
getLevelName
(
level
),
msg
.
splitlines
()
)
yield
date
,
name
,
getLevelName
(
level
),
msg
.
splitlines
(
)
if
p
:
self
.
_packet
(
*
p
)
yield
self
.
_packet
(
*
p
)
for
p
in
np
:
self
.
_packet
(
*
p
)
yield
self
.
_packet
(
*
p
)
finally
:
db
.
rollback
()
...
...
@@ -130,7 +107,7 @@ class main(object):
msg
.
append
(
"Can't decode packet"
)
else
:
msg
+=
logger
(
*
args
)
self
.
_emit
(
date
,
name
,
'PACKET'
,
msg
)
return
date
,
name
,
'PACKET'
,
msg
def
error
(
self
,
code
,
message
):
return
"%s (%s)"
%
(
code
,
message
),
...
...
@@ -149,5 +126,63 @@ class main(object):
return
()
def
emit_many
(
log_list
):
log_list
=
[(
log
,
iter
(
log
).
next
)
for
log
in
log_list
]
for
x
in
log_list
:
# try to start all transactions at the same time
x
[
1
]()
event_list
=
[]
for
log
,
next
in
log_list
:
try
:
event
=
next
()
except
StopIteration
:
continue
event_list
.
append
((
-
event
[
0
],
next
,
log
.
_emit
,
event
))
if
event_list
:
event_list
.
sort
()
while
True
:
key
,
next
,
emit
,
event
=
event_list
.
pop
()
try
:
next_date
=
-
event_list
[
-
1
][
0
]
except
IndexError
:
next_date
=
float
(
'inf'
)
try
:
while
event
[
0
]
<=
next_date
:
emit
(
*
event
)
event
=
next
()
except
StopIteration
:
if
not
event_list
:
break
else
:
insort
(
event_list
,
(
-
event
[
0
],
next
,
emit
,
event
))
def
main
():
parser
=
optparse
.
OptionParser
()
parser
.
add_option
(
'-f'
,
'--follow'
,
action
=
"store_true"
,
help
=
'output appended data as the file grows'
)
parser
.
add_option
(
'-F'
,
'--flush'
,
action
=
"append"
,
type
=
"int"
,
help
=
'with -f, tell process PID to flush logs approximately N'
' seconds (see -s)'
,
metavar
=
'PID'
)
parser
.
add_option
(
'-s'
,
'--sleep-interval'
,
type
=
"float"
,
default
=
1
,
help
=
'with -f, sleep for approximately N seconds (default 1.0)'
' between iterations'
,
metavar
=
'N'
)
options
,
args
=
parser
.
parse_args
()
if
options
.
sleep_interval
<=
0
:
parser
.
error
(
"sleep_interval must be positive"
)
if
not
args
:
parser
.
error
(
"no log specified"
)
log_list
=
map
(
Log
,
args
)
if
options
.
follow
:
try
:
pid_list
=
options
.
flush
or
()
while
True
:
emit_many
(
log_list
)
for
pid
in
pid_list
:
os
.
kill
(
pid
,
signal
.
SIGRTMIN
)
time
.
sleep
(
options
.
sleep_interval
)
except
KeyboardInterrupt
:
pass
else
:
emit_many
(
log_list
)
if
__name__
==
"__main__"
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment