Article From:
# !/user/bin/python
# -*- coding: utf-8 -*-
subprocess : You need to test shell on the Linux platformLogging'''

import logging
# Output the log in the file
# logging.basicConfig(filename="app.log", level=logging.DEBUG)
                    format='%(asctime)s %(levelname)s  %(filename)s:%(lineno)d  - %(message)s',
                    datefmt='%m/%d/%Y %I:%M:%S %p')  # Time is added to the log.%p stands for pm. TODO. Why didn't she take the number of trips?
logging.debug("test debug")"test info")
logging.error("test error")
logging.warning("User [alex] attempted wrong password more than 3 times")

# At the same time, print the log on the screen and output it in the file.
# step 1, create logger
logger = logging.getLogger("TEST-LOG")

# step2, create console handler and set level to debug

# step3, create file handler and set level to warning
fh = logging.FileHandler("process.log")

# step3, define format
fh_formatter = logging.Formatter('%(asctime)s %(levelname)s  %(filename)s:%(lineno)d  - %(message)s')
ch_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')


# step4, connect handlers to logger



Level When it’s used
DEBUG Detailed information, typically of interest only when diagnosing problems.
INFO Confirmation that things are working as expected.
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.
ERROR Due to a more serious problem, the software has not been able to perform some function.
CRITICAL A serious error, indicating that the program itself may be unable to continue running.

Similar Posts:

Link of this Article: Python logger /logging

Leave a Reply

Your email address will not be published. Required fields are marked *