4848from .storage import Storage , FileStorage , MemoryStorage
4949from .types import User , SentCode , TermsOfService
5050
51- log = logging .getLogger (__name__ )
52-
5351
5452class Client (Methods , BaseClient ):
5553 """Pyrogram Client, the main means for interacting with Telegram.
@@ -342,7 +340,7 @@ def terminate(self):
342340
343341 if self .takeout_id :
344342 self .send (functions .account .FinishTakeoutSession ())
345- log .warning ("Takeout session {} finished" .format (self .takeout_id ))
343+ logging .warning ("Takeout session {} finished" .format (self .takeout_id ))
346344
347345 Syncer .remove (self )
348346 self .dispatcher .stop ()
@@ -730,7 +728,7 @@ def authorize(self) -> User:
730728 print (e .MESSAGE .format (x = e .x ))
731729 time .sleep (e .x )
732730 except Exception as e :
733- log .error (e , exc_info = True )
731+ logging .error (e , exc_info = True )
734732 raise
735733 else :
736734 self .password = None
@@ -830,7 +828,7 @@ def start(self):
830828
831829 if not self .storage .is_bot and self .takeout :
832830 self .takeout_id = self .send (functions .account .InitTakeoutSession ()).id
833- log .warning ("Takeout session {} initiated" .format (self .takeout_id ))
831+ logging .warning ("Takeout session {} initiated" .format (self .takeout_id ))
834832
835833 self .send (functions .updates .GetState ())
836834 except (Exception , KeyboardInterrupt ):
@@ -1229,7 +1227,7 @@ def fetch_peers(
12291227
12301228 def download_worker (self ):
12311229 name = threading .current_thread ().name
1232- log .debug ("{} started" .format (name ))
1230+ logging .debug ("{} started" .format (name ))
12331231
12341232 while True :
12351233 packet = self .download_queue .get ()
@@ -1264,7 +1262,7 @@ def download_worker(self):
12641262 os .makedirs (directory , exist_ok = True )
12651263 shutil .move (temp_file_path , final_file_path )
12661264 except Exception as e :
1267- log .error (e , exc_info = True )
1265+ logging .error (e , exc_info = True )
12681266
12691267 try :
12701268 os .remove (temp_file_path )
@@ -1278,11 +1276,11 @@ def download_worker(self):
12781276 finally :
12791277 done .set ()
12801278
1281- log .debug ("{} stopped" .format (name ))
1279+ logging .debug ("{} stopped" .format (name ))
12821280
12831281 def updates_worker (self ):
12841282 name = threading .current_thread ().name
1285- log .debug ("{} started" .format (name ))
1283+ logging .debug ("{} started" .format (name ))
12861284
12871285 while True :
12881286 updates = self .updates_queue .get ()
@@ -1310,7 +1308,7 @@ def updates_worker(self):
13101308 pts_count = getattr (update , "pts_count" , None )
13111309
13121310 if isinstance (update , types .UpdateChannelTooLong ):
1313- log .warning (update )
1311+ logging .warning (update )
13141312
13151313 if isinstance (update , types .UpdateNewChannelMessage ) and is_min :
13161314 message = update .message
@@ -1362,11 +1360,11 @@ def updates_worker(self):
13621360 elif isinstance (updates , types .UpdateShort ):
13631361 self .dispatcher .updates_queue .put ((updates .update , {}, {}))
13641362 elif isinstance (updates , types .UpdatesTooLong ):
1365- log .info (updates )
1363+ logging .info (updates )
13661364 except Exception as e :
1367- log .error (e , exc_info = True )
1365+ logging .error (e , exc_info = True )
13681366
1369- log .debug ("{} stopped" .format (name ))
1367+ logging .debug ("{} stopped" .format (name ))
13701368
13711369 def send (self , data : TLObject , retries : int = Session .MAX_RETRIES , timeout : float = Session .WAIT_TIMEOUT ):
13721370 """Send raw Telegram queries.
@@ -1541,7 +1539,7 @@ def load_plugins(self):
15411539 if isinstance (handler , Handler ) and isinstance (group , int ):
15421540 self .add_handler (handler , group )
15431541
1544- log .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
1542+ logging .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
15451543 self .session_name , type (handler ).__name__ , name , group , module_path ))
15461544
15471545 count += 1
@@ -1555,12 +1553,12 @@ def load_plugins(self):
15551553 try :
15561554 module = import_module (module_path )
15571555 except ImportError :
1558- log .warning ('[{}] [LOAD] Ignoring non-existent module "{}"' .format (
1556+ logging .warning ('[{}] [LOAD] Ignoring non-existent module "{}"' .format (
15591557 self .session_name , module_path ))
15601558 continue
15611559
15621560 if "__path__" in dir (module ):
1563- log .warning ('[{}] [LOAD] Ignoring namespace "{}"' .format (
1561+ logging .warning ('[{}] [LOAD] Ignoring namespace "{}"' .format (
15641562 self .session_name , module_path ))
15651563 continue
15661564
@@ -1576,13 +1574,13 @@ def load_plugins(self):
15761574 if isinstance (handler , Handler ) and isinstance (group , int ):
15771575 self .add_handler (handler , group )
15781576
1579- log .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
1577+ logging .info ('[{}] [LOAD] {}("{}") in group {} from "{}"' .format (
15801578 self .session_name , type (handler ).__name__ , name , group , module_path ))
15811579
15821580 count += 1
15831581 except Exception :
15841582 if warn_non_existent_functions :
1585- log .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
1583+ logging .warning ('[{}] [LOAD] Ignoring non-existent function "{}" from "{}"' .format (
15861584 self .session_name , name , module_path ))
15871585
15881586 if exclude :
@@ -1593,12 +1591,12 @@ def load_plugins(self):
15931591 try :
15941592 module = import_module (module_path )
15951593 except ImportError :
1596- log .warning ('[{}] [UNLOAD] Ignoring non-existent module "{}"' .format (
1594+ logging .warning ('[{}] [UNLOAD] Ignoring non-existent module "{}"' .format (
15971595 self .session_name , module_path ))
15981596 continue
15991597
16001598 if "__path__" in dir (module ):
1601- log .warning ('[{}] [UNLOAD] Ignoring namespace "{}"' .format (
1599+ logging .warning ('[{}] [UNLOAD] Ignoring namespace "{}"' .format (
16021600 self .session_name , module_path ))
16031601 continue
16041602
@@ -1614,20 +1612,20 @@ def load_plugins(self):
16141612 if isinstance (handler , Handler ) and isinstance (group , int ):
16151613 self .remove_handler (handler , group )
16161614
1617- log .info ('[{}] [UNLOAD] {}("{}") from group {} in "{}"' .format (
1615+ logging .info ('[{}] [UNLOAD] {}("{}") from group {} in "{}"' .format (
16181616 self .session_name , type (handler ).__name__ , name , group , module_path ))
16191617
16201618 count -= 1
16211619 except Exception :
16221620 if warn_non_existent_functions :
1623- log .warning ('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"' .format (
1621+ logging .warning ('[{}] [UNLOAD] Ignoring non-existent function "{}" from "{}"' .format (
16241622 self .session_name , name , module_path ))
16251623
16261624 if count > 0 :
1627- log .warning ('[{}] Successfully loaded {} plugin{} from "{}"' .format (
1625+ logging .warning ('[{}] Successfully loaded {} plugin{} from "{}"' .format (
16281626 self .session_name , count , "s" if count > 1 else "" , root ))
16291627 else :
1630- log .warning ('[{}] No plugin loaded from "{}"' .format (
1628+ logging .warning ('[{}] No plugin loaded from "{}"' .format (
16311629 self .session_name , root ))
16321630
16331631 # def get_initial_dialogs_chunk(self, offset_date: int = 0):
@@ -1644,10 +1642,10 @@ def load_plugins(self):
16441642 # )
16451643 # )
16461644 # except FloodWait as e:
1647- # log .warning("get_dialogs flood: waiting {} seconds".format(e.x))
1645+ # logging .warning("get_dialogs flood: waiting {} seconds".format(e.x))
16481646 # time.sleep(e.x)
16491647 # else:
1650- # log .info("Total peers: {}".format(self.storage.peers_count))
1648+ # logging .info("Total peers: {}".format(self.storage.peers_count))
16511649 # return r
16521650 #
16531651 # def get_initial_dialogs(self):
@@ -1870,7 +1868,7 @@ def save_file(
18701868 except Client .StopTransmission :
18711869 raise
18721870 except Exception as e :
1873- log .error (e , exc_info = True )
1871+ logging .error (e , exc_info = True )
18741872 else :
18751873 if is_big :
18761874 return types .InputFileBig (
@@ -2096,7 +2094,7 @@ def get_file(
20962094 raise e
20972095 except Exception as e :
20982096 if not isinstance (e , Client .StopTransmission ):
2099- log .error (e , exc_info = True )
2097+ logging .error (e , exc_info = True )
21002098
21012099 try :
21022100 os .remove (file_name )
0 commit comments