1 log level: 2 'critical ': critical, 3 'error': error, 4 'warn': warning, 5 'warning': warning, 6 'info': info, 7 'debug': Debug, 8 'notset': notset,
Import logginglogging. warning ("User [WY] attempted wrong password more than 3 times") logging. critical ("server is down") Output: Warning: Root: User [WY] attempted wrong password more than 3 timescritical: Root: Server is down how to write logs to files? Import logginglogging. basicconfig (filename = "example. log ", level = logging. info) # The filename is followed by the log file name and the level is info. The log file records logging logs at or above the info level. warning ("User [WY] attempted wrong password more than 3 times") logging.info ("show this") logging. debug ("this is erro") logging. critical ("server is down") generates a new file example. logexample. log Record: Warning: Root: User [WY] attempted wrong password more than 3 timesinfo: Root: Show thiscritical: Root: Server is down Log Level: Debug <info <warning <critical
1 how to add time to logs? 2 Import logging 3 logging. basicconfig (filename = "example. log ", level = logging. info, format = "% (asctime) S % (Message) s", datefmt = "% m/% d/% Y % I: % m: % S % P ") # Note: Case Sensitive 4 logging. warning ("User [WY] attempted wrong password more than 3 times") 5 logging.info ("show this") 6 logging. debug ("this is erro") 7 logging. critical ("server is down") 8 9 example. log display: 10 10/20/2016 08:49:32 PM user [WY] attempted wrong password more than 3 times11 10/20/2016 08:49:32 PM show this12 10/20/2016 08:49:32 PM server is down
Log processing-logging Module