Opengist

Explore

  • All gists
  • Topics
  • Users
Give feedback on the new UI Powered by Opengist ⋅ 835ms

user:thomas gists created by user

title:mygist gists with given title

description:sync gists with given description

filename:myfile.txt gists having files with given name

extension:yml gists having files with given extension

language:go gists having files with given language

topic:homelab gists with given topic

all:systemctl search all fields

Login
t

tracking

Recently created Least recently created Recently updated Least recently updated

timmy / LoggingMixin 日誌功能擴展

Last active 5 hours ago debugging logging mixin oop python tracking

此 Mixin 類別為 Python 類別提供簡單的日誌紀錄功能,可用於追蹤物件的行為變化,適用於擴展任何需要日誌記錄的類別,如用戶管理、系統監控等應用。

0 0 0 1
1 import datetime
2
3 class LoggingMixin:
4 """ 提供日誌功能的 Mixin 類別 """
5
6 def log(self, message):
7 """ 簡單的日誌紀錄方法 """
8 timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
9 print(f"[{timestamp}] {self.__class__.__name__}: {message}")