Added logging support to gen_print.py.
Change-Id: I7077610c5fe79f3af383b5a862cfcdde89682a8b
Signed-off-by: Michael Walsh <micwalsh@us.ibm.com>
diff --git a/lib/gen_print.py b/lib/gen_print.py
index 3fccd0e..2a3ed19 100755
--- a/lib/gen_print.py
+++ b/lib/gen_print.py
@@ -1168,6 +1168,7 @@
return buffer
+
def gp_print(buffer,
stream='stdout'):
@@ -1193,6 +1194,24 @@
sys.stderr.flush()
+def gp_log(buffer):
+
+ r"""
+ Log the buffer using either python logging or BuiltIn().log depending on
+ whether we are running in a robot environment.
+
+ This function is intended for use only by other functions in this module.
+
+ Description of arguments:
+ buffer The string to be logged.
+ """
+
+ if robot_env:
+ BuiltIn().log(buffer)
+ else:
+ logging.warning(buffer)
+
+
def gp_debug_print(buffer):
r"""
@@ -1209,11 +1228,6 @@
gp_print(buffer)
- if robot_env:
- BuiltIn().log_to_console(buffer)
- else:
- print(buffer)
-
def get_var_value(var_value=None,
default=1,
@@ -1411,10 +1425,14 @@
dprint_func_template, replace_dict)
buffer += func_def
+ func_def = create_func_def_string(s_func_name, "l" + func_name,
+ lprint_func_template, replace_dict)
+ buffer += func_def
+
# Create abbreviated aliases (e.g. spvar is an alias for sprint_var).
alias = re.sub("print_", "p", func_name)
alias = re.sub("print", "p", alias)
- prefixes = ["", "s", "q", "d"]
+ prefixes = ["", "s", "q", "d", "l"]
for prefix in prefixes:
if alias == "p":
continue
@@ -1455,6 +1473,11 @@
" return"
] + print_func_template
+lprint_func_template = \
+ [
+ " gp_log(<mod_qualifer>replace_passwords(<call_line>))"
+ ]
+
replace_dict = {'output_stream': 'stdout', 'mod_qualifer': ''}