Python: refactoring loggers

This commit is contained in:
Alexander Bezzubov 2016-06-27 19:57:39 +09:00
parent d7f8cdd468
commit 651d8e82af
2 changed files with 21 additions and 22 deletions

View file

@ -43,7 +43,7 @@ import java.util.Properties;
* Python interpreter for Zeppelin.
*/
public class PythonInterpreter extends Interpreter {
Logger logger = LoggerFactory.getLogger(PythonInterpreter.class);
private static final Logger LOG = LoggerFactory.getLogger(PythonInterpreter.class);
public static final String BOOTSTRAP_PY = "/bootstrap.py";
public static final String BOOTSTRAP_INPUT_PY = "/bootstrap_input.py";
@ -65,8 +65,8 @@ public class PythonInterpreter extends Interpreter {
@Override
public void open() {
logger.info("Starting Python interpreter .....");
logger.info("Python path is set to:" + property.getProperty(ZEPPELIN_PYTHON));
LOG.info("Starting Python interpreter .....");
LOG.info("Python path is set to:" + property.getProperty(ZEPPELIN_PYTHON));
maxResult = Integer.valueOf(getProperty(MAX_RESULT));
process = getPythonProcess();
@ -74,32 +74,32 @@ public class PythonInterpreter extends Interpreter {
try {
process.open();
} catch (IOException e) {
logger.error("Can't start the python process", e);
LOG.error("Can't start the python process", e);
}
try {
logger.info("python PID : " + process.getPid());
LOG.info("python PID : " + process.getPid());
} catch (Exception e) {
logger.warn("Can't find python pid process", e);
LOG.warn("Can't find python pid process", e);
}
try {
logger.info("Bootstrap interpreter with " + BOOTSTRAP_PY);
LOG.info("Bootstrap interpreter with " + BOOTSTRAP_PY);
bootStrapInterpreter(BOOTSTRAP_PY);
} catch (IOException e) {
logger.error("Can't execute " + BOOTSTRAP_PY + " to initiate python process", e);
LOG.error("Can't execute " + BOOTSTRAP_PY + " to initiate python process", e);
}
if (py4J = isPy4jInstalled()) {
port = findRandomOpenPortOnAllLocalInterfaces();
logger.info("Py4j gateway port : " + port);
LOG.info("Py4j gateway port : " + port);
try {
gatewayServer = new GatewayServer(this, port);
gatewayServer.start();
logger.info("Bootstrap inputs with " + BOOTSTRAP_INPUT_PY);
LOG.info("Bootstrap inputs with " + BOOTSTRAP_INPUT_PY);
bootStrapInterpreter(BOOTSTRAP_INPUT_PY);
} catch (IOException e) {
logger.error("Can't execute " + BOOTSTRAP_INPUT_PY + " to " +
LOG.error("Can't execute " + BOOTSTRAP_INPUT_PY + " to " +
"initialize Zeppelin inputs in python process", e);
}
}
@ -107,7 +107,7 @@ public class PythonInterpreter extends Interpreter {
@Override
public void close() {
logger.info("closing Python interpreter .....");
LOG.info("closing Python interpreter .....");
try {
if (process != null) {
process.close();
@ -116,7 +116,7 @@ public class PythonInterpreter extends Interpreter {
gatewayServer.shutdown();
}
} catch (IOException e) {
logger.error("Can't close the interpreter", e);
LOG.error("Can't close the interpreter", e);
}
}
@ -136,7 +136,7 @@ public class PythonInterpreter extends Interpreter {
try {
process.interrupt();
} catch (IOException e) {
logger.error("Can't interrupt the python interpreter", e);
LOG.error("Can't interrupt the python interpreter", e);
}
}
@ -184,11 +184,11 @@ public class PythonInterpreter extends Interpreter {
private String sendCommandToPython(String cmd) {
String output = "";
logger.info("Sending : \n" + (cmd.length() > 200 ? cmd.substring(0, 200) + "..." : cmd));
LOG.info("Sending : \n" + (cmd.length() > 200 ? cmd.substring(0, 200) + "..." : cmd));
try {
output = process.sendAndGetResult(cmd);
} catch (IOException e) {
logger.error("Error when sending commands to python process", e);
LOG.error("Error when sending commands to python process", e);
}
//logger.info("Got : \n" + output);
return output;
@ -207,7 +207,7 @@ public class PythonInterpreter extends Interpreter {
if (py4J && port != null && port != -1) {
bootstrapCode = bootstrapCode.replaceAll("\\%PORT\\%", port.toString());
}
logger.info("Bootstrap python interpreter with code from \n " + file);
LOG.info("Bootstrap python interpreter with code from \n " + file);
sendCommandToPython(bootstrapCode);
}
@ -234,7 +234,7 @@ public class PythonInterpreter extends Interpreter {
port = socket.getLocalPort();
socket.close();
} catch (IOException e) {
logger.error("Can't find an open port", e);
LOG.error("Can't find an open port", e);
}
return port;
}

View file

@ -51,8 +51,7 @@ import java.util.Properties;
* Python interpreter unit test
*/
public class PythonInterpreterTest {
Logger logger = LoggerFactory.getLogger(PythonProcess.class);
private static final Logger LOG = LoggerFactory.getLogger(PythonProcess.class);
PythonInterpreter pythonInterpreter = null;
PythonProcess mockPythonProcess;
@ -81,7 +80,7 @@ public class PythonInterpreterTest {
}
});
} catch (IOException e) {
logger.error("Can't initiate python process", e);
LOG.error("Can't initiate python process", e);
}
pythonInterpreter = spy(new PythonInterpreter(getPythonTestProperties()));
@ -188,7 +187,7 @@ public class PythonInterpreterTest {
try {
s.close();
} catch (IOException e) {
logger.error("Can't close connection to localhost:" + py4jPort, e);
LOG.error("Can't close connection to localhost:" + py4jPort, e);
}
}
return working;