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
2c0024ba
Commit
2c0024ba
authored
Aug 19, 2015
by
Trevor Cappallo
Browse files
improve tests
parent
d7e626f3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
48 deletions
+6
-48
lib/OperationalLogger.py
lib/OperationalLogger.py
+6
-29
lib/OperationalMail.py
lib/OperationalMail.py
+0
-19
lib/TestZExit.py
lib/TestZExit.py
+0
-0
No files found.
lib/OperationalLogger.py
View file @
2c0024ba
...
...
@@ -27,11 +27,10 @@ def __exit_handler(logger, notify):
addresses
=
notify
[
'ERROR'
]
if
logger
.
has_critical
():
addresses
=
addresses
.
extend
(
notify
[
'CRITICAL'
])
addresses
=
list
(
set
(
addresses
))
if
not
addresses
:
logging
.
warning
(
'No recipients found. Email not sent'
)
else
:
addresses
=
list
(
set
(
addresses
))
logger
.
email_log
(
addresses
)
else
:
logging
.
info
(
'No errors found. Email not sent'
)
...
...
@@ -138,7 +137,7 @@ class OperationalLogger:
if
from_address
is
None
:
from_address
=
self
.
__from_address
logging
.
info
(
"Sending log email to %s"
,
addresses
)
message
=
"<br />
\n
"
.
join
([
__class__
.
__colorize
(
line
)
for
line
in
self
.
__error_buffer
.
getvalue
().
split
(
'
\n
'
)])
message
=
"<br />
\n
"
.
join
([
self
.
__class__
.
__colorize
(
line
)
for
line
in
self
.
__error_buffer
.
getvalue
().
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
,
...
...
@@ -147,11 +146,11 @@ class OperationalLogger:
@
staticmethod
def
__colorize
(
line
):
"""Add HTML markup for severity of log message."""
if
'
[
CRITICAL
]
'
in
line
:
if
'CRITICAL'
in
line
:
return
'<span style="color:red">{}</span>'
.
format
(
line
)
if
'
[
ERROR
]
'
in
line
:
if
'ERROR'
in
line
:
return
'<span style="color:red">{}</span>'
.
format
(
line
)
if
'
[
WARNING
]
'
in
line
:
if
'WARNING'
in
line
:
return
'<span style="color:blue">{}</span>'
.
format
(
line
)
return
line
...
...
@@ -278,7 +277,7 @@ def log_shell(arg_list, raise_err=False, return_output=False, **kwargs):
return_output: (like subprocess.check_output) returns any output
from shell call instead of the exit code
"""
logging
.
info
(
'S
tart
ing child process
of p
pid={}'
.
format
(
os
.
getp
p
id
()))
logging
.
info
(
'S
pawn
ing child process
from
pid={}'
.
format
(
os
.
getpid
()))
logging
.
info
(
'Executing: {}'
.
format
(
' '
.
join
(
arg_list
)))
try
:
my_name
=
os
.
path
.
basename
(
inspect
.
getfile
(
inspect
.
currentframe
()))
...
...
@@ -315,25 +314,3 @@ def stack_trace(log_level=logging.ERROR):
import
traceback
tb
=
traceback
.
format_exc
()
long_log
(
log_level
,
tb
)
if
__name__
==
'__main__'
:
setup
()
test
=
"""Blah
foo
bar
beer
bear
"""
logging
.
info
(
'Blah'
)
logging
.
debug
(
'Fin'
)
logging
.
error
(
'An error in testing, oh, no!!'
)
logging
.
critical
(
'Put up the Jimsignal!'
)
logging
.
error
(
test
)
c
=
[
'diff'
,
'a'
,
'b'
]
log_shell
(
c
)
try
:
raise
Exception
(
"I AM ERROR."
)
except
Exception
as
err
:
logging
.
debug
(
err
)
stack_trace
()
lib/OperationalMail.py
View file @
2c0024ba
...
...
@@ -59,22 +59,3 @@ def send_status(subject, message, to_list, from_address='no-reply@aer.com', repl
server
.
sendmail
(
from_address
,
to_list
,
mail
.
as_string
())
server
.
quit
()
return
if
__name__
==
'__main__'
:
msg
=
"""<P>Test of the OperationalMail module</P>
<P>Let us see if this works.</P>
<UL>
<LI>I am not sure it should</LI>
<LI>Do I really want it to?</LI>
<LI>So many questions.</LI>
</UL>
<P>Fin</P>
"""
default_addresses
=
[
'tcappallo@veriskclimate.com'
]
send_status
(
'Non-pyProcess Email Module'
,
msg
,
default_addresses
)
lib/TestExit.py
→
lib/Test
Z
Exit.py
View file @
2c0024ba
File moved
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