0

In my test, I am using python logger for logging the messages, My messages are either info or error. I want to qualify my test as pass or fail based on error messages. Is there any way, I can count error messages using logger and return no. of errors back to my test.

  • Can't you just create a variable and increment it on each log – Aven Desta Apr 01 '20 at 18:13
  • we can always do that, but always we have to increment that variable, lets say from my test I am printing 1000 error messages, so I have to increment that variables 1000 times. I am looking if logger automates such thing – Irshad Mansur Apr 01 '20 at 18:16
  • I would probably monkeypatch `logging.error` to increment some counter. – Adam Smith Apr 01 '20 at 18:27
  • 1
    correct. as @AdamSmith, said. [here](https://stackoverflow.com/questions/812477/how-many-times-was-logging-error-called) is a similar approach using decorators. I wouldn't expect the logging module to support this because it all depends on your run time code. – Aven Desta Apr 01 '20 at 18:29

0 Answers0