You can download this code by clicking the button below.
This code is now available for download.
This custom function takes a log level as an argument, randomly selects a log level, and then generates a random message and logs it.
Technology Stack : Loguru
Code Type : Custom function
Code Difficulty : Intermediate
import random
from loguru import logger
def random_log_message(level):
levels = ["debug", "info", "warning", "error", "critical"]
message = f"Random message at level {random.choice(levels)}"
logger.log(level, message)
return message