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
Open sidebar
Trevor Cappallo
OperationalLogging
Commits
af69e2fd
Commit
af69e2fd
authored
Aug 19, 2015
by
Trevor Cappallo
Browse files
add option for emailing full log in body
parent
2c0024ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
lib/OperationalLogger.py
lib/OperationalLogger.py
+12
-2
No files found.
lib/OperationalLogger.py
View file @
af69e2fd
...
...
@@ -32,6 +32,10 @@ def __exit_handler(logger, notify):
else
:
addresses
=
list
(
set
(
addresses
))
logger
.
email_log
(
addresses
)
elif
'DEBUG'
in
notify
and
notify
[
'DEBUG'
]:
addresses
=
list
(
set
(
notify
[
'DEBUG'
]))
logging
.
info
(
'Sending full DEBUG email to addresses: %s'
,
', '
.
join
(
addresses
))
logger
.
email_log
(
addresses
)
else
:
logging
.
info
(
'No errors found. Email not sent'
)
...
...
@@ -132,12 +136,18 @@ class OperationalLogger:
"""Return whether any CRITICAL-level log statements in buffer."""
return
len
(
self
.
__critical_buffer
.
getvalue
())
>
0
def
email_log
(
self
,
addresses
,
from_address
=
None
):
def
email_log
(
self
,
addresses
,
from_address
=
None
,
level
=
logging
.
ERROR
):
"""Send email to addresses with current buffered errors."""
if
from_address
is
None
:
from_address
=
self
.
__from_address
logging
.
info
(
"Sending log email to %s"
,
addresses
)
message
=
"<br />
\n
"
.
join
([
self
.
__class__
.
__colorize
(
line
)
for
line
in
self
.
__error_buffer
.
getvalue
().
split
(
'
\n
'
)])
if
level
==
logging
.
CRITICAL
:
buf
=
self
.
__critical_buffer
.
getvalue
()
elif
level
==
logging
.
DEBUG
:
buf
=
self
.
__debug_buffer
.
getvalue
()
else
:
buf
=
self
.
__error_buffer
.
getvalue
()
message
=
"<br />
\n
"
.
join
([
self
.
__class__
.
__colorize
(
line
)
for
line
in
buf
.
split
(
'
\n
'
)])
OperationalMail
.
send_status
(
subject
=
'Errors detected {}:{}'
.
format
(
self
.
__server_name
,
os
.
path
.
basename
(
sys
.
argv
[
0
])),
message
=
message
,
to_list
=
addresses
,
from_address
=
from_address
,
...
...
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