I use a Python library that uses the logging module. However, I made my own log function that my script uses internally.
Here's the logging function I want to utilize:
def log(name, content, swtch : bool = None, time = None): time = time or datetime.now(pytz.timezone('US/Pacific')) if swtch == True or swtch == None: toPrint = '{1.RED}{2}/{3}/{4} {5}:{6}:{7}:{8} {9} {0.BRIGHT}{1.GREEN}{10} {0.RESET_ALL}{11}{0.RESET_ALL}'.format( Style, Fore, str(time.month).zfill(2), str(time.day).zfill(2), str(time.year)[2:], str(time.hour % 12).zfill(2), str(time.minute).zfill(2), str(time.second).zfill(2), str(int(time.microsecond / 1000)).zfill(3), 'AM' if time.hour < 12 else 'PM', name, content ) print(toPrint) log_txt = '' if swtch == False or swtch == None: file = open('log.txt', 'r') log_txt = file.read() file.close() with open('log.txt', 'w') as file: text = '{0}/{1}/{2} {3}:{4}:{5}:{6} {7} {8} {9}'.format( str(time.month).zfill(2), str(time.day).zfill(2), str(time.year)[2:], str(time.hour % 12).zfill(2), str(time.minute).zfill(2), str(time.second).zfill(2), str(int(time.microsecond / 1000)).zfill(3), 'AM' if time.hour < 12 else 'PM', name, content ) file.write(log_txt + text + '\n') Let's work assuming that there's a logger named some_logger.
import logging log = logging.getLogger('some_logger') Is there a way to, instead of printing to stdout, pass positional arguments (representing log information) to another function instead? (To clarify: A function that will call log with the required args)