Skip to content

Commit

Permalink
Added fallback to all logging methods
Browse files Browse the repository at this point in the history
Some more documentation about debug in Session
  • Loading branch information
Hi-Fi committed Jul 11, 2018
1 parent e4074a9 commit db0a74c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit db0a74c

Please sign in to comment.