added log level management to interface and lish
This commit is contained in:
parent
755a0dcf23
commit
1b5ddec576
3 changed files with 34 additions and 11 deletions
|
|
@ -161,7 +161,7 @@ def main():
|
||||||
|
|
||||||
print("\nScheduled " + str(job_count) + " jobs")
|
print("\nScheduled " + str(job_count) + " jobs")
|
||||||
|
|
||||||
interface = LinspectorInterface(jobs, scheduler, lin_conf)
|
interface = LinspectorInterface(jobs, scheduler, lin_conf, root_logger)
|
||||||
|
|
||||||
if "jsonrpc_backend" in core and core["jsonrpc_backend"]:
|
if "jsonrpc_backend" in core and core["jsonrpc_backend"]:
|
||||||
jsonrpc = JsonrpcBackend(interface, core)
|
jsonrpc = JsonrpcBackend(interface, core)
|
||||||
|
|
|
||||||
|
|
@ -20,17 +20,19 @@ You should have received a copy of the GNU Affero General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from collections import OrderedDict
|
import logging
|
||||||
from logging import getLogger
|
|
||||||
|
|
||||||
logger = getLogger(__name__)
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class LinspectorInterface(object):
|
class LinspectorInterface(object):
|
||||||
def __init__(self, jobs, scheduler, linspectorConfig):
|
def __init__(self, jobs, scheduler, linspectorConfig, root_logger):
|
||||||
self.jobs = jobs
|
self.jobs = jobs
|
||||||
self._scheduler = scheduler
|
self._scheduler = scheduler
|
||||||
self._config = linspectorConfig
|
self._config = linspectorConfig
|
||||||
|
self._root_logger = root_logger
|
||||||
self._recompute_job_hex_strings()
|
self._recompute_job_hex_strings()
|
||||||
|
|
||||||
def _recompute_job_hex_strings(self):
|
def _recompute_job_hex_strings(self):
|
||||||
|
|
@ -161,3 +163,14 @@ class LinspectorInterface(object):
|
||||||
def get_thread_count(self):
|
def get_thread_count(self):
|
||||||
return {"Num Threads": str(self._scheduler._threadpool.num_threads),
|
return {"Num Threads": str(self._scheduler._threadpool.num_threads),
|
||||||
"Max Threads": str(self._scheduler._threadpool.max_threads)}
|
"Max Threads": str(self._scheduler._threadpool.max_threads)}
|
||||||
|
|
||||||
|
def set_log_level(self, log_level):
|
||||||
|
if log_level == "debug":
|
||||||
|
level = logging.DEBUG
|
||||||
|
elif log_level == "error":
|
||||||
|
level = logging.ERROR
|
||||||
|
elif log_level == "info":
|
||||||
|
level = logging.INFO
|
||||||
|
elif log_level == "warning":
|
||||||
|
level = logging.WARNING
|
||||||
|
self._root_logger.setLevel(level)
|
||||||
|
|
@ -350,7 +350,9 @@ Usage:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def do_log(self, text):
|
def do_log(self, text):
|
||||||
if text == "less":
|
text = shsplit(text)
|
||||||
|
|
||||||
|
if text[0] == "less":
|
||||||
try:
|
try:
|
||||||
# TODO: do the less on the logfile set by args and not a static path
|
# TODO: do the less on the logfile set by args and not a static path
|
||||||
with open(os.path.dirname(os.path.abspath(__file__)) + "/../../log/linspector.log"):
|
with open(os.path.dirname(os.path.abspath(__file__)) + "/../../log/linspector.log"):
|
||||||
|
|
@ -358,7 +360,13 @@ Usage:
|
||||||
except IOError:
|
except IOError:
|
||||||
self.print_color(RED, "Logfile not found.")
|
self.print_color(RED, "Logfile not found.")
|
||||||
self.help_log()
|
self.help_log()
|
||||||
elif text == "more":
|
elif text[0] == "level":
|
||||||
|
if text[1] in ["debug", "error", "info", "warning"]:
|
||||||
|
self.interface.set_log_level(text[1])
|
||||||
|
self.print_color(GREEN, "Setting log level to: " + text[1])
|
||||||
|
else:
|
||||||
|
self.print_color(RED, "Log level " + text[1] + " not supported")
|
||||||
|
elif text[0] == "more":
|
||||||
try:
|
try:
|
||||||
# TODO: do the more on the logfile set by args and not a static path
|
# TODO: do the more on the logfile set by args and not a static path
|
||||||
with open(os.path.dirname(os.path.abspath(__file__)) + "/../../log/linspector.log"):
|
with open(os.path.dirname(os.path.abspath(__file__)) + "/../../log/linspector.log"):
|
||||||
|
|
@ -366,7 +374,7 @@ Usage:
|
||||||
except IOError:
|
except IOError:
|
||||||
self.print_color(RED, "Logfile not found.")
|
self.print_color(RED, "Logfile not found.")
|
||||||
self.help_log()
|
self.help_log()
|
||||||
elif text == "tail":
|
elif text[0] == "tail":
|
||||||
try:
|
try:
|
||||||
# TODO: do the tail on the logfile set by args and not a static path
|
# TODO: do the tail on the logfile set by args and not a static path
|
||||||
with open(os.path.dirname(os.path.abspath(__file__)) + "/../../log/linspector.log"):
|
with open(os.path.dirname(os.path.abspath(__file__)) + "/../../log/linspector.log"):
|
||||||
|
|
@ -378,9 +386,11 @@ Usage:
|
||||||
def help_log(self):
|
def help_log(self):
|
||||||
print('''
|
print('''
|
||||||
Usage:
|
Usage:
|
||||||
less less on the linspector logfile (press "q" to exit)
|
less less on the linspector logfile (press "q" to exit)
|
||||||
more more on the linspector logfile (press "q" to exit)
|
level <LEVEL> set the log level to <LEVEL>
|
||||||
tail tail (-F) on the linspector logfile (Ctrl+C to exit)
|
supported levels are debug, error, info, warning
|
||||||
|
more more on the linspector logfile (press "q" to exit)
|
||||||
|
tail tail (-F) on the linspector logfile (Ctrl+C to exit)
|
||||||
''')
|
''')
|
||||||
|
|
||||||
def do_status(self, text):
|
def do_status(self, text):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue