-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
37 lines (26 loc) · 1.05 KB
/
Copy pathexample.py
File metadata and controls
37 lines (26 loc) · 1.05 KB
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
from custom_logger import CustomLogger
class ExampleClass:
def __init__(self, name: str, format: str = 'text'):
self.logger = CustomLogger(name=name, format=format)
def sample_method(self):
self.logger.info('Protocol problem: connection reset')
if __name__ == '__main__':
# Example 1: Text format
print('=== Text Format ===')
logger_text = CustomLogger(name='fbloggsfunction', format='text')
logger_text.info('Protocol problem: connection reset')
print()
# Example 2: JSON format
print('=== JSON Format ===')
logger_json = CustomLogger(name='fbloggsfunction', format='json')
logger_json.info('Protocol problem: connection reset')
print()
# Example 3: Text format with class
print('=== Text Format with Class ===')
example_text = ExampleClass('MyApp', format='text')
example_text.sample_method()
print()
# Example 4: JSON format with class
print('=== JSON Format with Class ===')
example_json = ExampleClass('MyApp', format='json')
example_json.sample_method()