aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2014-08-09 18:16:46 +0100
committerBryn M. Reeves <bmr@redhat.com>2014-08-09 18:16:46 +0100
commit721d9a0261808da02d34192a282209197261a343 (patch)
tree2fa7958b7ec779c2e1cad1d190b8973c36673459
parent067520af3c9a181e12810ec045fe08bc2c5964e9 (diff)
downloadsos-721d9a0261808da02d34192a282209197261a343.tar.gz
[plugin] make Plugin logging methods private
Related: #348. Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
-rw-r--r--sos/plugins/__init__.py90
-rw-r--r--sos/plugins/cluster.py2
-rw-r--r--sos/plugins/ds.py2
-rw-r--r--sos/plugins/kernel.py2
-rw-r--r--sos/plugins/kvm.py4
-rw-r--r--sos/plugins/maas.py2
-rw-r--r--sos/plugins/pcp.py10
-rw-r--r--sos/plugins/postgresql.py2
-rw-r--r--sos/plugins/sar.py2
9 files changed, 58 insertions, 58 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py
index 85f72cbd..1e5e26fe 100644
--- a/sos/plugins/__init__.py
+++ b/sos/plugins/__init__.py
@@ -135,16 +135,16 @@ class Plugin(object):
def _format_msg(self, msg):
return "[plugin:%s] %s" % (self.name(), msg)
- def log_error(self, msg):
+ def _log_error(self, msg):
self.soslog.error(self._format_msg(msg))
- def log_warn(self, msg):
+ def _log_warn(self, msg):
self.soslog.warning(self._format_msg(msg))
- def log_info(self, msg):
+ def _log_info(self, msg):
self.soslog.info(self._format_msg(msg))
- def log_debug(self, msg):
+ def _log_debug(self, msg):
self.soslog.debug(self._format_msg(msg))
def policy(self):
@@ -166,8 +166,8 @@ class Plugin(object):
This function returns the number of replacements made.
'''
globstr = '*' + cmd + '*'
- self.log_debug("substituting '%s' for '%s' in commands matching '%s'"
- % (subst, regexp, globstr))
+ self._log_debug("substituting '%s' for '%s' in commands matching '%s'"
+ % (subst, regexp, globstr))
if not self.executed_commands:
return 0
@@ -180,7 +180,7 @@ class Plugin(object):
continue
if fnmatch.fnmatch(called['exe'], globstr):
path = os.path.join(self.commons['cmddir'], called['file'])
- self.log_debug("applying substitution to '%s'" % path)
+ self._log_debug("applying substitution to '%s'" % path)
readable = self.archive.open_file(path)
result, replacements = re.subn(
regexp, subst, readable.read())
@@ -189,7 +189,7 @@ class Plugin(object):
except Exception as e:
msg = "regex substitution failed for '%s' with: '%s'"
- self.log_error(msg % (called['exe'], e))
+ self._log_error(msg % (called['exe'], e))
replacements = None
return replacements
@@ -203,8 +203,8 @@ class Plugin(object):
'''
try:
path = self._get_dest_for_srcpath(srcpath)
- self.log_debug("substituting '%s' for '%s' in '%s'"
- % (subst, regexp, path))
+ self._log_debug("substituting '%s' for '%s' in '%s'"
+ % (subst, regexp, path))
if not path:
return 0
readable = self.archive.open_file(path)
@@ -215,7 +215,7 @@ class Plugin(object):
replacements = 0
except Exception as e:
msg = "regex substitution failed for '%s' with: '%s'"
- self.log_error(msg % (path, e))
+ self._log_error(msg % (path, e))
replacements = 0
return replacements
@@ -246,25 +246,25 @@ class Plugin(object):
if os.path.isabs(linkdest):
reldest = os.path.relpath(linkdest,
os.path.dirname(srcpath))
- self.log_debug("made link target '%s' relative as '%s'"
- % (linkdest, reldest))
+ self._log_debug("made link target '%s' relative as '%s'"
+ % (linkdest, reldest))
else:
reldest = linkdest
- self.log_debug("copying link '%s' pointing to '%s' with isdir=%s"
- % (srcpath, linkdest, os.path.isdir(absdest)))
+ self._log_debug("copying link '%s' pointing to '%s' with isdir=%s"
+ % (srcpath, linkdest, os.path.isdir(absdest)))
# use the relative target path in the tarball
self.archive.add_link(reldest, srcpath)
if os.path.isdir(absdest):
- self.log_debug("link '%s' is a directory, skipping..." % linkdest)
+ self._log_debug("link '%s' is a directory, skipping..." % linkdest)
return
# copy the symlink target translating relative targets
# to absolute paths to pass to do_copy_path.
- self.log_debug("normalized link target '%s' as '%s'"
- % (linkdest, absdest))
+ self._log_debug("normalized link target '%s' as '%s'"
+ % (linkdest, absdest))
self.do_copy_path(absdest)
self.copied_files.append({'srcpath': srcpath,
@@ -274,8 +274,8 @@ class Plugin(object):
def copy_dir(self, srcpath):
for afile in os.listdir(srcpath):
- self.log_debug("recursively adding '%s' from '%s'" % (afile,
- srcpath))
+ self._log_debug("recursively adding '%s' from '%s'"
+ % (afile, srcpath))
self.do_copy_path(os.path.join(srcpath, afile), dest=None)
def _get_dest_for_srcpath(self, srcpath):
@@ -300,7 +300,7 @@ class Plugin(object):
saved for use later in preparing a report.
'''
if self.is_forbidden_path(srcpath):
- self.log_debug("skipping forbidden path '%s'" % srcpath)
+ self._log_debug("skipping forbidden path '%s'" % srcpath)
return ''
if not dest:
@@ -309,7 +309,7 @@ class Plugin(object):
try:
st = os.lstat(srcpath)
except (OSError, IOError):
- self.log_info("failed to stat '%s'" % srcpath)
+ self._log_info("failed to stat '%s'" % srcpath)
return
if stat.S_ISLNK(st.st_mode):
@@ -323,13 +323,13 @@ class Plugin(object):
# handle special nodes (block, char, fifo, socket)
if not (stat.S_ISREG(st.st_mode) or stat.S_ISDIR(st.st_mode)):
ntype = _node_type(st)
- self.log_debug("creating %s node at archive:'%s'" % (ntype,
- srcpath))
+ self._log_debug("creating %s node at archive:'%s'"
+ % (ntype, srcpath))
self.copy_node(srcpath, st)
return
# if we get here, it's definitely a regular file (not a symlink or dir)
- self.log_debug("copying path '%s' to archive:'%s'" % (srcpath, dest))
+ self._log_debug("copying path '%s' to archive:'%s'" % (srcpath, dest))
# if not readable(srcpath)
if not (st.st_mode & 0o444):
@@ -454,19 +454,19 @@ class Plugin(object):
copied into the sosreport by this module.
"""
if not (copyspec and len(copyspec)):
- self.log_warn("added null or empty copy spec")
+ self._log_warn("added null or empty copy spec")
return False
copy_paths = self.expand_copy_spec(copyspec)
self.copy_paths.update(copy_paths)
- self.log_info("added copyspec '%s'" % copyspec)
+ self._log_info("added copyspec '%s'" % copyspec)
def get_command_output(self, prog, timeout=300, runat=None):
result = sos_get_command_output(prog, timeout=timeout, runat=runat)
if result['status'] == 124:
- self.log_warn("command '%s' timed out after %ds"
- % (prog, timeout))
+ self._log_warn("command '%s' timed out after %ds"
+ % (prog, timeout))
if result['status'] == 127:
- self.log_debug("could not run '%s': command not found" % prog)
+ self._log_debug("could not run '%s': command not found" % prog)
return result
def call_ext_prog(self, prog, timeout=300, runat=None):
@@ -494,10 +494,10 @@ class Plugin(object):
runat=None):
"""Run a program and collect the output"""
cmd = (exe, suggest_filename, root_symlink, timeout, runat)
- self.log_debug("packed command tuple: ('%s', '%s', '%s', %s, '%s')"
- % cmd)
+ self._log_debug("packed command tuple: ('%s', '%s', '%s', %s, '%s')"
+ % cmd)
self.collect_cmds.append(cmd)
- self.log_info("added cmd output '%s'" % exe)
+ self._log_info("added cmd output '%s'" % exe)
def get_cmd_output_path(self, name=None, make=True):
"""Return a path into which this module should store collected
@@ -544,7 +544,7 @@ class Plugin(object):
"""Add a string to the archive as a file named `filename`"""
self.copy_strings.append((content, filename))
content = "..." + (content.splitlines()[0]).decode('utf8')
- self.log_debug("added string '%s' as '%s'" % (content, filename))
+ self._log_debug("added string '%s' as '%s'" % (content, filename))
def get_cmd_output_now(self, exe, suggest_filename=None,
root_symlink=False, timeout=300,
@@ -556,8 +556,8 @@ class Plugin(object):
result = self.get_command_output(exe, timeout=timeout, runat=runat)
if (result['status'] == 127):
return None
- self.log_debug("collected output of '%s' in %s" % (exe.split()[0],
- time() - start))
+ self._log_debug("collected output of '%s' in %s"
+ % (exe.split()[0], time() - start))
if suggest_filename:
outfn = self.make_command_filename(suggest_filename)
@@ -596,15 +596,15 @@ class Plugin(object):
def collect_copy_specs(self):
for path in self.copy_paths:
- self.log_info("collecting path '%s'" % path)
+ self._log_info("collecting path '%s'" % path)
self.do_copy_path(path)
def collect_cmd_output(self):
for progs in zip(self.collect_cmds):
prog, suggest_filename, root_symlink, timeout, runat = progs[0]
- self.log_debug("unpacked command tuple: "
- + "('%s', '%s', '%s', %s, '%s')" % progs[0])
- self.log_info("collecting output of '%s'" % prog)
+ self._log_debug("unpacked command tuple: "
+ + "('%s', '%s', '%s', %s, '%s')" % progs[0])
+ self._log_info("collecting output of '%s'" % prog)
self.get_cmd_output_now(prog, suggest_filename=suggest_filename,
root_symlink=root_symlink,
timeout=timeout, runat=runat)
@@ -612,16 +612,16 @@ class Plugin(object):
def collect_strings(self):
for string, file_name in self.copy_strings:
content = "..." + (string.splitlines()[0]).decode('utf8')
- self.log_info("collecting string '%s' as '%s'" % (content,
- file_name))
+ self._log_info("collecting string '%s' as '%s'"
+ % (content, file_name))
try:
self.archive.add_string(string,
os.path.join('sos_strings',
self.name(),
file_name))
except Exception as e:
- self.log_debug("could not add string '%s': %s"
- % (file_name, e))
+ self._log_debug("could not add string '%s': %s"
+ % (file_name, e))
def collect(self):
"""Collect the data for a plugin."""
@@ -630,7 +630,7 @@ class Plugin(object):
self.collect_cmd_output()
self.collect_strings()
fields = (self.name(), time() - start)
- self.log_debug("collected plugin '%s' in %s" % fields)
+ self._log_debug("collected plugin '%s' in %s" % fields)
def get_description(self):
""" This function will return the description for the plugin"""
diff --git a/sos/plugins/cluster.py b/sos/plugins/cluster.py
index 4f56cdef..6567fcb0 100644
--- a/sos/plugins/cluster.py
+++ b/sos/plugins/cluster.py
@@ -98,7 +98,7 @@ class Cluster(Plugin, RedHatPlugin):
str(self.get_option('crm_from'))):
crm_from = self.get_option('crm_from')
else:
- self.log_error(
+ self._log_error(
"crm_from parameter '%s' is not a valid date: using "
"default" % self.get_option('crm_from'))
diff --git a/sos/plugins/ds.py b/sos/plugins/ds.py
index 26079f77..082a7476 100644
--- a/sos/plugins/ds.py
+++ b/sos/plugins/ds.py
@@ -51,7 +51,7 @@ class DirectoryServer(Plugin, RedHatPlugin):
certpath = os.path.join("/etc/dirsrv", d)
self.add_cmd_output("certutil -L -d %s" % certpath)
except:
- self.log_warn("could not list /etc/dirsrv")
+ self._log_warn("could not list /etc/dirsrv")
if not self.check_version():
self.add_alert("Directory Server not found.")
diff --git a/sos/plugins/kernel.py b/sos/plugins/kernel.py
index 18e7a057..f09b252f 100644
--- a/sos/plugins/kernel.py
+++ b/sos/plugins/kernel.py
@@ -33,7 +33,7 @@ class Kernel(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
modules = os.listdir(self.sys_module)
self.add_cmd_output("modinfo " + " ".join(modules))
except OSError:
- self.log_warn("could not list %s" % self.sys_module)
+ self._log_warn("could not list %s" % self.sys_module)
self.add_cmd_outputs([
"dmesg",
diff --git a/sos/plugins/kvm.py b/sos/plugins/kvm.py
index 796527ac..3c3ec50e 100644
--- a/sos/plugins/kvm.py
+++ b/sos/plugins/kvm.py
@@ -43,7 +43,7 @@ class Kvm(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
r = self.call_ext_prog("mount -t debugfs debugfs %s"
% self.debugfs_path)
if r['status'] != 0:
- self.log_error("debugfs not mounted and mount attempt failed")
+ self._log_error("debugfs not mounted and mount attempt failed")
self._debugfs_cleanup = False
return
self.add_cmd_output("kvm_stat --once")
@@ -51,6 +51,6 @@ class Kvm(Plugin, RedHatPlugin, DebianPlugin, UbuntuPlugin):
def postproc(self):
if self._debugfs_cleanup and os.path.ismount(self.debugfs_path):
self.call_ext_prog("umount %s" % self.debugfs_path)
- self.log_error("could not unmount %s" % self.debugfs_path)
+ self._log_error("could not unmount %s" % self.debugfs_path)
# vim: et ts=4 sw=4
diff --git a/sos/plugins/maas.py b/sos/plugins/maas.py
index 8da94498..82a82bc4 100644
--- a/sos/plugins/maas.py
+++ b/sos/plugins/maas.py
@@ -63,7 +63,7 @@ class Maas(Plugin, UbuntuPlugin):
self.add_cmd_output("maas %s commissioning-results list" %
self.get_option("profile-name"))
else:
- self.log_error(
+ self._log_error(
"Cannot login into Maas remote API with provided creds.")
# vim: et ts=4 sw=4
diff --git a/sos/plugins/pcp.py b/sos/plugins/pcp.py
index 80e14067..b8c82b43 100644
--- a/sos/plugins/pcp.py
+++ b/sos/plugins/pcp.py
@@ -78,7 +78,7 @@ class Pcp(Plugin, RedHatPlugin, DebianPlugin):
self.pcplog_totalsize = 0
if not self.pcp_parse_conffile():
- self.log_warn("could not parse %s" % self.pcp_conffile)
+ self._log_warn("could not parse %s" % self.pcp_conffile)
return
# Add PCP_SYSCONF_DIR (/etc/pcp) and PCP_VAR_DIR (/var/lib/pcp/config)
@@ -130,12 +130,12 @@ class Pcp(Plugin, RedHatPlugin, DebianPlugin):
if os.path.isdir(path):
self.add_copy_spec(path)
else:
- self.log_warn("%s not found" % path)
+ self._log_warn("%s not found" % path)
else:
- self.log_warn("skipped %s. Size %d bigger than %d" % (path,
- dirsize, max_mb_size))
+ self._log_warn("skipped %s. Size %d bigger than %d"
+ % (path, dirsize, max_mb_size))
else:
- self.log_warn("pcp_hostname was not set. Skipping.")
+ self._log_warn("pcp_hostname was not set. Skipping.")
self.add_copy_specs([
# Collect PCP_LOG_DIR/pmcd and PCP_LOG_DIR/NOTICES
diff --git a/sos/plugins/postgresql.py b/sos/plugins/postgresql.py
index 45ec7d36..9bdbf236 100644
--- a/sos/plugins/postgresql.py
+++ b/sos/plugins/postgresql.py
@@ -66,7 +66,7 @@ class PostgreSQL(Plugin):
if (result['status'] == 0):
self.add_copy_spec(dest_file)
else:
- self.log_error(
+ self._log_error(
"Unable to execute pg_dump. Error(%s)" % (result['output'])
)
self.add_alert(
diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py
index e680e511..71d493ce 100644
--- a/sos/plugins/sar.py
+++ b/sos/plugins/sar.py
@@ -49,7 +49,7 @@ class Sar(Plugin,):
try:
dir_list = os.listdir(self.sa_path)
except:
- self.log_warn("sar: could not list %s" % self.sa_path)
+ self._log_warn("sar: could not list %s" % self.sa_path)
return
# find all the sa files that don't have an existing sar file
for fname in dir_list: