Skip to main content

Improved logging system for Python

Project description

flog

Improved logging system for Python

Table of Contents

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

  • CRITICAL
  • ERROR
  • WARNING
  • INFO
  • MINORINFO
  • DEBUG
  • NOTSET

LogColor

  • OKGREEN
  • ERROR
  • WARNING
  • BOLD
  • COLOROFF

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flogg-1.0.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flogg-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file flogg-1.0.0.tar.gz.

File metadata

  • Download URL: flogg-1.0.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for flogg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2337eb09848db7b9fed46a62352e01d13f6ace060796f4595f605b86fedcc382
MD5 ade2294cf1171a323eada23d4e71ba3b
BLAKE2b-256 ca4a2893aa0c7937ac0cdda99824fefd857f9d0693f5ac63bbd04d91622a37e0

See more details on using hashes here.

File details

Details for the file flogg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: flogg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for flogg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 723390177e2be7811a8836fa74eb8de1cfe01086f4cc0ab4e29b7c54b6211904
MD5 8f36e7706a65f95fabc40ce62369fd26
BLAKE2b-256 92fc64fd7cc95e1ac75c625126c17c362f3c5ed2c79bc9941d5660f001699d59

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page