Package: uglylogger
uglyloggerAn ugly, slow Logger class for pythonFAQWhy required python version is equal or greater than 3.10?match .. case .. is introduced in3.10and I am not interested in supporting older releasesWhy is it ugly?I am not an expert on PythonIt is not thread-safeI don't know what happens if two instances are created with the same name, and I don't care. I'd never do thatThe solo purpose is to have an easy to use and easy to read logger classWhy is it ugly but not that ugly?it is easy to use and easy to readI may keep this library up-to-date and even optimize it in the futureat least it has a CI/CD pipelineInstallationpip install uglyloggerRelease NotesRelease notesUsageInstantiate# A logger which can log both to console and to a file
logger = Logger("name", "file.log")  

# A logger which can only log to console
logger = Logger("name")Release the resourceslogger.release()Releases the resources, it's safe to delete the log file after calling this methodColor Modelogger.set_color_mode(LogColorMode.COLORED)coloroed output if the console/terminal supports itlogger.set_color_mode(LogColorMode.MONO)no color used for the console/terminal outputLog to consolelogger.console("Message", color=LogColor.BLACK, level=LogLevel.DEBUG)color and level are optionalif not provided, default color is BLACKif not provided, default level is DEBUGLog to filelogger.file("Message", level=LogLevel.DEBUG)level is optionalif not provided, default level is DEBUGif instantiated without a file name, nothing happensLog to both file and consolelogger.log("Message", color=LogColor.BLACK, level=LogLevel.DEBUG, output=LogOutput.ALL)color, level and output are optionalif not provided, default color is BLACKif not provided, default level is DEBUGif not provided, default output is ALLif instantiated without a file name, writing to file is ignoredOther ways of logginglogger.debug("Message", color=LogColor.BLACK, output=LogOutput.ALL)logger.info("Message", color=LogColor.BLACK, output=LogOutput.ALL)logger.warning("Message", color=LogColor.BLACK, output=LogOutput.ALL)logger.error("Message", color=LogColor.BLACK, output=LogOutput.ALL)logger.critical("Message", color=LogColor.BLACK, output=LogOutput.ALL)Available LogColor- BLACK
- RED
- GREEN
- YELLOW
- BLUE
- MAGENTA
- CYAN
- WHITEAvailable LogLevel- DEBUG
- INFO
- WARNING
- ERROR
- CRITICALAvailable LogOutput- NONE
- CONSOLE
- FILE
- ALLset log formatlogger.set_format([
    ...
    LogFormatBlock.XXX
    ...
])Available LogFormatBlock- NAME
- LEVEL
- DATETIME
- MESSAGE
- FILE
- LINE
- FUNCTIONExample Formatslogger.set_format([LogFormatBlock.MESSAGE])
logger.console("Hello World!")
# Output : Hello World!logger.set_format([
    "[",
    LogFormatBlock.LEVEL,
    "] ",
    LogFormatBlock.MESSAGE]
)
logger.console("Hello World!")
# Output : [DEBUG] Hello World!Move the log file to another locationlogger.move(new_file: str, option: LogMoveOption)
# Output : Hello World!Available LogMoveOption- MOVE_AND_APPEND  
   Moves the log file to the destination
   Deletes if there's already a file in the destination
   Appends to the moved file
   Old file is obviously deleted
- COPY_AND_APPEND  
   Copies the log file to the destination
   Deletes if there's already a file in the destination
   Appends to the moved file
   Old file is obviously remains    
- KEEP_AND_APPEND  
   Keeps the old log file
   Appends if there's already a file in the destination
   Creates a new file if not
- KEEP_AND_INIT  
   Keeps the old log file
   Creates a new file in the destination    
- DELETE_AND_INIT  
   Deletes the old log file
   Creates a new file in the destination