A simple and efficient logging utility for Python applications
Project description
Superyngo Logger
A simple and efficient logging utility for Python applications. My Logger provides an easy-to-use logging solution with file rotation, custom formatting, and log cleanup capabilities.
✨ Features
- 簡單初始化: 一行代碼即可設置完整的日誌系統
- 文件輪轉: 自動管理日誌文件大小和數量
- 日誌清理: 自動清理舊的日誌文件
- 彩色輸出: 控制台輸出支援彩色日誌
- 靈活配置: 支援自定義日誌格式和輸出路徑
- Multiton 模式: 相同路徑的 logger 實例復用
🚀 Installation
pip install superyngo-logger
📖 Quick Start
Basic Usage
from superyngo_logger import init_logger
from pathlib import Path
# 初始化 logger(使用預設設置)
logger = init_logger()
# 開始記錄日誌
logger.info("這是一條資訊日誌")
logger.warning("這是一條警告日誌")
logger.error("這是一條錯誤日誌")
Advanced Usage
from superyngo_logger import init_logger, clean_logs
from pathlib import Path
# 自定義日誌目錄和應用名稱
log_dir = Path("./logs")
logger = init_logger(
log_dir=log_dir,
app_name="my_app"
)
# 記錄不同級別的日誌
logger.debug("調試資訊")
logger.info("程式正常運行")
logger.warning("注意:某些條件可能需要關注")
logger.error("發生錯誤")
logger.critical("嚴重錯誤!")
# 清理10天前的舊日誌文件
clean_logs(log_dir, days_count=10)
Custom Configuration
from superyngo_logger import init_logger
from pathlib import Path
# 使用自定義配置文件
config_path = Path("./my_logging.conf")
logger = init_logger(
log_dir=Path("./custom_logs"),
config_path=config_path,
app_name="custom_app"
)
📝 API Reference
init_logger(log_dir=None, config_path=None, app_name="myapp")
初始化並返回一個 logger 實例。
參數:
log_dir(Path, optional): 日誌文件目錄。預設為執行檔案目錄下的 "Logs" 資料夾config_path(Path, optional): 自定義配置文件路徑。如果不存在則使用預設配置app_name(str): 應用程式名稱,用於日誌文件命名。預設為 "myapp"
返回:
Logger: 配置好的 logger 實例
clean_logs(log_dir, days_count=10)
清理指定目錄中的舊日誌文件。
參數:
log_dir(Path): 包含日誌文件的目錄路徑days_count(int): 保留日誌文件的天數。預設為 10 天
🔧 Configuration
Logger 支援兩種配置方式:
1. 預設配置(字典格式)
程式內建的預設配置包含:
- 控制台處理器:彩色輸出,DEBUG 級別
- 文件處理器:純文字輸出,INFO 級別
- 自動日誌輪轉和時間戳
2. 配置文件格式
您可以提供一個 .conf 格式的配置文件來自定義日誌行為:
[loggers]
keys=root
[handlers]
keys=consoleHandler,fileHandler
[formatters]
keys=formatter
[logger_root]
level=DEBUG
handlers=consoleHandler,fileHandler
[handler_consoleHandler]
class=StreamHandler
level=DEBUG
formatter=formatter
args=(sys.stdout,)
[handler_fileHandler]
class=FileHandler
level=INFO
formatter=formatter
args=('app.log', 'a')
[formatter_formatter]
format=%(asctime)s - %(levelname)s - %(message)s
📁 Project Structure
superyngo-logger/
├── src/
│ └── superyngo_logger/
│ ├── __init__.py # 套件入口
│ ├── logger_module.py # 主要功能模組
│ └── config.py # 配置和格式化
├── tests/ # 測試文件
├── docs/ # 文檔
├── README.md
├── LICENSE
├── CHANGELOG.md
└── pyproject.toml
🧪 Development
安裝開發依賴
pip install -e ".[dev]"
運行測試
pytest
代碼格式化
black src tests
isort src tests
類型檢查
mypy src
📄 License
本專案使用 MIT 授權條款 - 詳見 LICENSE 文件。
🤝 Contributing
歡迎貢獻!請先閱讀我們的貢獻指南。
- Fork 這個專案
- 創建您的功能分支 (
git checkout -b feature/AmazingFeature) - 提交您的更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 開啟一個 Pull Request
📮 Support
如果您有任何問題或建議,請通過以下方式聯繫:
- 📧 Email: superyngo@gmail.com
- 🐛 Issues: GitHub Issues
📝 Changelog
查看 CHANGELOG.md 以了解每個版本的更改內容。
Made with ❤️ by Wenyang
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file superyngo_logger-0.0.2.tar.gz.
File metadata
- Download URL: superyngo_logger-0.0.2.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d75a2f6c7681793a2bce45c21a86b230a73433d1df1c5b105bdf95949564d70c
|
|
| MD5 |
6c78ca813d30725502b859e708b11a3c
|
|
| BLAKE2b-256 |
a2328b9fba809ce5ddac1cdb106abfaef6915d61206439ca1f355d40aa3e1e81
|
Provenance
The following attestation bundles were made for superyngo_logger-0.0.2.tar.gz:
Publisher:
publish.yml on superyngo/my_logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
superyngo_logger-0.0.2.tar.gz -
Subject digest:
d75a2f6c7681793a2bce45c21a86b230a73433d1df1c5b105bdf95949564d70c - Sigstore transparency entry: 229350906
- Sigstore integration time:
-
Permalink:
superyngo/my_logger@5c52d575ed8aa82291385e2fb7bb5291ac4bfe0e -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/superyngo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5c52d575ed8aa82291385e2fb7bb5291ac4bfe0e -
Trigger Event:
push
-
Statement type:
File details
Details for the file superyngo_logger-0.0.2-py3-none-any.whl.
File metadata
- Download URL: superyngo_logger-0.0.2-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b285463cf8e52f9808cecbe118327bdf6dc7cb3df5a939c4a5577d5fe1eb8d9a
|
|
| MD5 |
8e511ccfa6a6ee5c2b0836227c3700ac
|
|
| BLAKE2b-256 |
fa5ed0d89563984d517371ffb7cd4807f7ea1a2a026b22e6a3a13c7b7507c9a8
|
Provenance
The following attestation bundles were made for superyngo_logger-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on superyngo/my_logger
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
superyngo_logger-0.0.2-py3-none-any.whl -
Subject digest:
b285463cf8e52f9808cecbe118327bdf6dc7cb3df5a939c4a5577d5fe1eb8d9a - Sigstore transparency entry: 229350907
- Sigstore integration time:
-
Permalink:
superyngo/my_logger@5c52d575ed8aa82291385e2fb7bb5291ac4bfe0e -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/superyngo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5c52d575ed8aa82291385e2fb7bb5291ac4bfe0e -
Trigger Event:
push
-
Statement type: