2
2
import dataclasses
3
3
import json
4
4
import logging
5
- import logging .handlers
6
5
import sys
7
6
from enum import Enum
8
7
from typing import Any , Dict , List , Optional , Set , Union
16
15
from galaxy .task_manager import TaskManager
17
16
18
17
18
+ logger = logging .getLogger (__name__ )
19
+
20
+
19
21
class JSONEncoder (json .JSONEncoder ):
20
22
def default (self , o ): # pylint: disable=method-hidden
21
23
if dataclasses .is_dataclass (o ):
@@ -33,7 +35,7 @@ class Plugin:
33
35
"""Use and override methods of this class to create a new platform integration."""
34
36
35
37
def __init__ (self , platform , version , reader , writer , handshake_token ):
36
- logging .info ("Creating plugin for platform %s, version %s" , platform .value , version )
38
+ logger .info ("Creating plugin for platform %s, version %s" , platform .value , version )
37
39
self ._platform = platform
38
40
self ._version = version
39
41
@@ -189,24 +191,24 @@ async def wrapper(*args, **kwargs):
189
191
async def run (self ):
190
192
"""Plugin's main coroutine."""
191
193
await self ._connection .run ()
192
- logging .debug ("Plugin run loop finished" )
194
+ logger .debug ("Plugin run loop finished" )
193
195
194
196
def close (self ) -> None :
195
197
if not self ._active :
196
198
return
197
199
198
- logging .info ("Closing plugin" )
200
+ logger .info ("Closing plugin" )
199
201
self ._connection .close ()
200
202
self ._external_task_manager .cancel ()
201
203
self ._internal_task_manager .create_task (self .shutdown (), "shutdown" )
202
204
self ._active = False
203
205
204
206
async def wait_closed (self ) -> None :
205
- logging .debug ("Waiting for plugin to close" )
207
+ logger .debug ("Waiting for plugin to close" )
206
208
await self ._external_task_manager .wait ()
207
209
await self ._internal_task_manager .wait ()
208
210
await self ._connection .wait_closed ()
209
- logging .debug ("Plugin closed" )
211
+ logger .debug ("Plugin closed" )
210
212
211
213
def create_task (self , coro , description ):
212
214
"""Wrapper around asyncio.create_task - takes care of canceling tasks on shutdown"""
@@ -217,11 +219,11 @@ async def _pass_control(self):
217
219
try :
218
220
self .tick ()
219
221
except Exception :
220
- logging .exception ("Unexpected exception raised in plugin tick" )
222
+ logger .exception ("Unexpected exception raised in plugin tick" )
221
223
await asyncio .sleep (1 )
222
224
223
225
async def _shutdown (self ):
224
- logging .info ("Shutting down" )
226
+ logger .info ("Shutting down" )
225
227
self .close ()
226
228
await self ._external_task_manager .wait ()
227
229
await self ._internal_task_manager .wait ()
@@ -238,7 +240,7 @@ def _initialize_cache(self, data: Dict):
238
240
try :
239
241
self .handshake_complete ()
240
242
except Exception :
241
- logging .exception ("Unhandled exception during `handshake_complete` step" )
243
+ logger .exception ("Unhandled exception during `handshake_complete` step" )
242
244
self ._internal_task_manager .create_task (self ._pass_control (), "tick" )
243
245
244
246
@staticmethod
@@ -639,7 +641,7 @@ async def import_game_achievements(game_id, context_):
639
641
except ApplicationError as error :
640
642
self ._game_achievements_import_failure (game_id , error )
641
643
except Exception :
642
- logging .exception ("Unexpected exception raised in import_game_achievements" )
644
+ logger .exception ("Unexpected exception raised in import_game_achievements" )
643
645
self ._game_achievements_import_failure (game_id , UnknownError ())
644
646
645
647
async def import_games_achievements (game_ids_ , context_ ):
@@ -803,7 +805,7 @@ async def import_game_time(game_id, context_):
803
805
except ApplicationError as error :
804
806
self ._game_time_import_failure (game_id , error )
805
807
except Exception :
806
- logging .exception ("Unexpected exception raised in import_game_time" )
808
+ logger .exception ("Unexpected exception raised in import_game_time" )
807
809
self ._game_time_import_failure (game_id , UnknownError ())
808
810
809
811
async def import_game_times (game_ids_ , context_ ):
@@ -861,7 +863,7 @@ async def import_game_library_settings(game_id, context_):
861
863
except ApplicationError as error :
862
864
self ._game_library_settings_import_failure (game_id , error )
863
865
except Exception :
864
- logging .exception ("Unexpected exception raised in import_game_library_settings" )
866
+ logger .exception ("Unexpected exception raised in import_game_library_settings" )
865
867
self ._game_library_settings_import_failure (game_id , UnknownError ())
866
868
867
869
async def import_game_library_settings_set (game_ids_ , context_ ):
@@ -919,7 +921,7 @@ async def import_os_compatibility(game_id, context_):
919
921
except ApplicationError as error :
920
922
self ._os_compatibility_import_failure (game_id , error )
921
923
except Exception :
922
- logging .exception ("Unexpected exception raised in import_os_compatibility" )
924
+ logger .exception ("Unexpected exception raised in import_os_compatibility" )
923
925
self ._os_compatibility_import_failure (game_id , UnknownError ())
924
926
925
927
async def import_os_compatibility_set (game_ids_ , context_ ):
@@ -974,7 +976,7 @@ async def import_user_presence(user_id, context_) -> None:
974
976
except ApplicationError as error :
975
977
self ._user_presence_import_failure (user_id , error )
976
978
except Exception :
977
- logging .exception ("Unexpected exception raised in import_user_presence" )
979
+ logger .exception ("Unexpected exception raised in import_user_presence" )
978
980
self ._user_presence_import_failure (user_id , UnknownError ())
979
981
980
982
async def import_user_presence_set (user_ids_ , context_ ) -> None :
@@ -1037,29 +1039,29 @@ def main():
1037
1039
main()
1038
1040
"""
1039
1041
if len (argv ) < 3 :
1040
- logging .critical ("Not enough parameters, required: token, port" )
1042
+ logger .critical ("Not enough parameters, required: token, port" )
1041
1043
sys .exit (1 )
1042
1044
1043
1045
token = argv [1 ]
1044
1046
1045
1047
try :
1046
1048
port = int (argv [2 ])
1047
1049
except ValueError :
1048
- logging .critical ("Failed to parse port value: %s" , argv [2 ])
1050
+ logger .critical ("Failed to parse port value: %s" , argv [2 ])
1049
1051
sys .exit (2 )
1050
1052
1051
1053
if not (1 <= port <= 65535 ):
1052
- logging .critical ("Port value out of range (1, 65535)" )
1054
+ logger .critical ("Port value out of range (1, 65535)" )
1053
1055
sys .exit (3 )
1054
1056
1055
1057
if not issubclass (plugin_class , Plugin ):
1056
- logging .critical ("plugin_class must be subclass of Plugin" )
1058
+ logger .critical ("plugin_class must be subclass of Plugin" )
1057
1059
sys .exit (4 )
1058
1060
1059
1061
async def coroutine ():
1060
1062
reader , writer = await asyncio .open_connection ("127.0.0.1" , port )
1061
1063
extra_info = writer .get_extra_info ("sockname" )
1062
- logging .info ("Using local address: %s:%u" , * extra_info )
1064
+ logger .info ("Using local address: %s:%u" , * extra_info )
1063
1065
async with plugin_class (reader , writer , token ) as plugin :
1064
1066
await plugin .run ()
1065
1067
@@ -1069,5 +1071,5 @@ async def coroutine():
1069
1071
1070
1072
asyncio .run (coroutine ())
1071
1073
except Exception :
1072
- logging .exception ("Error while running plugin" )
1074
+ logger .exception ("Error while running plugin" )
1073
1075
sys .exit (5 )
0 commit comments