Package: logg3r
OverviewSetting up logging sucks, this makes it easierFeaturesSimple logger set upCreates log directory and filename as described inLoginitializationPrints all log entries to the terminal incolorfor easier debuggingPromotes loggingduringdevelopment, not after. Reduce your tech debt.UseStandard Usefromlogg3rimportLoglogger=Log(log_path="./path-to/log-directory",name="test_log",level=1)logger.debug("test message")logger.info("test message")logger.warning("test message")logger.error("test message")logger.critical("test message")Log file exampletest_log.log2023-07-29 03:13:27 | DEBUG | test message
2023-07-29 03:13:27 | INFO | test message
2023-07-29 03:13:27 | WARNING | test message
2023-07-29 03:13:27 | ERROR | test message
2023-07-29 03:13:27 | CRITICAL | test messageTerminal ExampleLog with line numbers  -recommendedfromlogg3rimportLoglogger=Log(log_path="./path-to/log-directory",name="test_log",level=1)line=logger.line#must be called from the line being loggedlogger.debug(line()+"test message")logger.info(line()+"test message")logger.warning(line()+"test message")logger.error(line()+"test message")logger.critical(line()+"test message")Log file exampletest_log.log2023-07-29 03:30:25 | DEBUG | 7 test message
2023-07-29 03:30:25 | INFO | 8 test message
2023-07-29 03:30:25 | WARNING | 9 test message
2023-07-29 03:30:25 | ERROR | 10 test message
2023-07-29 03:30:25 | CRITICAL | 11 test messageTerminal ExampleInitialization Keyword ArgumentsRequiredlog_path(string)If the path does not exist (andcreate_pathis notFalse)logg3rwill create the directoryname(string)Sets the name of your log file - file will present as "filename.log" in your log directorylevel(integer)Seelog levelsSets minimum level of log message that will be stored in the log file (all log function calls print to terminal)Optionalprint_filename(bool)fromlogg3rimportLogLogger=Log(log_path="./path-to/log-directory",name="test_log",level=1,print_filename=True)Defaults toFalseIf enabled, the filename will print in the first section of the log message in the terminal - the filename will not be written to the log fileformatter(string)fromlogg3rimportLogfmt='{}|%(levelname)s|%(message)s'.format(datetime.datetime.utcnow().replace(microsecond=0))Logger=Log(log_path="./path-to/log-directory",name="test_log",level=1,formatter=fmt)The formatter can be any string you like%(levelname)sisrequiredand corresponds to thelog level%(message)sisrequiredand is the message passed when calling any of the log functionsIn the example above the date and time are represented at{}and formatted with.format(datetime.datetime.utcnow().replace(microsecond=0))Any other string elements can be added to the formatterrotation(tuple)fromlogg3rimportLogrotation_args=filename,when='d',interval=30,backupCount=1,encoding=None,delay=False,utc=True,atTime=datetime.time(4,0,0)Logger=Log(log_path="./path-to/log-directory,name="test_log",level=1,rotation=rotation_args)SeePython Logging TimedRotatingFileHandlerDefaults to 30 days of retention with (1) log overflow file (log.1)create_path(bool)Defaults toTrueIf set toFalseinitializinglogg3rwill not create a new log directory, but will put the file in the directory passed tolog_pathLog Levels1= DEBUG (green)2= INFO (cyan)3= WARNING (yellow)4= ERROR (magenta)5= CRITICAL (red)logg3r.LogFunctions.debugCreatesdebug levellog message entry to log filePrints message in color to terminallogger.debug("log message").infoCreatesinfo levellog message entry to log filePrints message in color to terminallogger.info("log message").warningCreateswarning levellog message entry to log filePrints message in color to terminallogger.warning("log message").errorCreateserror levellog message entry to log filePrints message in color to terminallogger.error("log message").criticalCreatescritical levellog message entry to log filePrints message in color to terminallogger.critical("log message").lineReturns line number of the code where the function is called - unfortunately this couldn't be integrated automatically because the function must be called from the line being loggedline=logger.linelogger.debug(line()+"log_message")Referenceshttps://docs.python.org/3.8/library/logging.handlers.html#timedrotatingfilehandlerhttps://docs.python.org/3.8/library/logging.html