A python module to log some messages easily into a file and in the console with helpful colors.
Started august, 10 2022
- python3
cd root_of_your_project
[ -d .git ] && git submodule add https://github.com/Mazettt/python-log.git log || git clone https://github.com/Mazettt/python-log.git log
pip install -r log/requirements.txtFirst import it:
import log.src.log as logThen log your first message:
# note: by default, it doesn't show the message in console
log.log("message")
# to show in console:
log.log("message", True)There is also a set of different colored messages:
# note: these functions print the message in the console by default
log.info("message") # blue
log.debug("message") # grey
log.success("message") # green
log.warning("message") # yellow
log.error("message") # red
log.critical("message") # purpleBy default, the log file is located in ./logs folder and is named "latest.log":
.
βββ main.py # your code
βββ log # log module
βββ logs # logs folder
βββ latest.log # log fileBut you can change it:
log.log("message", logFileName="new.log", logFolderPath="my_logs")If you want to reset your log file and keep a backup of the current one:
log.resetLogFile()
# note: if you have changed the default file or folder name, you need to specify it:
log.resetLogFile(logFileName="new.log", logFolderPath="my_logs")Now:
.
βββ main.py # your code
βββ log # log module
βββ logs # logs folder
βββ 2022-12-31_08h44m01.log # backup of latest.log
βββ latest.log # is now emptyAnother way to use it is to declare an object that will always remember your settings, so you don't have to worry about specifiing it in the functions:
myLog = log.LogClass(logFileName="new.log", logFolderPath="my_logs", showInConsole=True)
myLog.log("message")
myLog.resetLogFile()π€ Martin d'HΓ©rouville
- Github: @Mazettt
- LinkedIn: @martin-d-herouville