From db0a74c0aa29eba90f2cad110388a66b95b025c8 Mon Sep 17 00:00:00 2001 From: Hi-Fi Date: Wed, 11 Jul 2018 20:45:00 +0300 Subject: [PATCH] Added fallback to all logging methods Some more documentation about debug in Session --- .../httprequestlibrary/keywords/Session.java | 4 +- .../httprequestlibrary/utils/RobotLogger.java | 37 ++++++++++++++++--- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/github/hi_fi/httprequestlibrary/keywords/Session.java b/src/main/java/com/github/hi_fi/httprequestlibrary/keywords/Session.java index 0c7c93c..667152f 100644 --- a/src/main/java/com/github/hi_fi/httprequestlibrary/keywords/Session.java +++ b/src/main/java/com/github/hi_fi/httprequestlibrary/keywords/Session.java @@ -28,7 +28,7 @@ public class Session { + "\n\n" + "``proxy`` Dictionary that contains proxy information. Only one proxy supported per session. Dictionary should contain at least following keys: *protocol*, *host* and *port* of proxy. It can also contain *username* and *password*\n\n" + "``verify`` Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.\n\n" - + "``debug`` Enable http verbosity option more information\n\n") + + "``debug`` Enable http verbosity option more information. Note that this is not bound to session, but for the state of system. So if another session with debug=False is created, the earlier with debug=True is not printing debug from HTTPclient anymore\n\n") @ArgumentNames({ "alias", "url", "headers={}", "cookies=None", "auth=None", "timeout=None", "proxy=None", "verify=False", "debug=False" }) public void createSession(String alias, String url, String... params) { @@ -52,7 +52,7 @@ public void createSession(String alias, String url, String... params) { + "\n\n" + "``proxy`` Dictionary that contains proxy information. Only one proxy supported per session. Dictionary should contain at least following keys: *protocol*, *host* and *port* of proxy. It can also contain *username* and *password*\n\n" + "``verify`` Whether the SSL cert will be verified. A CA_BUNDLE path can also be provided.\n\n" - + "``debug`` Enable http verbosity option more information\n\n") + + "``debug`` Enable http verbosity option more information. Note that this is not bound to session, but for the state of system. So if another session with debug=False is created, the earlier with debug=True is not printing debug from HTTPclient anymore\n\n") @ArgumentNames({ "alias", "url", "headers={}", "cookies=None", "auth=None", "timeout=None", "proxy=None", "verify=False", "debug=False" }) public void createDigestSession(String alias, String url, String... params) { diff --git a/src/main/java/com/github/hi_fi/httprequestlibrary/utils/RobotLogger.java b/src/main/java/com/github/hi_fi/httprequestlibrary/utils/RobotLogger.java index f7b38da..4b5a8c6 100644 --- a/src/main/java/com/github/hi_fi/httprequestlibrary/utils/RobotLogger.java +++ b/src/main/java/com/github/hi_fi/httprequestlibrary/utils/RobotLogger.java @@ -61,7 +61,12 @@ public RobotLogger(String name) { } public static void logHTML(Object log) { - pythonInterpreter.get().eval("logger.info(repr('" + convertStringToLogger(log) + "'), html=true)"); + try { + pythonInterpreter.get().eval("logger.info(repr('" + convertStringToLogger(log) + "'), html=true)"); + } catch (Exception e) { + //Python logger fails with e.g. Chinese characters, so this done as fallback + System.out.println("*HTML* "+log); + } } public void debug(Object log) { @@ -81,7 +86,14 @@ public void debug(Object message, Throwable t) { } public void error(Object log) { - pythonInterpreter.get().eval("logger.error(repr('" + convertStringToLogger(log) + "')"); + try { + pythonInterpreter.get().eval("logger.error('" + convertStringToLogger(log) + "')"); + } catch (Exception e) { + //Python logger fails with e.g. Chinese characters, so this done as fallback + if (log != null) { + System.out.println("*ERROR* "+log); + } + } } public void error(Object message, Throwable t) { @@ -98,7 +110,12 @@ public void fatal(Object message, Throwable t) { } public void info(Object log) { - pythonInterpreter.get().eval("logger.info(repr('" + convertStringToLogger(log) + "')"); + try { + pythonInterpreter.get().eval("logger.info('" + convertStringToLogger(log) + "')"); + } catch (Exception e) { + //Python logger fails with e.g. Chinese characters, so this done as fallback + System.out.println("*INFO* "+log); + } } public void info(Object message, Throwable t) { @@ -107,7 +124,12 @@ public void info(Object message, Throwable t) { } public void trace(Object log) { - pythonInterpreter.get().eval("logger.trace(repr('" + convertStringToLogger(log) + "')"); + try { + pythonInterpreter.get().eval("logger.trace('" + convertStringToLogger(log) + "')"); + } catch (Exception e) { + //Python logger fails with e.g. Chinese characters, so this done as fallback + System.out.println("*TRACE* "+log); + } } public void trace(Object message, Throwable t) { @@ -116,7 +138,12 @@ public void trace(Object message, Throwable t) { } public void warn(Object log) { - pythonInterpreter.get().eval("logger.warn(repr('" + convertStringToLogger(log) + "')"); + try { + pythonInterpreter.get().eval("logger.warn('" + convertStringToLogger(log) + "')"); + } catch (Exception e) { + //Python logger fails with e.g. Chinese characters, so this done as fallback + System.out.println("*WARN* "+log); + } } public void warn(Object message, Throwable t) {