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 @@ async def terminate(self):
340342
341343 if self .takeout_id :
342344 await 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 await Syncer .remove (self )
346348 await self .dispatcher .stop ()
@@ -733,7 +735,7 @@ async def authorize(self) -> User:
733735 print (e .MESSAGE .format (x = e .x ))
734736 time .sleep (e .x )
735737 except Exception as e :
736- logging .error (e , exc_info = True )
738+ log .error (e , exc_info = True )
737739 raise
738740 else :
739741 self .password = None
@@ -833,7 +835,7 @@ async def start(self):
833835
834836 if not self .storage .is_bot and self .takeout :
835837 self .takeout_id = (await self .send (functions .account .InitTakeoutSession ())).id
836- logging .warning ("Takeout session {} initiated" .format (self .takeout_id ))
838+ log .warning ("Takeout session {} initiated" .format (self .takeout_id ))
837839
838840 await self .send (functions .updates .GetState ())
839841 except (Exception , KeyboardInterrupt ):
@@ -1273,7 +1275,7 @@ async def download_worker(self):
12731275 os .makedirs (directory , exist_ok = True )
12741276 shutil .move (temp_file_path , final_file_path )
12751277 except Exception as e :
1276- logging .error (e , exc_info = True )
1278+ log .error (e , exc_info = True )
12771279
12781280 try :
12791281 os .remove (temp_file_path )
@@ -1314,7 +1316,7 @@ async def updates_worker(self):
13141316 pts_count = getattr (update , "pts_count" , None )
13151317
13161318 if isinstance (update , types .UpdateChannelTooLong ):
1317- logging .warning (update )
1319+ log .warning (update )
13181320
13191321 if isinstance (update , types .UpdateNewChannelMessage ) and is_min :
13201322 message = update .message
@@ -1366,9 +1368,9 @@ async def updates_worker(self):
13661368 elif isinstance (updates , types .UpdateShort ):
13671369 self .dispatcher .updates_queue .put_nowait ((updates .update , {}, {}))
13681370 elif isinstance (updates , types .UpdatesTooLong ):
1369- logging .info (updates )
1371+ log .info (updates )
13701372 except Exception as e :
1371- logging .error (e , exc_info = True )
1373+ log .error (e , exc_info = True )
13721374
13731375 async def send (self , data : TLObject , retries : int = Session .MAX_RETRIES , timeout : float = Session .WAIT_TIMEOUT ):
13741376 """Send raw Telegram queries.
@@ -1543,7 +1545,7 @@ def load_plugins(self):
15431545 if isinstance (handler , Handler ) and isinstance (group , int ):
15441546 self .add_handler (handler , group )
15451547
1546- logging .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
1548+ log .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
15471549 self .session_name , type (handler ).__name__ , name , group , module_path ))
15481550
15491551 count += 1
@@ -1557,12 +1559,12 @@ def load_plugins(self):
15571559 try :
15581560 module = import_module (module_path )
15591561 except ImportError :
1560- logging .warning ('[{}] [LOAD] Ignoring non-existent module "{}"' .format (
1562+ log .warning ('[{}] [LOAD] Ignoring non-existent module "{}"' .format (
15611563 self .session_name , module_path ))
15621564 continue
15631565
15641566 if "__path__" in dir (module ):
1565- logging .warning ('[{}] [LOAD] Ignoring namespace "{}"' .format (
1567+ log .warning ('[{}] [LOAD] Ignoring namespace "{}"' .format (
15661568 self .session_name , module_path ))
15671569 continue
15681570
@@ -1578,13 +1580,13 @@ def load_plugins(self):
15781580 if isinstance (handler , Handler ) and isinstance (group , int ):
15791581 self .add_handler (handler , group )
15801582
1581- logging .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
1583+ log .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
15821584 self .session_name , type (handler ).__name__ , name , group , module_path ))
15831585
15841586 count += 1
15851587 except Exception :
15861588 if warn_non_existent_functions :
1587- logging .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
1589+ log .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
15881590 self .session_name , name , module_path ))
15891591
15901592 if exclude :
@@ -1595,12 +1597,12 @@ def load_plugins(self):
15951597 try :
15961598 module = import_module (module_path )
15971599 except ImportError :
1598- logging .warning ('[{}] [UNLOAD] Ignoring non-existent module "{}"' .format (
1600+ log .warning ('[{}] [UNLOAD] Ignoring non-existent module "{}"' .format (
15991601 self .session_name , module_path ))
16001602 continue
16011603
16021604 if "__path__" in dir (module ):
1603- logging .warning ('[{}] [UNLOAD] Ignoring namespace "{}"' .format (
1605+ log .warning ('[{}] [UNLOAD] Ignoring namespace "{}"' .format (
16041606 self .session_name , module_path ))
16051607 continue
16061608
@@ -1616,20 +1618,20 @@ def load_plugins(self):
16161618 if isinstance (handler , Handler ) and isinstance (group , int ):
16171619 self .remove_handler (handler , group )
16181620
1619- logging .info ('[{}] [UNLOAD] {}("{}") from group {} in "{}"' .format (
1621+ log .info ('[{}] [UNLOAD] {}("{}") from group {} in "{}"' .format (
16201622 self .session_name , type (handler ).__name__ , name , group , module_path ))
16211623
16221624 count -= 1
16231625 except Exception :
16241626 if warn_non_existent_functions :
1625- logging .warning ('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"' .format (
1627+ log .warning ('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"' .format (
16261628 self .session_name , name , module_path ))
16271629
16281630 if count > 0 :
1629- logging .warning ('[{}] Successfully loaded {} plugin{} from "{}"' .format (
1631+ log .warning ('[{}] Successfully loaded {} plugin{} from "{}"' .format (
16301632 self .session_name , count , "s" if count > 1 else "" , root ))
16311633 else :
1632- logging .warning ('[{}] No plugin loaded from "{}"' .format (
1634+ log .warning ('[{}] No plugin loaded from "{}"' .format (
16331635 self .session_name , root ))
16341636
16351637 # def get_initial_dialogs_chunk(self, offset_date: int = 0):
@@ -1646,10 +1648,10 @@ def load_plugins(self):
16461648 # )
16471649 # )
16481650 # except FloodWait as e:
1649- # logging .warning("get_dialogs flood: waiting {} seconds".format(e.x))
1651+ # log .warning("get_dialogs flood: waiting {} seconds".format(e.x))
16501652 # time.sleep(e.x)
16511653 # else:
1652- # logging .info("Total peers: {}".format(self.storage.peers_count))
1654+ # log .info("Total peers: {}".format(self.storage.peers_count))
16531655 # return r
16541656 #
16551657 # def get_initial_dialogs(self):
@@ -1885,7 +1887,7 @@ async def worker(session):
18851887 except Client .StopTransmission :
18861888 raise
18871889 except Exception as e :
1888- logging .error (e , exc_info = True )
1890+ log .error (e , exc_info = True )
18891891 else :
18901892 if is_big :
18911893 return types .InputFileBig (
@@ -2117,7 +2119,7 @@ async def get_file(self, media_type: int,
21172119 raise e
21182120 except Exception as e :
21192121 if not isinstance (e , Client .StopTransmission ):
2120- logging .error (e , exc_info = True )
2122+ log .error (e , exc_info = True )
21212123
21222124 try :
21232125 os .remove (file_name )
0 commit comments