-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample-1.py
32 lines (25 loc) · 945 Bytes
/
example-1.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
# -*- coding: utf-8 -*-
from loggable import loggable_method as loggable
import logging
import sys
# this is just an example config
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
class Example1(object):
@loggable(__name__)
def decorated_method_with_name(self):
self.logger.debug("Debug decorated_method_with_name")
print("This is a decorated method")
@loggable
def decorated_method_without_name(self):
self.logger.debug("Debug decorated_method_without_name")
print("This is a decorated method")
def undecorated_method(self):
print("This is an undecorated method")
try:
self.logger.debug("This trows an error")
except Exception as e:
print("Expected error: {}".format(e))
if __name__ == "__main__":
Example1().decorated_method_with_name()
Example1().decorated_method_without_name()
Example1().undecorated_method()