Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
poezio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
178
Issues
178
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
poezio
poezio
Commits
e5e0533b
Commit
e5e0533b
authored
Feb 07, 2019
by
Link Mauve
3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logger: Log the JID during a parsing error.
parent
42b87268
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
9 deletions
+9
-9
poezio/logger.py
poezio/logger.py
+5
-5
test/test_logger.py
test/test_logger.py
+4
-4
No files found.
poezio/logger.py
View file @
e5e0533b
...
@@ -56,14 +56,14 @@ class LogMessage(LogItem):
...
@@ -56,14 +56,14 @@ class LogMessage(LogItem):
self
.
nick
=
nick
self
.
nick
=
nick
def
parse_log_line
(
msg
:
str
)
->
Optional
[
LogItem
]:
def
parse_log_line
(
msg
:
str
,
jid
:
str
)
->
Optional
[
LogItem
]:
match
=
re
.
match
(
MESSAGE_LOG_RE
,
msg
)
match
=
re
.
match
(
MESSAGE_LOG_RE
,
msg
)
if
match
:
if
match
:
return
LogMessage
(
*
match
.
groups
())
return
LogMessage
(
*
match
.
groups
())
match
=
re
.
match
(
INFO_LOG_RE
,
msg
)
match
=
re
.
match
(
INFO_LOG_RE
,
msg
)
if
match
:
if
match
:
return
LogInfo
(
*
match
.
groups
())
return
LogInfo
(
*
match
.
groups
())
log
.
debug
(
'Error while parsing
"%s"'
,
msg
)
log
.
debug
(
'Error while parsing
%s’s logs: “%s”'
,
jid
,
msg
)
return
None
return
None
...
@@ -176,7 +176,7 @@ class Logger:
...
@@ -176,7 +176,7 @@ class Logger:
filename
,
filename
,
exc_info
=
True
)
exc_info
=
True
)
return
None
return
None
return
parse_log_lines
(
lines
)
return
parse_log_lines
(
lines
,
jid
)
def
log_message
(
self
,
def
log_message
(
self
,
jid
:
str
,
jid
:
str
,
...
@@ -306,7 +306,7 @@ def _get_lines_from_fd(fd: IO[Any], nb: int = 10) -> List[str]:
...
@@ -306,7 +306,7 @@ def _get_lines_from_fd(fd: IO[Any], nb: int = 10) -> List[str]:
return
lines
return
lines
def
parse_log_lines
(
lines
:
List
[
str
])
->
List
[
Dict
[
str
,
Any
]]:
def
parse_log_lines
(
lines
:
List
[
str
]
,
jid
:
str
)
->
List
[
Dict
[
str
,
Any
]]:
"""
"""
Parse raw log lines into poezio log objects
Parse raw log lines into poezio log objects
"""
"""
...
@@ -320,7 +320,7 @@ def parse_log_lines(lines: List[str]) -> List[Dict[str, Any]]:
...
@@ -320,7 +320,7 @@ def parse_log_lines(lines: List[str]) -> List[Dict[str, Any]]:
idx
+=
1
idx
+=
1
log
.
debug
(
'fail?'
)
log
.
debug
(
'fail?'
)
continue
continue
log_item
=
parse_log_line
(
lines
[
idx
])
log_item
=
parse_log_line
(
lines
[
idx
]
,
jid
)
idx
+=
1
idx
+=
1
if
not
isinstance
(
log_item
,
LogItem
):
if
not
isinstance
(
log_item
,
LogItem
):
log
.
debug
(
'wrong log format? %s'
,
log_item
)
log
.
debug
(
'wrong log format? %s'
,
log_item
)
...
...
test/test_logger.py
View file @
e5e0533b
...
@@ -7,13 +7,13 @@ from poezio.common import get_utc_time, get_local_time
...
@@ -7,13 +7,13 @@ from poezio.common import get_utc_time, get_local_time
def
test_parse_message
():
def
test_parse_message
():
line
=
'MR 20170909T09:09:09Z 000 <nick> body'
line
=
'MR 20170909T09:09:09Z 000 <nick> body'
assert
vars
(
parse_log_line
(
line
))
==
vars
(
LogMessage
(
'2017'
,
'09'
,
'09'
,
'09'
,
'09'
,
'09'
,
'0'
,
'nick'
,
'body'
))
assert
vars
(
parse_log_line
(
line
,
'user@domain'
))
==
vars
(
LogMessage
(
'2017'
,
'09'
,
'09'
,
'09'
,
'09'
,
'09'
,
'0'
,
'nick'
,
'body'
))
line
=
'<>'
line
=
'<>'
assert
parse_log_line
(
line
)
is
None
assert
parse_log_line
(
line
,
'user@domain'
)
is
None
line
=
'MR 20170908T07:05:04Z 003 <nick> '
line
=
'MR 20170908T07:05:04Z 003 <nick> '
assert
vars
(
parse_log_line
(
line
))
==
vars
(
LogMessage
(
'2017'
,
'09'
,
'08'
,
'07'
,
'05'
,
'04'
,
'003'
,
'nick'
,
''
))
assert
vars
(
parse_log_line
(
line
,
'user@domain'
))
==
vars
(
LogMessage
(
'2017'
,
'09'
,
'08'
,
'07'
,
'05'
,
'04'
,
'003'
,
'nick'
,
''
))
def
test_log_and_parse_messages
():
def
test_log_and_parse_messages
():
...
@@ -27,7 +27,7 @@ def test_log_and_parse_messages():
...
@@ -27,7 +27,7 @@ def test_log_and_parse_messages():
msg2_utc
=
get_utc_time
(
msg2
[
'date'
])
msg2_utc
=
get_utc_time
(
msg2
[
'date'
])
assert
built_msg2
==
'MR %s 001 <toto> coucou
\n
coucou
\n
'
%
(
msg2_utc
.
strftime
(
'%Y%m%dT%H:%M:%SZ'
))
assert
built_msg2
==
'MR %s 001 <toto> coucou
\n
coucou
\n
'
%
(
msg2_utc
.
strftime
(
'%Y%m%dT%H:%M:%SZ'
))
assert
parse_log_lines
((
built_msg1
+
built_msg2
).
split
(
'
\n
'
))
==
[
assert
parse_log_lines
((
built_msg1
+
built_msg2
).
split
(
'
\n
'
)
,
'user@domain'
)
==
[
{
'time'
:
msg1
[
'date'
],
'history'
:
True
,
'txt'
:
'
\x19
5,-1}coucou'
,
'nickname'
:
'toto'
},
{
'time'
:
msg1
[
'date'
],
'history'
:
True
,
'txt'
:
'
\x19
5,-1}coucou'
,
'nickname'
:
'toto'
},
{
'time'
:
msg2
[
'date'
],
'history'
:
True
,
'txt'
:
'
\x19
5,-1}coucou
\n
coucou'
,
'nickname'
:
'toto'
},
{
'time'
:
msg2
[
'date'
],
'history'
:
True
,
'txt'
:
'
\x19
5,-1}coucou
\n
coucou'
,
'nickname'
:
'toto'
},
]
]
Maxime Buquet
@ppjet
mentioned in issue
#3466 (closed)
·
Mar 02, 2019
mentioned in issue
#3466 (closed)
mentioned in issue #3466
Toggle commit list
Maxime Buquet
@ppjet
mentioned in issue
#3467
·
Mar 02, 2019
mentioned in issue
#3467
mentioned in issue #3467
Toggle commit list
Maxime Buquet
@ppjet
mentioned in issue
#3468
·
Mar 02, 2019
mentioned in issue
#3468
mentioned in issue #3468
Toggle commit list
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