Skip to content

A python module to log some messages easily into a file and in the console with helpful colors.

License

Notifications You must be signed in to change notification settings

Mazettt/python-log

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python Log

A python module to log some messages easily into a file and in the console with helpful colors.

Started august, 10 2022

Requirements

  • python3

Install

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.txt

Usage

First import it:

import log.src.log as log

Then 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") # purple

By 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 file

But 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 empty

Another 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()

Authors

👤 Martin d'Hérouville

About

A python module to log some messages easily into a file and in the console with helpful colors.

Resources

License

Stars

Watchers

Forks

Languages