You can download this code by clicking the button below.
This code is now available for download.
This function logs a random message with a given log level based on the input log level.
Technology Stack : Loguru
Code Type : Function
Code Difficulty : Intermediate
import random
import loguru
from loguru import logger
def random_log_message(level):
"""
This function logs a random message with a given log level.
"""
levels = ["info", "debug", "warning", "error", "critical"]
message = f"Random log message at {random.choice(levels)} level."
logger.log(level, message)
# JSON representation of the code