-
Notifications
You must be signed in to change notification settings - Fork 10
/
infomercial.py
57 lines (32 loc) · 1008 Bytes
/
infomercial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"""
"Has this ever happened to you?"
Here's an example of some ostensibly well-instrumented code.
"""
import logging
_user():
'a dummy function that supposedly creates the user'
return None
def create_user(name):
logging.info('creating user with name %r', name)
try:
user = _create_user()
if user is not None:
logging.info('successfully created user %r', name)
else:
logging.error('failed to create user %r', name)
except Exception:
logging.critical('exception encountered while creating user %r',
name, exc_info=True)
return user
"""
Notice how the logging statements tend to dominate the code, almost
drowning out the meaning of the code.
Here's lithoxyl's take
"""
from log import dal_log
def create_user(name):
with dal_log.critical('user creation', reraise=False) as act:
user = _create_user()
if user is None:
act.failure()
return user