11#!/usr/bin/env python3
22"""
3- SmartLogger Demo - نمایش قابلیتهای رنگی سیستم لاگ
3+ SmartLogger Complete Demo - تست جامع قابلیتهای رنگی
44"""
55
66import time
77import logging
8+ import os
9+ import sys
10+
11+ print ("🔍 SmartLogger Environment Check:" )
12+ print (f"Terminal supports colors: { sys .stdout .isatty ()} " )
13+ print (f"Platform: { sys .platform } " )
14+ print (f"TERM: { os .environ .get ('TERM' , 'Not set' )} " )
15+
16+ # تست رنگ ANSI مستقیم
17+ print ("\n 🎨 Direct ANSI Color Test:" )
18+ print (f"\033 [31mRed\033 [0m \033 [32mGreen\033 [0m \033 [33mYellow\033 [0m \033 [34mBlue\033 [0m" )
19+
20+ # فعال کردن force color برای اطمینان
21+ os .environ ['FORCE_COLOR' ] = '1'
822
923# فعالسازی SmartLogger
1024import smartlogger .auto
@@ -146,11 +160,42 @@ def demo_error_scenarios():
146160 getattr (error_logger , level )(f"{ level .upper ()} : { message } " )
147161 time .sleep (0.5 )
148162
163+ def demo_force_color_test ():
164+ """تست با force color برای محیطهای مختلف"""
165+ print ("\n 🔧 === Demo: Force Color Test ===" )
166+
167+ from smartlogger import ColoredStreamHandler , ColoredFormatter
168+
169+ # ایجاد handler با force color
170+ handler = ColoredStreamHandler (sys .stdout , force_color = True )
171+ formatter = ColoredFormatter ('%(levelname)s: %(message)s' )
172+ handler .setFormatter (formatter )
173+
174+ force_logger = logging .getLogger ('ForceColor' )
175+ force_logger .handlers .clear ()
176+ force_logger .addHandler (handler )
177+ force_logger .setLevel (logging .DEBUG )
178+
179+ force_logger .debug ("Force DEBUG (should be blue)" )
180+ force_logger .info ("Force INFO (should be green)" )
181+ force_logger .warning ("Force WARNING (should be yellow)" )
182+ force_logger .error ("Force ERROR (should be red)" )
183+ force_logger .critical ("Force CRITICAL (should be bold red)" )
184+
149185def main ():
150186 """اجرای تمام demo ها"""
151- print ("🎯 SmartLogger Demonstration" )
187+ print ("\n 🎯 SmartLogger Complete Demonstration" )
152188 print ("=" * 50 )
153- print ("نمایش قابلیتهای رنگی سیستم لاگ پایتون" )
189+
190+ # بررسی وضعیت SmartLogger
191+ try :
192+ from smartlogger .auto import is_active
193+ from smartlogger .utils .terminal import supports_colors
194+ print (f"SmartLogger Active: { is_active ()} " )
195+ print (f"Color Support: { supports_colors ()} " )
196+ except Exception as e :
197+ print (f"SmartLogger Status Error: { e } " )
198+
154199 print ("=" * 50 )
155200
156201 # اجرای تمام demo ها
@@ -159,15 +204,15 @@ def main():
159204 demo_custom_colors ()
160205 demo_multiple_loggers ()
161206 demo_error_scenarios ()
207+ demo_force_color_test ()
162208
163209 print ("\n ✅ === Demo Completed ===" )
164- print ("تمام قابلیتهای SmartLogger نمایش داده شد!" )
165- print ("رنگها بر اساس سطح لاگ تنظیم شدهاند:" )
166- print ("🔵 DEBUG (آبی)" )
167- print ("🟢 INFO (سبز)" )
168- print ("🟡 WARNING (زرد)" )
169- print ("🔴 ERROR (قرمز)" )
170- print ("🟥 CRITICAL (قرمز Bold)" )
210+ print ("🎨 If you see colors above, SmartLogger is working!" )
211+ print ("🔧 If you don't see colors:" )
212+ print (" • Try running in Terminal.app (not VSCode)" )
213+ print (" • Use iTerm2 on macOS" )
214+ print (" • Check terminal ANSI color support" )
215+ print (" • Set FORCE_COLOR=1 environment variable" )
171216
172217if __name__ == "__main__" :
173218 main ()
0 commit comments