-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.py
43 lines (30 loc) · 1.01 KB
/
main.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
import io
import logging
import sys
def stderr_logger():
logger = logging.getLogger('stderr_logger')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(stream=sys.stderr) # also the default
logger.addHandler(handler)
logger.info('This is through sys.stderr!')
def stdout_logger():
logger = logging.getLogger('stdout_logger')
logger.setLevel(logging.INFO)
handler = logging.StreamHandler(stream=sys.stdout) # also the default
logger.addHandler(handler)
logger.info('This is through sys.stdout!')
def bytestream_logger():
# A file "stream"
logger = logging.getLogger('bytestream_logger')
logger.setLevel(logging.INFO)
with io.BytesIO() as _buffer:
handler = logging.StreamHandler(stream=_buffer)
logger.addHandler(handler)
logger.info('This is being written to an I/O buffer!')
print(_buffer.getvalue())
def main():
stderr_logger()
stdout_logger()
bytestream_logger()
if __name__ == '__main__':
main()