4848from .storage import Storage , FileStorage , MemoryStorage
4949from .types import User , SentCode , TermsOfService
5050
51+ log = logging .getLogger (__name__ )
52+
5153
5254class Client (Methods , BaseClient ):
5355 """Pyrogram Client, the main means for interacting with Telegram.
@@ -340,7 +342,7 @@ def terminate(self):
340342
341343 if self .takeout_id :
342344 self .send (functions .account .FinishTakeoutSession ())
343- logging .warning ("Takeout session {} finished" .format (self .takeout_id ))
345+ log .warning ("Takeout session {} finished" .format (self .takeout_id ))
344346
345347 Syncer .remove (self )
346348 self .dispatcher .stop ()
@@ -728,7 +730,7 @@ def authorize(self) -> User:
728730 print (e .MESSAGE .format (x = e .x ))
729731 time .sleep (e .x )
730732 except Exception as e :
731- logging .error (e , exc_info = True )
733+ log .error (e , exc_info = True )
732734 raise
733735 else :
734736 self .password = None
@@ -828,7 +830,7 @@ def start(self):
828830
829831 if not self .storage .is_bot and self .takeout :
830832 self .takeout_id = self .send (functions .account .InitTakeoutSession ()).id
831- logging .warning ("Takeout session {} initiated" .format (self .takeout_id ))
833+ log .warning ("Takeout session {} initiated" .format (self .takeout_id ))
832834
833835 self .send (functions .updates .GetState ())
834836 except (Exception , KeyboardInterrupt ):
@@ -1227,7 +1229,7 @@ def fetch_peers(
12271229
12281230 def download_worker (self ):
12291231 name = threading .current_thread ().name
1230- logging .debug ("{} started" .format (name ))
1232+ log .debug ("{} started" .format (name ))
12311233
12321234 while True :
12331235 packet = self .download_queue .get ()
@@ -1262,7 +1264,7 @@ def download_worker(self):
12621264 os .makedirs (directory , exist_ok = True )
12631265 shutil .move (temp_file_path , final_file_path )
12641266 except Exception as e :
1265- logging .error (e , exc_info = True )
1267+ log .error (e , exc_info = True )
12661268
12671269 try :
12681270 os .remove (temp_file_path )
@@ -1276,11 +1278,11 @@ def download_worker(self):
12761278 finally :
12771279 done .set ()
12781280
1279- logging .debug ("{} stopped" .format (name ))
1281+ log .debug ("{} stopped" .format (name ))
12801282
12811283 def updates_worker (self ):
12821284 name = threading .current_thread ().name
1283- logging .debug ("{} started" .format (name ))
1285+ log .debug ("{} started" .format (name ))
12841286
12851287 while True :
12861288 updates = self .updates_queue .get ()
@@ -1308,7 +1310,7 @@ def updates_worker(self):
13081310 pts_count = getattr (update , "pts_count" , None )
13091311
13101312 if isinstance (update , types .UpdateChannelTooLong ):
1311- logging .warning (update )
1313+ log .warning (update )
13121314
13131315 if isinstance (update , types .UpdateNewChannelMessage ) and is_min :
13141316 message = update .message
@@ -1360,11 +1362,11 @@ def updates_worker(self):
13601362 elif isinstance (updates , types .UpdateShort ):
13611363 self .dispatcher .updates_queue .put ((updates .update , {}, {}))
13621364 elif isinstance (updates , types .UpdatesTooLong ):
1363- logging .info (updates )
1365+ log .info (updates )
13641366 except Exception as e :
1365- logging .error (e , exc_info = True )
1367+ log .error (e , exc_info = True )
13661368
1367- logging .debug ("{} stopped" .format (name ))
1369+ log .debug ("{} stopped" .format (name ))
13681370
13691371 def send (self , data : TLObject , retries : int = Session .MAX_RETRIES , timeout : float = Session .WAIT_TIMEOUT ):
13701372 """Send raw Telegram queries.
@@ -1539,7 +1541,7 @@ def load_plugins(self):
15391541 if isinstance (handler , Handler ) and isinstance (group , int ):
15401542 self .add_handler (handler , group )
15411543
1542- logging .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
1544+ log .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
15431545 self .session_name , type (handler ).__name__ , name , group , module_path ))
15441546
15451547 count += 1
@@ -1553,12 +1555,12 @@ def load_plugins(self):
15531555 try :
15541556 module = import_module (module_path )
15551557 except ImportError :
1556- logging .warning ('[{}] [LOAD] Ignoring non-existent module "{}"' .format (
1558+ log .warning ('[{}] [LOAD] Ignoring non-existent module "{}"' .format (
15571559 self .session_name , module_path ))
15581560 continue
15591561
15601562 if "__path__" in dir (module ):
1561- logging .warning ('[{}] [LOAD] Ignoring namespace "{}"' .format (
1563+ log .warning ('[{}] [LOAD] Ignoring namespace "{}"' .format (
15621564 self .session_name , module_path ))
15631565 continue
15641566
@@ -1574,13 +1576,13 @@ def load_plugins(self):
15741576 if isinstance (handler , Handler ) and isinstance (group , int ):
15751577 self .add_handler (handler , group )
15761578
1577- logging .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
1579+ log .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
15781580 self .session_name , type (handler ).__name__ , name , group , module_path ))
15791581
15801582 count += 1
15811583 except Exception :
15821584 if warn_non_existent_functions :
1583- logging .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
1585+ log .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
15841586 self .session_name , name , module_path ))
15851587
15861588 if exclude :
@@ -1591,12 +1593,12 @@ def load_plugins(self):
15911593 try :
15921594 module = import_module (module_path )
15931595 except ImportError :
1594- logging .warning ('[{}] [UNLOAD] Ignoring non-existent module "{}"' .format (
1596+ log .warning ('[{}] [UNLOAD] Ignoring non-existent module "{}"' .format (
15951597 self .session_name , module_path ))
15961598 continue
15971599
15981600 if "__path__" in dir (module ):
1599- logging .warning ('[{}] [UNLOAD] Ignoring namespace "{}"' .format (
1601+ log .warning ('[{}] [UNLOAD] Ignoring namespace "{}"' .format (
16001602 self .session_name , module_path ))
16011603 continue
16021604
@@ -1612,20 +1614,20 @@ def load_plugins(self):
16121614 if isinstance (handler , Handler ) and isinstance (group , int ):
16131615 self .remove_handler (handler , group )
16141616
1615- logging .info ('[{}] [UNLOAD] {}("{}") from group {} in "{}"' .format (
1617+ log .info ('[{}] [UNLOAD] {}("{}") from group {} in "{}"' .format (
16161618 self .session_name , type (handler ).__name__ , name , group , module_path ))
16171619
16181620 count -= 1
16191621 except Exception :
16201622 if warn_non_existent_functions :
1621- logging .warning ('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"' .format (
1623+ log .warning ('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"' .format (
16221624 self .session_name , name , module_path ))
16231625
16241626 if count > 0 :
1625- logging .warning ('[{}] Successfully loaded {} plugin{} from "{}"' .format (
1627+ log .warning ('[{}] Successfully loaded {} plugin{} from "{}"' .format (
16261628 self .session_name , count , "s" if count > 1 else "" , root ))
16271629 else :
1628- logging .warning ('[{}] No plugin loaded from "{}"' .format (
1630+ log .warning ('[{}] No plugin loaded from "{}"' .format (
16291631 self .session_name , root ))
16301632
16311633 # def get_initial_dialogs_chunk(self, offset_date: int = 0):
@@ -1642,10 +1644,10 @@ def load_plugins(self):
16421644 # )
16431645 # )
16441646 # except FloodWait as e:
1645- # logging .warning("get_dialogs flood: waiting {} seconds".format(e.x))
1647+ # log .warning("get_dialogs flood: waiting {} seconds".format(e.x))
16461648 # time.sleep(e.x)
16471649 # else:
1648- # logging .info("Total peers: {}".format(self.storage.peers_count))
1650+ # log .info("Total peers: {}".format(self.storage.peers_count))
16491651 # return r
16501652 #
16511653 # def get_initial_dialogs(self):
@@ -1868,7 +1870,7 @@ def save_file(
18681870 except Client .StopTransmission :
18691871 raise
18701872 except Exception as e :
1871- logging .error (e , exc_info = True )
1873+ log .error (e , exc_info = True )
18721874 else :
18731875 if is_big :
18741876 return types .InputFileBig (
@@ -2094,7 +2096,7 @@ def get_file(
20942096 raise e
20952097 except Exception as e :
20962098 if not isinstance (e , Client .StopTransmission ):
2097- logging .error (e , exc_info = True )
2099+ log .error (e , exc_info = True )
20982100
20992101 try :
21002102 os .remove (file_name )
0 commit comments