2121from . import handlers
2222from .signal import Signal
2323
24+ LOG = logging .getLogger (__name__ )
25+
2426
2527async def grep_static (dest , url = 'http://127.0.0.1:5000' ):
2628 http_client = tornado .httpclient .AsyncHTTPClient ()
@@ -40,7 +42,8 @@ def cli():
4042 )
4143
4244 openpifpaf .decoder .cli (parser )
43- openpifpaf .network .cli (parser )
45+ openpifpaf .logger .cli (parser )
46+ openpifpaf .network .Factory .cli (parser )
4447
4548 parser .add_argument ('--disable-cuda' , action = 'store_true' ,
4649 help = 'disable CUDA' )
@@ -51,8 +54,6 @@ def cli():
5154 help = 'directory in which to create a static version of this page' )
5255 parser .add_argument ('--demo-password' , default = None ,
5356 help = 'password that allows better performance for a demo' )
54- parser .add_argument ('--debug' , default = False , action = 'store_true' ,
55- help = 'debug messages and autoreload' )
5657 parser .add_argument ('--google-analytics' ,
5758 help = 'provide a google analytics id to inject analytics code' )
5859
@@ -76,19 +77,17 @@ def cli():
7677
7778 args = parser .parse_args ()
7879
79- # log
80- logging .basicConfig (level = logging .INFO if not args .debug else logging .DEBUG )
81-
8280 # configure
83- openpifpaf .network .configure (args )
81+ openpifpaf .logger .configure (args , LOG )
82+ openpifpaf .network .Factory .configure (args )
8483
8584 # config
86- logging .debug ('host=%s, port=%d' , args .host , args .port )
87- logging .debug ('Python %s, OpenPifPafWebDemo %s' , sys .version , __version__ )
85+ LOG .debug ('host=%s, port=%d' , args .host , args .port )
86+ LOG .debug ('Python %s, OpenPifPafWebDemo %s' , sys .version , __version__ )
8887 if args .host in ('localhost' , '127.0.0.1' ):
89- logging .info ('Open http://%s:%d in a web browser.' , args .host , args .port )
88+ LOG .info ('Open http://%s:%d in a web browser.' , args .host , args .port )
9089 if args .host != '0.0.0.0' :
91- logging .info ('Access is restricted by IP address. Use --host=0.0.0.0 to allow all.' )
90+ LOG .info ('Access is restricted by IP address. Use --host=0.0.0.0 to allow all.' )
9291
9392 # add args.device
9493 args .device = torch .device ('cpu' )
@@ -109,7 +108,7 @@ def main():
109108 args = cli ()
110109 width_height = (int (640 * args .resolution // 16 ) * 16 + 1 ,
111110 int (480 * args .resolution // 16 ) * 16 + 1 )
112- logging .debug ('target width and height = %s' , width_height )
111+ LOG .debug ('target width and height = %s' , width_height )
113112 processor_singleton = Processor (width_height , args )
114113
115114 static_path = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'static' )
@@ -123,7 +122,7 @@ def main():
123122 tornado .autoreload .watch ('openpifpafwebdemo/static/frontend.js' )
124123 tornado .autoreload .watch ('openpifpafwebdemo/static/clientside.js' )
125124
126- if args . debug :
125+ if LOG . getEffectiveLevel () == logging . DEBUG :
127126 version = '{}-{}' .format (
128127 __version__ ,
129128 '' .join (random .choices (string .ascii_lowercase + string .digits , k = 4 ))
@@ -185,7 +184,7 @@ def main():
185184 'keyfile' : os .path .join (module_dir , 'test' , 'test.key' ),
186185 }
187186
188- logging .info ('Open https://%s:%d in a web browser.' , args .host , args .ssl_port )
187+ LOG .info ('Open https://%s:%d in a web browser.' , args .host , args .ssl_port )
189188 app .listen (args .ssl_port , ssl_options = ssl_ctx )
190189
191190 try :
0 commit comments