Message ID | 20231110155009.941766-1-JPEWhacker@gmail.com |
---|---|
State | New |
Headers | show |
Series | [bitbake-devel] asyncrpc: Add option to set log level when running as a process | expand |
Thanks! Tested-by: Martin Jansa <Martin.Jansa@gmail.com> On Fri, Nov 10, 2023 at 4:50 PM Joshua Watt <JPEWhacker@gmail.com> wrote: > When running an asyncrpc server as a subprocess, it is often desired to > run it with a lower logging level since the normal logging of clients > connecting and disconnecting is not desired. > > As such, add an option to set the logging level of the server when > running as a subprocess and set the level to WARNING when starting a > local hashserver or PRserver > > Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> > --- > lib/bb/asyncrpc/serv.py | 5 ++++- > lib/bb/cooker.py | 2 +- > lib/prserv/serv.py | 2 +- > 3 files changed, 6 insertions(+), 3 deletions(-) > > diff --git a/lib/bb/asyncrpc/serv.py b/lib/bb/asyncrpc/serv.py > index 5fed1730..f0be9a6c 100644 > --- a/lib/bb/asyncrpc/serv.py > +++ b/lib/bb/asyncrpc/serv.py > @@ -322,7 +322,7 @@ class AsyncServer(object): > self.loop = asyncio.new_event_loop() > asyncio.set_event_loop(self.loop) > > - def serve_as_process(self, *, prefunc=None, args=()): > + def serve_as_process(self, *, prefunc=None, args=(), log_level=None): > """ > Serve requests in a child process > """ > @@ -351,6 +351,9 @@ class AsyncServer(object): > if prefunc is not None: > prefunc(self, *args) > > + if log_level is not None: > + self.logger.setLevel(log_level) > + > self._serve_forever(tasks) > > if sys.version_info >= (3, 6): > diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py > index 9a3e32ac..4bf1809b 100644 > --- a/lib/bb/cooker.py > +++ b/lib/bb/cooker.py > @@ -345,7 +345,7 @@ class BBCooker: > sync=False, > upstream=upstream, > ) > - self.hashserv.serve_as_process() > + self.hashserv.serve_as_process(log_level=logging.WARNING) > for mc in self.databuilder.mcdata: > self.databuilder.mcorigdata[mc].setVar("BB_HASHSERVE", > self.hashservaddr) > self.databuilder.mcdata[mc].setVar("BB_HASHSERVE", > self.hashservaddr) > diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py > index 6168eb18..62d3b5a0 100644 > --- a/lib/prserv/serv.py > +++ b/lib/prserv/serv.py > @@ -130,7 +130,7 @@ class PRServSingleton(object): > def start(self): > self.prserv = PRServer(self.dbfile) > self.prserv.start_tcp_server(socket.gethostbyname(self.host), > self.port) > - self.process = self.prserv.serve_as_process() > + self.process = > self.prserv.serve_as_process(log_level=logging.WARNING) > > if not self.prserv.address: > raise PRServiceConfigError > -- > 2.34.1 > > > -=-=-=-=-=-=-=-=-=-=-=- > Links: You receive all messages sent to this group. > View/Reply Online (#15505): > https://lists.openembedded.org/g/bitbake-devel/message/15505 > Mute This Topic: https://lists.openembedded.org/mt/102509062/3617156 > Group Owner: bitbake-devel+owner@lists.openembedded.org > Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [ > martin.jansa@gmail.com] > -=-=-=-=-=-=-=-=-=-=-=- > >
diff --git a/lib/bb/asyncrpc/serv.py b/lib/bb/asyncrpc/serv.py index 5fed1730..f0be9a6c 100644 --- a/lib/bb/asyncrpc/serv.py +++ b/lib/bb/asyncrpc/serv.py @@ -322,7 +322,7 @@ class AsyncServer(object): self.loop = asyncio.new_event_loop() asyncio.set_event_loop(self.loop) - def serve_as_process(self, *, prefunc=None, args=()): + def serve_as_process(self, *, prefunc=None, args=(), log_level=None): """ Serve requests in a child process """ @@ -351,6 +351,9 @@ class AsyncServer(object): if prefunc is not None: prefunc(self, *args) + if log_level is not None: + self.logger.setLevel(log_level) + self._serve_forever(tasks) if sys.version_info >= (3, 6): diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py index 9a3e32ac..4bf1809b 100644 --- a/lib/bb/cooker.py +++ b/lib/bb/cooker.py @@ -345,7 +345,7 @@ class BBCooker: sync=False, upstream=upstream, ) - self.hashserv.serve_as_process() + self.hashserv.serve_as_process(log_level=logging.WARNING) for mc in self.databuilder.mcdata: self.databuilder.mcorigdata[mc].setVar("BB_HASHSERVE", self.hashservaddr) self.databuilder.mcdata[mc].setVar("BB_HASHSERVE", self.hashservaddr) diff --git a/lib/prserv/serv.py b/lib/prserv/serv.py index 6168eb18..62d3b5a0 100644 --- a/lib/prserv/serv.py +++ b/lib/prserv/serv.py @@ -130,7 +130,7 @@ class PRServSingleton(object): def start(self): self.prserv = PRServer(self.dbfile) self.prserv.start_tcp_server(socket.gethostbyname(self.host), self.port) - self.process = self.prserv.serve_as_process() + self.process = self.prserv.serve_as_process(log_level=logging.WARNING) if not self.prserv.address: raise PRServiceConfigError
When running an asyncrpc server as a subprocess, it is often desired to run it with a lower logging level since the normal logging of clients connecting and disconnecting is not desired. As such, add an option to set the logging level of the server when running as a subprocess and set the level to WARNING when starting a local hashserver or PRserver Signed-off-by: Joshua Watt <JPEWhacker@gmail.com> --- lib/bb/asyncrpc/serv.py | 5 ++++- lib/bb/cooker.py | 2 +- lib/prserv/serv.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-)