apol: log INFO messages to the status bar

Still keep the CLI messaging controlled by -v or --debug switches. For some
reason, the root logging had to be DEBUG for this to work, and
only as initialized by basicConfig.  Setting a NullHandler to DEBUG level
didn't work either.
This commit is contained in:
Chris PeBenito 2016-03-04 14:05:20 -05:00
parent 7d88a1424e
commit 6a4cbf20d5
2 changed files with 21 additions and 4 deletions

17
apol
View File

@ -35,13 +35,22 @@ parser.add_argument("--debug", action="store_true", dest="debug", help="Enable d
args = parser.parse_args()
logging.basicConfig(level=logging.DEBUG, filename="/dev/null")
console_handler = logging.StreamHandler()
if args.debug:
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s|%(levelname)s|%(name)s|%(message)s')
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(
logging.Formatter('%(asctime)s|%(levelname)s|%(name)s|%(message)s'))
elif args.verbose:
logging.basicConfig(level=logging.INFO, format='%(message)s')
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(logging.Formatter('%(message)s'))
else:
logging.basicConfig(level=logging.WARNING, format='%(message)s')
console_handler.setLevel(logging.WARNING)
console_handler.setFormatter(logging.Formatter('%(message)s'))
logging.getLogger().addHandler(console_handler)
try:
app = QApplication(sys.argv)

View File

@ -25,6 +25,7 @@ from PyQt5.QtWidgets import QAction, QApplication, QDialog, QFileDialog, QLineEd
from setools import PermissionMap, SELinuxPolicy
from ..widget import SEToolsWidget
from ..logtosignal import LogToSignalHandler
# Analysis tabs:
from .dta import DomainTransitionAnalysisTab
from .infoflow import InfoFlowAnalysisTab
@ -75,6 +76,13 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
tabBar.addAction(self.close_tab_action)
tabBar.setContextMenuPolicy(Qt.ActionsContextMenu)
# capture INFO and higher Python messages from setools lib for status bar
handler = LogToSignalHandler()
handler.setLevel(logging.INFO)
handler.setFormatter(logging.Formatter('%(message)s'))
handler.message.connect(self.statusbar.showMessage)
logging.getLogger("setools").addHandler(handler)
# connect signals
self.open_policy.triggered.connect(self.select_policy)
self.open_permmap.triggered.connect(self.select_permmap)