forked from CRImier/pyLCI
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from ZeroPhone/ZPUI-40
[WIP] Log management through config file
- Loading branch information
Showing
11 changed files
with
345 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
i = None | ||
o = None | ||
|
||
from collections import OrderedDict | ||
import logging | ||
|
||
import helpers.logger as log_system | ||
|
||
logger_alias_map = (("root","Main launcher"), | ||
("input.input","Input system"), | ||
("apps.app_manager","App manager"), | ||
("context_manager","Context manager"), | ||
("emulator","Emulator"), | ||
("helpers.logger","Logging system")) | ||
|
||
logger_alias_map = OrderedDict(logger_alias_map) | ||
|
||
from ui import Menu, Listbox | ||
|
||
def get_logger_names(): | ||
return log_system.get_logger_names() | ||
|
||
def prettify_logger_names(names): | ||
name_mapping = OrderedDict() | ||
for name in names: | ||
if name in logger_alias_map: | ||
# We have a defined name for this logger | ||
name_mapping[name] = logger_alias_map[name] | ||
elif name.startswith("ui."): | ||
# This is an UI logger | ||
element_name = name[len("ui."):].capitalize() | ||
name_mapping[name] = "UI - {}".format(element_name) | ||
elif name.startswith("apps."): | ||
# This is an app logger | ||
app_name, module_name = name.rsplit(".", 2)[1:] | ||
app_name = app_name.capitalize().replace("_", " ") | ||
name_mapping[name] = '{} app - {}'.format(app_name, module_name) | ||
elif name.startswith("input.drivers") or name.startswith("output.drivers"): | ||
# This is a driver logger | ||
driver_name = name.rsplit(".", 1)[1].capitalize().replace("_", " ") | ||
name_mapping[name] = '{} driver'.format(driver_name) | ||
else: | ||
# Fallback - name is not know and we can't yet prettify it | ||
name_mapping[name] = name | ||
return name_mapping | ||
|
||
def get_available_levels(): | ||
return [ key.lower() for key in logging._levelNames.keys() if isinstance(key, basestring) ] | ||
|
||
def select_loglevel(current): | ||
available_levels = get_available_levels() | ||
lb_contents = [[level.capitalize(), level] for level in available_levels] | ||
lb = Listbox(lb_contents, i, o, "Loglevel selection listbox") | ||
lb.start_pointer = available_levels.index(current.lower()) | ||
return lb.activate() | ||
|
||
def change_loglevel(logger_name, current_level): | ||
new_level = select_loglevel(current_level) | ||
if new_level is not None: | ||
assert (new_level in get_available_levels()) | ||
log_system.LoggingConfig().set_level(logger_name, new_level) | ||
log_system.LoggingConfig().reload_config() | ||
|
||
def get_menu_contents(): | ||
logger_names = get_logger_names() | ||
pretty_logger_names = prettify_logger_names(logger_names) | ||
sorted_names = sorted(pretty_logger_names.items(), key=lambda x: x[1]) | ||
for i, (name, pname) in enumerate(sorted_names): | ||
l = log_system.get_log_level_for_logger(name) | ||
sorted_names[i] = (name, pname, l) | ||
return [["{}:{}".format(l[:1], pname), lambda x=name, y=l:change_loglevel(x, y)] for name, pname, l in sorted_names] | ||
|
||
def config_logging(): | ||
Menu([], i, o, contents_hook=get_menu_contents).activate() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.. _logging_config: | ||
|
||
Logging configuration | ||
##################### | ||
|
||
Changing log levels | ||
=================== | ||
|
||
In case of problems with ZPUI, logs can help you understand it - especially when | ||
the problem is not easily repeatable. To enable verbose logging for a particular | ||
system/app/driver, go to ``"Settings"->"Logging settings"`` menu, then click on | ||
the part of ZPUI that you're interested in and pick "Debug". From now on, that part | ||
of ZPUI will log a lot more in ``zpui.log`` files - which you can then read through, | ||
or send to the developers. | ||
|
||
Alternatively, you can change the log_conf.ini file directly. In it, add a new | ||
section for the app you want to learn, like this: | ||
|
||
.. code-block:: ini | ||
[path.to.code.file] | ||
level = debug | ||
``path.to.code.file`` would be the Python-style path to the module you want to debug, | ||
for example, ``input.input``, ``context_manager`` or ``apps.network_apps.wpa_cli``. | ||
|
Oops, something went wrong.