mirror of
https://github.com/SELinuxProject/setools
synced 2025-03-25 04:26:28 +00:00
Apply logging best practices.
* Use __name__ for the logger name * Add top-level library NullHandlers
This commit is contained in:
parent
d7e8cf0701
commit
c017bd7cfa
@ -24,6 +24,8 @@ try:
|
||||
except ImportError: # pragma: no cover
|
||||
__version__ = "unknown"
|
||||
|
||||
import logging
|
||||
|
||||
# Python classes for policy representation
|
||||
from . import policyrep
|
||||
from .policyrep import SELinuxPolicy
|
||||
@ -72,3 +74,5 @@ from .dta import DomainTransitionAnalysis
|
||||
|
||||
# Policy difference
|
||||
from .diff import PolicyDifference
|
||||
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
@ -50,6 +50,10 @@ class BoolQuery(compquery.ComponentQuery):
|
||||
else:
|
||||
self._default = bool(value)
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(BoolQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all Booleans matching the criteria."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -41,6 +41,10 @@ class BoundsQuery(PolicyQuery):
|
||||
child = CriteriaDescriptor("child_regex")
|
||||
child_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(BoundsQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching *bounds statements."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -39,6 +39,10 @@ class CategoryQuery(mixins.MatchAlias, compquery.ComponentQuery):
|
||||
will be used on the alias names.
|
||||
"""
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(CategoryQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching categories."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -43,6 +43,10 @@ class CommonQuery(mixins.MatchPermission, compquery.ComponentQuery):
|
||||
on the permission names instead of set logic.
|
||||
"""
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(CommonQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching commons."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -72,6 +72,10 @@ class ConstraintQuery(mixins.MatchObjClass, mixins.MatchPermission, query.Policy
|
||||
type_regex = False
|
||||
type_indirect = True
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(ConstraintQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def _match_expr(self, expr, criteria, indirect, regex):
|
||||
"""
|
||||
Match roles/types/users in a constraint expression,
|
||||
|
@ -46,6 +46,10 @@ class DefaultQuery(MatchObjClass, PolicyQuery):
|
||||
default = CriteriaDescriptor(lookup_function="validate_default_value")
|
||||
default_range = CriteriaDescriptor(lookup_function="validate_default_range")
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(DefaultQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching default_* statements."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -27,7 +27,7 @@ class Difference(object):
|
||||
"""Base class for all policy differences."""
|
||||
|
||||
def __init__(self, left_policy, right_policy):
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.left_policy = left_policy
|
||||
self.right_policy = right_policy
|
||||
|
||||
|
@ -54,7 +54,7 @@ class DomainTransitionAnalysis(object):
|
||||
Parameter:
|
||||
policy The policy to analyze.
|
||||
"""
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
self.policy = policy
|
||||
self.exclude = exclude
|
||||
|
@ -60,6 +60,10 @@ class FSUseQuery(contextquery.ContextQuery):
|
||||
fs = CriteriaDescriptor("fs_regex")
|
||||
fs_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(FSUseQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching fs_use_* statements."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -64,6 +64,10 @@ class GenfsconQuery(contextquery.ContextQuery):
|
||||
path = CriteriaDescriptor("path_regex")
|
||||
path_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(GenfsconQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching genfscons."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -41,7 +41,7 @@ class InfoFlowAnalysis(object):
|
||||
exclude The types excluded from the information flow analysis.
|
||||
(default is none)
|
||||
"""
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
self.policy = policy
|
||||
|
||||
|
@ -54,6 +54,10 @@ class InitialSIDQuery(compquery.ComponentQuery, contextquery.ContextQuery):
|
||||
No effect if not using set operations.
|
||||
"""
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(InitialSIDQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching initial SIDs."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -56,6 +56,10 @@ class MLSRuleQuery(mixins.MatchObjClass, query.PolicyQuery):
|
||||
default_superset = False
|
||||
default_proper = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(MLSRuleQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching MLS rules."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -54,6 +54,10 @@ class NetifconQuery(compquery.ComponentQuery, contextquery.ContextQuery):
|
||||
No effect if not using set operations.
|
||||
"""
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(NetifconQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching netifcons."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -97,6 +97,10 @@ class NodeconQuery(contextquery.ContextQuery):
|
||||
else:
|
||||
self._network = None
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(NodeconQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching nodecons."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -60,6 +60,10 @@ class ObjClassQuery(compquery.ComponentQuery):
|
||||
perms_indirect = True
|
||||
perms_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(ObjClassQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching object classes."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -37,7 +37,7 @@ class PermissionMap(object):
|
||||
Parameter:
|
||||
permmapfile The path to the permission map to load.
|
||||
"""
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
if permmapfile:
|
||||
self.load(permmapfile)
|
||||
|
@ -35,6 +35,10 @@ class PolCapQuery(compquery.ComponentQuery):
|
||||
be used for matching the name.
|
||||
"""
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(PolCapQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching policy capabilities."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -79,7 +79,7 @@ class SELinuxPolicy(object):
|
||||
policyfile Path to a policy to open.
|
||||
"""
|
||||
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = None
|
||||
self.filename = None
|
||||
|
||||
|
@ -141,7 +141,7 @@ def QpolGenerator(cast):
|
||||
|
||||
def qpol_logger(level, msg):
|
||||
"""Log qpol messages via Python logging."""
|
||||
logging.getLogger("libqpol").debug(msg)
|
||||
logging.getLogger(__name__).debug(msg)
|
||||
|
||||
def qpol_policy_factory(path):
|
||||
"""Factory function for qpol policy objects."""
|
||||
|
@ -114,6 +114,10 @@ class PortconQuery(contextquery.ContextQuery):
|
||||
else:
|
||||
self._protocol = None
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(PortconQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching portcons."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -24,8 +24,6 @@ class PolicyQuery(object):
|
||||
"""Base class for SELinux policy queries."""
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
|
||||
self.policy = policy
|
||||
|
||||
# keys are sorted in reverse order so regex settings
|
||||
|
@ -82,6 +82,10 @@ class RBACRuleQuery(mixins.MatchObjClass, query.PolicyQuery):
|
||||
except InvalidType:
|
||||
self._target = self.policy.lookup_role(value)
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(RBACRuleQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching RBAC rules."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -49,6 +49,10 @@ class RoleQuery(compquery.ComponentQuery):
|
||||
types_equal = False
|
||||
types_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(RoleQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching roles."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -49,6 +49,10 @@ class SensitivityQuery(mixins.MatchAlias, compquery.ComponentQuery):
|
||||
sens_dom = False
|
||||
sens_domby = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(SensitivityQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching sensitivities."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -93,6 +93,10 @@ class TERuleQuery(mixins.MatchObjClass, mixins.MatchPermission, query.PolicyQuer
|
||||
boolean_regex = False
|
||||
boolean_equal = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(TERuleQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching TE rules."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -49,6 +49,10 @@ class TypeAttributeQuery(compquery.ComponentQuery):
|
||||
types_equal = False
|
||||
types_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(TypeAttributeQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching types."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -67,6 +67,10 @@ class TypeQuery(mixins.MatchAlias, compquery.ComponentQuery):
|
||||
else:
|
||||
self._permissive = bool(value)
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(TypeQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching types."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -74,6 +74,10 @@ class UserQuery(compquery.ComponentQuery):
|
||||
roles_equal = False
|
||||
roles_regex = False
|
||||
|
||||
def __init__(self, policy, **kwargs):
|
||||
super(UserQuery, self).__init__(policy, **kwargs)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
def results(self):
|
||||
"""Generator which yields all matching users."""
|
||||
self.log.info("Generating results from {0.policy}".format(self))
|
||||
|
@ -19,3 +19,6 @@
|
||||
|
||||
from .apol import ApolMainWindow
|
||||
from . import widget
|
||||
|
||||
import logging
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
@ -32,7 +32,7 @@ class DetailsPopup(SEToolsWidget, QDialog):
|
||||
|
||||
def __init__(self, parent, title=None):
|
||||
super(DetailsPopup, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.setupUi(title)
|
||||
|
||||
def setupUi(self, title):
|
||||
|
@ -34,7 +34,7 @@ class DomainTransitionAnalysisTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
def __init__(self, parent, policy, perm_map):
|
||||
super(DomainTransitionAnalysisTab, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = policy
|
||||
self.query = DomainTransitionAnalysis(policy)
|
||||
self.setupUi()
|
||||
|
@ -30,7 +30,7 @@ class ExcludeTypes(SEToolsWidget, QDialog):
|
||||
|
||||
def __init__(self, parent, policy):
|
||||
super(ExcludeTypes, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.parent = parent
|
||||
self.policy = policy
|
||||
self.excluded_list = [str(e) for e in self.parent.query.exclude]
|
||||
|
@ -34,7 +34,7 @@ class InfoFlowAnalysisTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
def __init__(self, parent, policy, perm_map):
|
||||
super(InfoFlowAnalysisTab, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = policy
|
||||
self.query = InfoFlowAnalysis(policy, perm_map)
|
||||
self.setupUi()
|
||||
|
@ -38,7 +38,7 @@ class ApolMainWindow(SEToolsWidget, QMainWindow):
|
||||
|
||||
def __init__(self, filename):
|
||||
super(ApolMainWindow, self).__init__()
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
|
||||
if filename:
|
||||
self._policy = SELinuxPolicy(filename)
|
||||
|
@ -35,7 +35,7 @@ class MLSRuleQueryTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
def __init__(self, parent, policy, perm_map):
|
||||
super(MLSRuleQueryTab, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = policy
|
||||
self.query = MLSRuleQuery(policy)
|
||||
self.setupUi()
|
||||
|
@ -35,7 +35,7 @@ class RBACRuleQueryTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
def __init__(self, parent, policy, perm_map):
|
||||
super(RBACRuleQueryTab, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = policy
|
||||
self.query = RBACRuleQuery(policy)
|
||||
self.setupUi()
|
||||
|
@ -35,7 +35,7 @@ class TERuleQueryTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
def __init__(self, parent, policy, perm_map):
|
||||
super(TERuleQueryTab, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = policy
|
||||
self.query = TERuleQuery(policy)
|
||||
self.setupUi()
|
||||
|
@ -35,7 +35,7 @@ class UserQueryTab(SEToolsWidget, QScrollArea):
|
||||
|
||||
def __init__(self, parent, policy, perm_map):
|
||||
super(UserQueryTab, self).__init__(parent)
|
||||
self.log = logging.getLogger(self.__class__.__name__)
|
||||
self.log = logging.getLogger(__name__)
|
||||
self.policy = policy
|
||||
self.query = UserQuery(policy)
|
||||
self.setupUi()
|
||||
|
Loading…
Reference in New Issue
Block a user