Verbose Terminal is a Python library that provides a simple and easy-to-use interface for displaying stylish messages in the terminal. It includes predefined styles for log, debug, info, success, warning, error and critical messages, and also has support for logging.
- Python 3.10+
You can install the package via pip:
pip install verbose-terminal
Import the console
class from the verbose_terminal
module and use its methods to print styled messages. The following examples demonstrate how to use the library:
from verbose_terminal import console
# Displaying messages with different styles
console.log("This is a plain message.")
console.debug("This is a debug message.")
console.info("Here is some information.")
console.success("Operation completed successfully!")
console.warning("This is a warning message.")
console.error("An error has occurred.")
console.critical("This is a critical message.")
By default, the verbose
flag is set to True
. This means that the messages will be displayed on the terminal. To not display messages in the terminal, set the verbose
flag to False
.
from verbose_terminal import console
# Displaying messages in the terminal
console.log("This message will be displayed.")
console.log("This message will not be displayed.", verbose=False)
Verbose Terminal can also log all messages to a file, whether they are printed to the terminal or not.
To enable logging, use the enable_logging
method and specify a log file:
from verbose_terminal import console
# Enable logging to 'messages.log'
console.enable_logging('messages.log')
Note: Logging should be enabled only once during the application initialization. If you enable logging again in another section of your code, the last enabled logging configuration will take precedence, and messages will be logged to the new file specified in the latest enable_logging
call.
from verbose_terminal import console
# Enable logging to 'initial_log.log'
console.enable_logging('initial_log.log')
# Enable logging again to 'new_log.log', this will override the previous log file
console.enable_logging('new_log.log')
In this example, all subsequent log messages will be saved to 'new_log.log', not 'initial_log.log'. Ensure you enable logging only once to avoid such conflicts.
By default, the log_level
flag is set to INFO
. Only messages will be recorded: info, success, warning, error and critical, if you want to add the debug and log messages you must pass the LOG
flag
from verbose_terminal import console
# Enable logging to 'messages.log'
console.enable_logging('messages.log', log_level='LOG')
To disable logging, use the disable_logging
method:
from verbose_terminal import console
# Disable logging
console.disable_logging()
To view the logs, use the view_logs
method:
from verbose_terminal import console
# View logs
print(console.view_logs())
To clear the logs, use the clear_logs
method:
from verbose_terminal import console
# Clear logs
console.clear_logs()
To save the logs to a file, use the save_logs
method:
from verbose_terminal import console
# Save logs to 'logs.txt'
console.save_logs('logs.txt')
To run the tests, run the following command:
pytest
This will execute the unit tests and display the styled messages in the terminal, allowing you to visually verify the output.
Contributions are welcome! If you'd like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes and push your branch to GitHub.
- Submit a pull request.
Please see the CONTRIBUTING.md file for more details.
Feel free to explore the code and customize the styles as per your requirements. If you encounter any issues or have suggestions for improvements, please open an issue on GitHub.
Please see the CHANGELOG.md file for details on recent changes and releases.
This project is licensed under the MIT License. See the LICENSE file for more details.