'How Do I set different log levels for different situations?
I did a lot of searching and checking to see if anyone had gone through something similar, but apparently not. My situation currently revolves around the fact that I cannot set multiple log levels for different situations for some reason.
In my case, I am working on setting log levels to conditional statements, and if those statements are true, then to make a log to a file. This works perfectly, and I'm just using the level INFO for it. The code below:
if n == 1:
print("Arduino: Connection Established")
logging.info("Arduino: Connection Established. Device Healthy")
However, I wanted to see if I could test out DEBUGS and WARNINGS on it as well, and tried it on another part of the code to see if it would work.
def setCoordinate(x_coord, y_coord):
coord = ("("+ str(x_coord) + "," + str(y_coord) + ")")
i2cWrite(coord)
logging.warning('Coordinate: {}'.format(coord))
When I had tried it, this was the result: The Result
At first, I thought this would have been due to setting the logging's basicConfig level to be INFO, so when I removed it and tried again, nothing changed.
logging.basicConfig(filename='I2CHealth.log', level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s')
What went wrong? What am I supposed to do here? I have tried to find relevant information about this online but found nothing relevant.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|