Message ID | 20230802233626.3642612-1-joe.slater@windriver.com |
---|---|
State | New |
Headers | show |
Series | [1/1] runqemu: add some logging control | expand |
On 2023-08-02 19:36, joe.slater@windriver.com wrote: > From: Joe Slater<joe.slater@windriver.com> > > Use QB_LOG_FILE to log to a file, and QB_LOG_LEVEL > to set the base log level. Example values - > > QB_LOG_FILE="runq.log" > QB_LOG_LEVEL=DEBUG > > Signed-off-by: Joe Slater<joe.slater@windriver.com> > --- > scripts/runqemu | 16 ++++++++++++---- > 1 file changed, 12 insertions(+), 4 deletions(-) > > diff --git a/scripts/runqemu b/scripts/runqemu > index 5e6793d44e..bea164d041 100755 > --- a/scripts/runqemu > +++ b/scripts/runqemu > @@ -36,12 +36,20 @@ runqemu, i.e. `runqemu /path/to/my-image-name.qemuboot.conf`\n\n %s" % message) > > def create_logger(): > logger = logging.getLogger('runqemu') > - logger.setLevel(logging.INFO) > + try: > + logger.setLevel(os.getenv("QB_LOG_LEVEL")) > + except: > + logger.setLevel(logging.INFO) > > - # create console handler and set level to debug > - ch = logging.StreamHandler() > - ch.setLevel(logging.DEBUG) Better to keep the log level the same or call out the change in the short/long log. ../Randy > > + # create a handler and set level to debug > + try: > + ch = logging.FileHandler(os.getenv("QB_LOG_FILE")) > + except: > + ch = logging.StreamHandler() > + > + ch.setLevel(logging.DEBUG) > + > # create formatter > formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s') >
diff --git a/scripts/runqemu b/scripts/runqemu index 5e6793d44e..bea164d041 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -36,12 +36,20 @@ runqemu, i.e. `runqemu /path/to/my-image-name.qemuboot.conf`\n\n %s" % message) def create_logger(): logger = logging.getLogger('runqemu') - logger.setLevel(logging.INFO) + try: + logger.setLevel(os.getenv("QB_LOG_LEVEL")) + except: + logger.setLevel(logging.INFO) - # create console handler and set level to debug - ch = logging.StreamHandler() - ch.setLevel(logging.DEBUG) + # create a handler and set level to debug + try: + ch = logging.FileHandler(os.getenv("QB_LOG_FILE")) + except: + ch = logging.StreamHandler() + + ch.setLevel(logging.DEBUG) + # create formatter formatter = logging.Formatter('%(name)s - %(levelname)s - %(message)s')