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
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
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):
...
@@ -27,7 +27,9 @@ class Log(object):
_log_id
=
_packet_id
=
-
1
_log_id
=
_packet_id
=
-
1
_protocol_date
=
None
_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
.
_default_name
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
db_path
))[
0
]
self
.
_db
=
sqlite3
.
connect
(
db_path
)
self
.
_db
=
sqlite3
.
connect
(
db_path
)
...
@@ -75,11 +77,12 @@ class Log(object):
...
@@ -75,11 +77,12 @@ class Log(object):
self
.
_next_protocol
=
float
(
'inf'
)
self
.
_next_protocol
=
float
(
'inf'
)
def
_emit
(
self
,
date
,
name
,
levelname
,
msg_list
):
def
_emit
(
self
,
date
,
name
,
levelname
,
msg_list
):
d
=
int
(
date
)
prefix
=
self
.
_date_format
prefix
=
'%s.%04u %-9s %-10s '
%
(
if
prefix
:
time
.
strftime
(
'%F %T'
,
time
.
localtime
(
d
)),
d
=
int
(
date
)
int
((
date
-
d
)
*
10000
),
levelname
,
prefix
=
'%s.%04u '
%
(
time
.
strftime
(
prefix
,
time
.
localtime
(
d
)),
name
or
self
.
_default_name
)
int
((
date
-
d
)
*
10000
))
prefix
+=
'%-9s %-10s '
%
(
levelname
,
name
or
self
.
_default_name
)
for
msg
in
msg_list
:
for
msg
in
msg_list
:
print
prefix
+
msg
print
prefix
+
msg
...
@@ -93,11 +96,8 @@ class Log(object):
...
@@ -93,11 +96,8 @@ class Log(object):
Packets
[
code
]
=
p
=
type
(
'UnknownPacket[%u]'
%
code
,
(
object
,),
{})
Packets
[
code
]
=
p
=
type
(
'UnknownPacket[%u]'
%
code
,
(
object
,),
{})
msg
=
[
'#0x%04x %-30s %s'
%
(
msg_id
,
p
.
__name__
,
peer
)]
msg
=
[
'#0x%04x %-30s %s'
%
(
msg_id
,
p
.
__name__
,
peer
)]
if
body
is
not
None
:
if
body
is
not
None
:
try
:
logger
=
getattr
(
self
,
p
.
handler_method_name
,
None
)
logger
=
getattr
(
self
,
p
.
handler_method_name
)
if
logger
or
self
.
_decode_all
:
except
AttributeError
:
pass
else
:
p
=
p
()
p
=
p
()
p
.
_id
=
msg_id
p
.
_id
=
msg_id
p
.
_body
=
body
p
.
_body
=
body
...
@@ -106,7 +106,10 @@ class Log(object):
...
@@ -106,7 +106,10 @@ class Log(object):
except
self
.
PacketMalformedError
:
except
self
.
PacketMalformedError
:
msg
.
append
(
"Can't decode packet"
)
msg
.
append
(
"Can't decode packet"
)
else
:
else
:
msg
+=
logger
(
*
args
)
if
logger
:
msg
+=
logger
(
*
args
)
elif
args
:
msg
=
'%s
\
t
| %r'
%
(
msg
[
0
],
args
),
return
date
,
name
,
'PACKET'
,
msg
return
date
,
name
,
'PACKET'
,
msg
def
error
(
self
,
code
,
message
):
def
error
(
self
,
code
,
message
):
...
@@ -157,6 +160,10 @@ def emit_many(log_list):
...
@@ -157,6 +160,10 @@ def emit_many(log_list):
def
main
():
def
main
():
parser
=
optparse
.
OptionParser
()
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"
,
parser
.
add_option
(
'-f'
,
'--follow'
,
action
=
"store_true"
,
help
=
'output appended data as the file grows'
)
help
=
'output appended data as the file grows'
)
parser
.
add_option
(
'-F'
,
'--flush'
,
action
=
"append"
,
type
=
"int"
,
parser
.
add_option
(
'-F'
,
'--flush'
,
action
=
"append"
,
type
=
"int"
,
...
@@ -170,7 +177,7 @@ def main():
...
@@ -170,7 +177,7 @@ def main():
parser
.
error
(
"sleep_interval must be positive"
)
parser
.
error
(
"sleep_interval must be positive"
)
if
not
args
:
if
not
args
:
parser
.
error
(
"no log specified"
)
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
:
if
options
.
follow
:
try
:
try
:
pid_list
=
options
.
flush
or
()
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