-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathlogger.py
35 lines (27 loc) · 1 KB
/
logger.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
"""
Python Logging
- Captures and records events while app is running
- Events can be categorized for easier analysis
- Highly customizable outputs
- Debugging
"""
import logging
def main():
# Use basicConfig to configure logging
# this is only executed once, subsequent calls to
# basicConfig will have no effect
logging.basicConfig(level=logging.INFO,
filemode="w",
filename="output.log",
format="%(asctime)s [%(levelname)s] %(message)s",
)
# Try out each of the log levels
logging.debug("This is a debug-level log message")
logging.info("This is an info-level log message")
logging.warning("This is a warning-level message")
logging.error("This is an error-level message")
logging.critical("This is a critical-level message")
# Output formatted string to the log
logging.info("Here's a {} variable and an int: {}".format("string", 10))
if __name__ == "__main__":
main()