log-sample.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import logging
  2. # DEBUG: Detailed information, typically of interest only when diagnosing problems.
  3. # INFO: Confirmation that things are working as expected.
  4. # WARNING: An indication that something unexpected happened, or indicative of some problem in the near future (e.g. ‘disk space low’). The software is still working as expected.
  5. # ERROR: Due to a more serious problem, the software has not been able to perform some function.
  6. # CRITICAL: A serious error, indicating that the program itself may be unable to continue running.
  7. logging.basicConfig(filename='test.log', level=logging.DEBUG,
  8. format='%(asctime)s:%(levelname)s:%(message)s')
  9. def add(x, y):
  10. """Add Function"""
  11. return x + y
  12. def subtract(x, y):
  13. """Subtract Function"""
  14. return x - y
  15. def multiply(x, y):
  16. """Multiply Function"""
  17. return x * y
  18. def divide(x, y):
  19. """Divide Function"""
  20. return x / y
  21. num_1 = 20
  22. num_2 = 10
  23. add_result = add(num_1, num_2)
  24. logging.debug('Add: {} + {} = {}'.format(num_1, num_2, add_result))
  25. sub_result = subtract(num_1, num_2)
  26. logging.debug('Sub: {} - {} = {}'.format(num_1, num_2, sub_result))
  27. mul_result = multiply(num_1, num_2)
  28. logging.debug('Mul: {} * {} = {}'.format(num_1, num_2, mul_result))
  29. div_result = divide(num_1, num_2)
  30. logging.debug('Div: {} / {} = {}'.format(num_1, num_2, div_result))