Skip to main content

A timezone-configurable logging package based on loguru with Shanghai timezone as default

Project description

LogFtz - Timezone-Configurable Logging Package

A Python logging package based on loguru with configurable timezone support. Defaults to Shanghai timezone (Asia/Shanghai) but allows users to set any timezone.

Features

  • 🕐 Configurable timezone support (defaults to Asia/Shanghai)
  • 📊 Configurable minimum log level (defaults to INFO)
  • 📝 Clean log format: MM-DD HH:mm:ss|LEVEL|MESSAGE
  • 📁 Automatic daily log file rotation
  • 🗂️ Automatic retention of last 3 days of log files
  • 🚀 Built on high-performance loguru library
  • 🌍 International support with English interface

Installation

Install dependencies

pip install logftz

Usage

Basic Usage

from logftz import logger

# Log with different levels
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.debug("This is a debug message")

Timezone Configuration

from logftz import logger, set_timezone

# Set timezone globally
set_timezone('UTC')
logger.info("This message uses UTC timezone")

# Set to New York timezone
set_timezone('America/New_York')
logger.info("This message uses New York timezone")

# Back to Shanghai timezone (default)
set_timezone('Asia/Shanghai')
logger.info("This message uses Shanghai timezone")

Log Level Configuration

from logftz import logger, set_level

# Set minimum log level to DEBUG (show all logs)
set_level('DEBUG')
logger.debug("This debug message will now be shown")

# Set minimum log level to WARNING (hide INFO and DEBUG)
set_level('WARNING')
logger.info("This info message will be hidden")
logger.warning("This warning message will be shown")

Advanced Usage with Custom Configuration

from logftz import LoggerConfig

# Create a custom logger configuration with timezone and level
config = LoggerConfig(timezone='Europe/London', level='DEBUG')

# Change timezone or level later
config.set_timezone('Asia/Tokyo')
config.set_level('WARNING')

Log Output Example

12-25 14:30:15|INFO|This is an info message
12-25 14:30:16|WARNING|This is a warning message
12-25 14:30:17|ERROR|This is an error message

Configuration

  • Default Timezone: Asia/Shanghai
  • Log Level: INFO and above
  • File Path: logs/YYYY-MM-DD.log
  • Rotation: Daily rotation
  • Retention: Keep last 3 days of log files
  • Format: MM-DD HH:mm:ss|LEVEL|MESSAGE

Supported Timezones

You can use any timezone supported by pytz, including:

  • UTC
  • Asia/Shanghai
  • Asia/Tokyo
  • Europe/London
  • America/New_York
  • America/Los_Angeles
  • And many more...

Project Structure

logftz/
├── logftz/
│   ├── __init__.py    # Package initialization and public API
│   └── log.py         # Core logging configuration
├── setup.py           # Installation configuration
├── requirements.txt   # Dependencies
└── README.md         # Documentation

Dependencies

  • loguru >= 0.6.0
  • pytz >= 2021.1

API Reference

Functions

  • set_timezone(timezone: str): Set the global timezone for logging
  • set_level(level: str): Set the minimum log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)

Classes

  • LoggerConfig(timezone: str = 'Asia/Shanghai', level: str = 'INFO'): Create a custom logger configuration
    • set_timezone(timezone: str): Change the timezone for this configuration
    • set_level(level: str): Change the minimum log level for this configuration

Variables

  • logger: The main logger instance (loguru logger)

License

MIT License

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

logftz-3.0.2.tar.gz (6.3 kB view details)

Uploaded Source

File details

Details for the file logftz-3.0.2.tar.gz.

File metadata

  • Download URL: logftz-3.0.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for logftz-3.0.2.tar.gz
Algorithm Hash digest
SHA256 12ffe355cf9972d77bb6f277d9b47f1566c949ef6b7639fa439644373e8f6b4a
MD5 eb61d5d72d6fcfc9fd42ea9dd771c869
BLAKE2b-256 282f5a1e49fd546376a6b57db4e8267cafa8351543bda757730bcc27463717f8

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