flog
Improved logging system for Python
Table of Contents
- Import
- Basic Usage
- Log Levels
- Runtime Log Level Configuration
- Using in Classes
- Using Outside Classes
- Message Categories
- Available Enums
- Configuration
- Developer Mode
- Examples
Import
import forloop_modules.flog as flog
# or
from flog_pkg.flog import FlogLogger, FlogLevel
Basic Usage
flog.debug("Debug message")
flog.minor_info("Minor info message")
flog.info("Info message")
flog.warning("Warning message")
flog.error("Error message")
flog.critical("Critical message")
Log Levels
Log levels from lowest to highest:
- DEBUG (10) - Detailed debugging information
- MINORINFO (15) - Minor informational messages
- INFO (20) - General informational messages
- WARNING (30) - Warning messages (yellow)
- ERROR (40) - Error messages (red)
- CRITICAL (50) - Critical error messages (red)
Runtime Log Level Configuration
Using the Logger Instance (flog_pkg)
# Set default log level (using enum)
flog.logger.set_log_level(flog.FlogLevel.DEBUG)
# Set log level using string (case-insensitive)
flog.logger.set_log_level("debug")
flog.logger.set_log_level("INFO")
flog.logger.set_log_level("Warning")
# Set log level for specific class
flog.logger.set_log_level(flog.FlogLevel.INFO, class_name="MyClass")
flog.logger.set_log_level("info", class_name="MyClass")
# Get current log level
level = flog.logger.get_log_level()
level = flog.logger.get_log_level(class_name="MyClass")
# Invalid log level raises ValueError
flog.logger.set_log_level("invalid") # Raises ValueError with helpful message
Direct FLOG_CONFIG Manipulation (works in both versions)
# Set default log level
flog.FLOG_CONFIG["DEFAULT"] = flog.FlogLevel.DEBUG
# Set log level for specific class
flog.FLOG_CONFIG["MyClass"] = flog.FlogLevel.INFO
# Get current log level
level = flog.FLOG_CONFIG.get("DEFAULT", flog.FlogLevel.WARNING)
Using in Classes
The logger automatically detects the class name from which it's called:
class MyClass:
def __init__(self):
flog.info("Initializing MyClass") # Automatically detects class name
def my_method(self):
flog.debug("Debug message from method")
Using Outside Classes
When called outside of a class, no class name is shown in the output:
flog.info("This is a standalone message") # No class name in output
Message Categories
Filter messages by category (default: "*" = all):
# Log with a specific category
flog.info("Message", message_category="important")
# Configure which categories to display
flog.MESSAGE_CATEGORIES = ["important", "errors"]
Available Enums
FlogLevel
CRITICALERRORWARNINGINFOMINORINFODEBUGNOTSET
LogColor
OKGREENERRORWARNINGBOLDCOLOROFF
Configuration
FLOG_CONFIG
Dictionary mapping class names to log levels:
- Default level:
WARNING - Pre-configured classes:
Wizard,Scanner,CleaningUtility,DfToListHandler
Example:
flog.FLOG_CONFIG["DEFAULT"] = flog.FlogLevel.INFO
flog.FLOG_CONFIG["MyClass"] = flog.FlogLevel.DEBUG
Developer Mode
- When
DEVELOPER_MODE=True: Colored output, timestamps, class names - When
DEVELOPER_MODE=False: Logging is disabled
Examples
Basic Logging
flog.info("Application started")
flog.warning("Low memory detected")
flog.error("Failed to connect to database")
Runtime Configuration
# Enable debug logging
flog.logger.set_log_level(flog.FlogLevel.DEBUG)
flog.debug("This will now be visible")
Class-Specific Configuration
# Set debug level for a specific class
flog.FLOG_CONFIG["DatabaseHandler"] = flog.FlogLevel.DEBUG
Using in a Class
class DeploymentSupervisor:
def supervise(self):
flog.info("Starting supervision")
flog.debug("Checking deployments...")
Help Method
You can also view this help in Python:
import forloop_modules.flog as flog
flog.help()
Metadata
Release files for flogg 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flogg-1.0.1.tar.gz | 7.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flogg-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.7 kB
Release files / flogg-1.0.1.tar.gz
| Download URL | flogg-1.0.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf8d2a17a713fb51c399a3eb23f259881cc1cae3c7ccb76ac0232aab966f68db
|
|
BLAKE2b-256 checksum How to use checksums |
4fb81fdb736c771bd49b68012e9dc3bbf4032247fd9bc209c27ac640784857c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / flogg-1.0.1-py3-none-any.whl
| Download URL | flogg-1.0.1-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
25aab96cd0f3932af611de7bb2665b66ea443d52c588aaba8a61c682d0e36471
|
|
BLAKE2b-256 checksum How to use checksums |
118a90c9bca45458b159845e6f50b2f730fa6ca716cc462278b7a91e4110c7be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|