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
Iliya Manolov
neoppod
Commits
e2eef562
Commit
e2eef562
authored
Jul 16, 2012
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New -a and -d options to 'neolog'
parent
57f6ee3d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
13 deletions
+20
-13
neo/scripts/neolog.py
neo/scripts/neolog.py
+20
-13
No files found.
neo/scripts/neolog.py
View file @
e2eef562
...
...
@@ -27,7 +27,9 @@ class Log(object):
_log_id
=
_packet_id
=
-
1
_protocol_date
=
None
def
__init__
(
self
,
db_path
):
def
__init__
(
self
,
db_path
,
decode_all
,
date_format
):
self
.
_date_format
=
'%F %T'
if
date_format
is
None
else
date_format
self
.
_decode_all
=
decode_all
self
.
_default_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
db_path
))[
0
]
self
.
_db
=
sqlite3
.
connect
(
db_path
)
...
...
@@ -75,11 +77,12 @@ class Log(object):
self
.
_next_protocol
=
float
(
'inf'
)
def
_emit
(
self
,
date
,
name
,
levelname
,
msg_list
):
d
=
int
(
date
)
prefix
=
'%s.%04u %-9s %-10s '
%
(
time
.
strftime
(
'%F %T'
,
time
.
localtime
(
d
)),
int
((
date
-
d
)
*
10000
),
levelname
,
name
or
self
.
_default_name
)
prefix
=
self
.
_date_format
if
prefix
:
d
=
int
(
date
)
prefix
=
'%s.%04u '
%
(
time
.
strftime
(
prefix
,
time
.
localtime
(
d
)),
int
((
date
-
d
)
*
10000
))
prefix
+=
'%-9s %-10s '
%
(
levelname
,
name
or
self
.
_default_name
)
for
msg
in
msg_list
:
print
prefix
+
msg
...
...
@@ -93,11 +96,8 @@ class Log(object):
Packets
[
code
]
=
p
=
type
(
'UnknownPacket[%u]'
%
code
,
(
object
,),
{})
msg
=
[
'#0x%04x %-30s %s'
%
(
msg_id
,
p
.
__name__
,
peer
)]
if
body
is
not
None
:
try
:
logger
=
getattr
(
self
,
p
.
handler_method_name
)
except
AttributeError
:
pass
else
:
logger
=
getattr
(
self
,
p
.
handler_method_name
,
None
)
if
logger
or
self
.
_decode_all
:
p
=
p
()
p
.
_id
=
msg_id
p
.
_body
=
body
...
...
@@ -106,7 +106,10 @@ class Log(object):
except
self
.
PacketMalformedError
:
msg
.
append
(
"Can't decode packet"
)
else
:
msg
+=
logger
(
*
args
)
if
logger
:
msg
+=
logger
(
*
args
)
elif
args
:
msg
=
'%s
\
t
| %r'
%
(
msg
[
0
],
args
),
return
date
,
name
,
'PACKET'
,
msg
def
error
(
self
,
code
,
message
):
...
...
@@ -157,6 +160,10 @@ def emit_many(log_list):
def
main
():
parser
=
optparse
.
OptionParser
()
parser
.
add_option
(
'-a'
,
'--all'
,
action
=
"store_true"
,
help
=
'decode all packets'
)
parser
.
add_option
(
'-d'
,
'--date'
,
metavar
=
'FORMAT'
,
help
=
'custom date format, according to strftime(3)'
)
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"
,
...
...
@@ -170,7 +177,7 @@ def main():
parser
.
error
(
"sleep_interval must be positive"
)
if
not
args
:
parser
.
error
(
"no log specified"
)
log_list
=
map
(
Log
,
args
)
log_list
=
[
Log
(
db_path
,
options
.
all
,
options
.
date
)
for
db_path
in
args
]
if
options
.
follow
:
try
:
pid_list
=
options
.
flush
or
()
...
...
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