Skip to content

Commit

Permalink
pyDKB/common: add default prefix to log function (caller module name).
Browse files Browse the repository at this point in the history
If used from `LoggableObject`, prefix is the caller class name (passed
via `LoggableObject.log` method). If no prefix passed, caller module
name is used instead.

`LoggableObject` method does not support additional prefixes, yet if
`log` function is called directly, prefixes can be passed and in this
case caller `__name__` should be passed explicitly.
  • Loading branch information
mgolosova committed Jul 9, 2019
1 parent a789894 commit 588b5ff
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Utils/Dataflow/pyDKB/common/hdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def check_stderr(proc, timeout=None, max_lines=1):
if err:
n_lines += 1
if max_lines is None or n_lines <= max_lines:
log("%s" % err, logLevel.INFO, 'proc')
log("%s" % err, logLevel.INFO, __name__, 'proc')
if proc.poll():
raise subprocess.CalledProcessError(proc.returncode, None)
return proc.poll()
Expand Down
5 changes: 4 additions & 1 deletion Utils/Dataflow/pyDKB/common/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""

import sys
import inspect

from types import logLevel

Expand All @@ -26,7 +27,9 @@ def log(message, level=logLevel.INFO, *args):
if args:
prefix = ' ' + ' '.join(['(%s)' %p for p in args])
else:
prefix = ''
frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0])
prefix = ' (%s)' % mod.__name__
if lines:
out_message = "(%s)%s %s" % (logLevel.memberName(level),
prefix, lines[0])
Expand Down
2 changes: 1 addition & 1 deletion Utils/Dataflow/pyDKB/dataflow/cds.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from invenio_client.contrib import cds
import splinter
except ImportError, e:
log("%s failed (%s)\n" % (__name__, e), logLevel.WARN)
log("Submodule failed (%s)" % e, logLevel.WARN)
__all__ = []
else:

Expand Down
2 changes: 1 addition & 1 deletion Utils/Dataflow/test/pyDKB/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ test_case() {
after=`cat $case/after 2>/dev/null`

eval "$before $cmd; $after" 2>&1 1> out.tmp | \
grep -a -v '(WARN) pyDKB.dataflow.cds failed (No module named invenio_client.contrib)' | \
grep -a -v '(WARN) (pyDKB.dataflow.cds) Submodule failed (No module named invenio_client.contrib)' | \
sed -e"s#$base_dir#\$base_dir#" > err.tmp

err_correct=0
Expand Down

0 comments on commit 588b5ff

Please sign in to comment.