Skip to content

Commit

Permalink
JAPI-110 Add log4j support (#202)
Browse files Browse the repository at this point in the history
* JAPI-110 Add log4j support

- Added log4j as a dependency
- Added log4j.properties file
- Replaced current logging functionality with log4j

Signed-off-by: James McMullan <James.McMullan@lexisnexis.com>

* Code review changes

- Moved to an older version of log4j that doesnt require newer Java versions
- Deprecated Utils.print & Utils.println
- Changed default log level in print & println to info / warn
- Added log function to Utils for end users to potential use
- Reversed logging changes in rdf2hpcc & clienttools
  • Loading branch information
jpmcmu authored and rpastrana committed Sep 26, 2018
1 parent 779d7e3 commit 39a06a4
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 90 deletions.
6 changes: 6 additions & 0 deletions wsclient/log4j.properties
@@ -0,0 +1,6 @@
log4j.rootLogger=INFO, stdout

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

log4j.appender.stdout.layout.ConversionPattern=%d %p %t %C - %m%n
5 changes: 5 additions & 0 deletions wsclient/pom.xml
Expand Up @@ -136,6 +136,11 @@
<artifactId>mail</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<profiles>
<profile>
Expand Down
Expand Up @@ -18,7 +18,9 @@
import java.util.HashMap;
import java.util.Properties;

import org.apache.log4j.Logger;
import org.apache.axis.client.Stub;

import org.hpccsystems.ws.client.gen.filespray.v1_15.DropZone;
import org.hpccsystems.ws.client.gen.filespray.v1_15.DropZoneFilesRequest;
import org.hpccsystems.ws.client.gen.filespray.v1_15.DropZoneFilesResponse;
Expand Down Expand Up @@ -111,6 +113,7 @@ public static SprayVariableFormat convertVarSprayFormatName2Code(String varSpray
}

private static URL originalURL;
private static Logger log = Logger.getLogger(HPCCFileSprayClient.class.getName());

public static URL getOriginalURL() throws MalformedURLException
{
Expand Down Expand Up @@ -784,7 +787,7 @@ public boolean uploadLargeFile(File uploadFile, DropZone dropZone)
}
catch (IOException e)
{
Utils.println(System.err, "Encountered error while reading file: " + e.getLocalizedMessage() , false, verbose);
log.error("Encountered error while reading file: " + e.getLocalizedMessage());
returnValue = false;
}
finally
Expand All @@ -803,12 +806,12 @@ public boolean uploadLargeFile(File uploadFile, DropZone dropZone)
}
catch (MalformedURLException e)
{
Utils.println(System.err, "There was a malformed URL: " + e.getLocalizedMessage() , false, verbose);
log.error("There was a malformed URL: " + e.getLocalizedMessage());
returnValue = false;
}
catch (IOException e)
{
Utils.println(System.err, "There was an error opening the file: " + e.getLocalizedMessage() , false, verbose);
log.error("There was an error opening the file: " + e.getLocalizedMessage());
e.printStackTrace();
returnValue = false;
}
Expand All @@ -824,7 +827,7 @@ public boolean uploadLargeFile(File uploadFile, DropZone dropZone)
}
catch (IOException e)
{
Utils.println(System.err, "Encountered error while closing: " + e.getLocalizedMessage() , false, verbose);
log.error("Encountered error while closing: " + e.getLocalizedMessage());
}
}

Expand Down Expand Up @@ -899,13 +902,13 @@ private boolean uploadFile(File file, DropZone dropZone) throws Exception
while ((line = rreader.readLine()) != null)
response.append(line);

Utils.println(System.out, "File upload has finished, please fetch file list to verify upload", false, verbose);
log.debug("File upload has finished, please fetch file list to verify upload");
}
catch (Exception e)
{
if (!fileUploadURL.equals(fileUploadConnection.getURL()))
{
Utils.println(System.err, "HTTP Error reported on File upload related to a server redirect, please verify on server.", false, verbose);
log.error("HTTP Error reported on File upload related to a server redirect, please verify on server.");
}

if (verbose)
Expand Down
36 changes: 20 additions & 16 deletions wsclient/src/main/java/org/hpccsystems/ws/client/HPCCWsClient.java
Expand Up @@ -5,6 +5,8 @@
import java.rmi.RemoteException;
import java.util.List;

import org.apache.log4j.Logger;

import org.hpccsystems.ws.client.HPCCFileSprayClient.SprayVariableFormat;
import org.hpccsystems.ws.client.extended.HPCCWsAttributesClient;
import org.hpccsystems.ws.client.extended.HPCCWsSQLClient;
Expand Down Expand Up @@ -34,6 +36,8 @@
*/
public class HPCCWsClient extends DataSingleton
{
private static final Logger log = Logger.getLogger(HPCCWsClient.class.getName());

public static DataSingletonCollection All = new DataSingletonCollection();
public static DataSingletonCollection SubClients = new DataSingletonCollection();

Expand Down Expand Up @@ -530,11 +534,11 @@ public boolean sprayFlatHPCCFile(String fileName, String targetFileLabel, int re
}
catch (ArrayOfEspException e)
{
Utils.println(System.out, "Error: Could not spray file" + e.getLocalizedMessage(),true, verbosemode);
log.error("Error: Could not spray file" + e.getLocalizedMessage());
}
catch (RemoteException e)
{
Utils.println(System.out, "Error: Could not spray file" + e.getLocalizedMessage(),true, verbosemode);
log.error("Error: Could not spray file" + e.getLocalizedMessage());
}
catch (Exception e)
{
Expand Down Expand Up @@ -566,7 +570,7 @@ public boolean sprayCustomCSVHPCCFile(String fileName, String targetFileLabel, S
}
catch (Exception e)
{
Utils.println(System.out, "Error: Could not spray file", true, true);
log.error("Error: Could not spray file");
success = false;
}

Expand Down Expand Up @@ -623,11 +627,11 @@ public boolean sprayVariableHPCCFile(String fileName, String targetFileLabel, St
}
catch (org.hpccsystems.ws.client.gen.filespray.v1_15.ArrayOfEspException e)
{
Utils.println(System.out, "Error: Could not spray file" + e.getLocalizedMessage(),true, true);
log.error("Error: Could not spray file" + e.getLocalizedMessage());
}
catch (RemoteException e)
{
Utils.println(System.out, "Error: Could not spray file" + e.getLocalizedMessage(),true, true);
log.error("Error: Could not spray file" + e.getLocalizedMessage());
}
catch (Exception e)
{
Expand All @@ -646,7 +650,7 @@ private boolean handleSprayResponse(ProgressResponse sprayResponse) throws Excep
{
for (EspException espexception : exceptions.getException())
{
Utils.println(System.out, "Error spraying file: " + espexception.getSource() + espexception.getMessage(), false, verbosemode);
log.error("Error spraying file: " + espexception.getSource() + espexception.getMessage());
}
}
else
Expand All @@ -658,23 +662,23 @@ private boolean handleSprayResponse(ProgressResponse sprayResponse) throws Excep

ProgressRequest dfuprogressparams = new ProgressRequest();
dfuprogressparams.setWuid(sprayResponse.getWuid());
Utils.println(System.out, "Spray file DWUID: " +sprayResponse.getWuid(), true, verbosemode);
log.debug("Spray file DWUID: " +sprayResponse.getWuid());
ProgressResponse progressResponse = fileSprayClient.fileSprayServiceSoapProxy.getDFUProgress(dfuprogressparams);

if (progressResponse.getExceptions() != null)
{
Utils.println(System.out, "Spray progress status fetch failed.", false, verbosemode);
log.error("Spray progress status fetch failed.");
}
else
{
String state = progressResponse.getState();
Utils.println(System.out, progressResponse.getState(), true, verbosemode);
log.debug(progressResponse.getState());
if (!state.equalsIgnoreCase("FAILED"))
{
//this should be in a dedicated thread.
for (int i = 0; i < 10 && progressResponse.getPercentDone() < 100 && !progressResponse.getState().equalsIgnoreCase("FAILED"); i++)
{
Utils.println(System.out, progressResponse.getProgressMessage(), true, verbosemode);
log.debug(progressResponse.getProgressMessage());
progressResponse = fileSprayClient.fileSprayServiceSoapProxy.getDFUProgress(dfuprogressparams);

try
Expand All @@ -686,16 +690,16 @@ private boolean handleSprayResponse(ProgressResponse sprayResponse) throws Excep
e.printStackTrace();
}
}
Utils.println(System.out, progressResponse.getProgressMessage(), true, verbosemode);
log.debug(progressResponse.getProgressMessage());
success = true;
}
else
{
Utils.println(System.out, "Spray failed.", false, verbosemode);
log.error("Spray failed.");
}
Utils.println(System.out, "Final summary from server: " + progressResponse.getSummaryMessage(),true, verbosemode);
log.debug("Final summary from server: " + progressResponse.getSummaryMessage());

Utils.println(System.out, "Spray attempt completed, verify DWUID: " +sprayResponse.getWuid(), false, verbosemode);
log.info("Spray attempt completed, verify DWUID: " +sprayResponse.getWuid());
}
}
return success;
Expand Down Expand Up @@ -778,7 +782,7 @@ public String submitECLandGetResults(WorkunitInfo wu) throws Exception
}
catch (Exception e)
{
Utils.println(System.err, "Error submitting ECL: " + e.getLocalizedMessage(), false, verbosemode);
log.error("Error submitting ECL: " + e.getLocalizedMessage());
throw e;
}

Expand Down Expand Up @@ -825,7 +829,7 @@ public String submitECLandGetWUID(WorkunitInfo wu)
}
catch (Exception e)
{
System.out.println("Error submitting ECL: " + e.getLocalizedMessage());
log.error("Error submitting ECL: " + e.getLocalizedMessage());
e.printStackTrace();
}

Expand Down
Expand Up @@ -13,7 +13,9 @@
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.log4j.Logger;
import org.apache.axis.client.Stub;

import org.apache.commons.lang3.StringUtils;
import org.hpccsystems.ws.client.gen.wsdfu.v1_39.SuperfileListRequest;
import org.hpccsystems.ws.client.gen.wsdfu.v1_39.SuperfileListResponse;
Expand Down Expand Up @@ -66,6 +68,7 @@
public class HPCCWsDFUClient extends DataSingleton
{
private static URL originalURL;
private static final Logger log = Logger.getLogger(HPCCWsDFUClient.class.getName());

public static URL getOriginalURL() throws MalformedURLException
{
Expand Down Expand Up @@ -167,8 +170,7 @@ public DFUInfoResponse getFileInfo(String logicalname, String clustername,
{
for (EspException espexception : e.getException())
{
Utils.println(System.out, "Error retrieving file type for file: " + espexception.getSource()
+ espexception.getMessage(), false, true);
log.error("Error retrieving file type for file: " + espexception.getSource() + espexception.getMessage());
}
}
throw e;
Expand Down Expand Up @@ -246,8 +248,8 @@ public NodeList getFileData(String logicalname, Long beginrow, Integer numrows,
{
for (EspException espexception : e.getException())
{
Utils.println(System.out, "Error retrieving file type for file: " + espexception.getSource()
+ espexception.getMessage(), false, true);
log.error("Error retrieving file type for file: " + espexception.getSource()
+ espexception.getMessage());
}
}
throw e;
Expand Down Expand Up @@ -362,7 +364,7 @@ public List<DFUDataColumnInfo> getFileMetaDataInfo(String logicalname, String cl
catch (Exception e)
{
String msg = "Error calling DFUInfo for " + logicalname + ":" + e.getMessage();
Utils.println(System.out, msg, true, verbose);
log.error(msg);
throw new Exception(msg, e);
}
try
Expand Down Expand Up @@ -397,8 +399,8 @@ public List<DFUDataColumnInfo> getFileMetaDataInfo(String logicalname, String cl
{
for (EspException espexception : e.getException())
{
Utils.println(System.out, "Error retrieving field names for file: " + espexception.getSource()
+ espexception.getMessage(), false, true);
log.error("Error retrieving field names for file: " + espexception.getSource()
+ espexception.getMessage());
}
}
throw e;
Expand Down Expand Up @@ -438,9 +440,7 @@ public List<DFUDataColumnInfo> getFileMetaDataInfo(String logicalname, String cl
}
catch (Exception e)
{
Utils.println(System.err,
"Could not parse ecl for " + logicalname + ", returning base metadata. Ecl:" + eclrecord, false,
false);
log.error("Could not parse ecl for " + logicalname + ", returning base metadata. Ecl:" + eclrecord);
}

return cols;
Expand Down Expand Up @@ -483,8 +483,8 @@ public DFUDataColumn[] getFileMetaData(String logicalname, String clustername) t
{
for (EspException espexception : e.getException())
{
Utils.println(System.out, "Error retrieving field names for file: " + espexception.getSource()
+ espexception.getMessage(), false, true);
log.error("Error retrieving field names for file: " + espexception.getSource()
+ espexception.getMessage());
}
}
throw e;
Expand Down Expand Up @@ -558,8 +558,8 @@ public List<DFUDataColumnInfo> getFileDataColumns(String logicalname, String clu
{
for (EspException espexception : e.getException())
{
Utils.println(System.out, "Error retrieving field names for file: " + espexception.getSource()
+ espexception.getMessage(), false, true);
log.error("Error retrieving field names for file: " + espexception.getSource()
+ espexception.getMessage());
}
}
throw e;
Expand Down Expand Up @@ -704,7 +704,7 @@ private void handleException(ArrayOfEspException exp) throws Exception
{
errs = errs + ex.getMessage() + "\n";
}
Utils.println(System.out, ex.getMessage(), true, verbose);
log.error(ex.getMessage());
}
throw new Exception(errs, exp);
}
Expand Down Expand Up @@ -1048,8 +1048,8 @@ public DFUFileDetailInfo getFileDetails(String logicalname, String clustername,
{
for (EspException espexception : e.getException())
{
Utils.println(System.out, "Error retrieving file type for file: " + logicalname + ": "
+ espexception.getSource() + espexception.getMessage(), false, true);
log.error("Error retrieving file type for file: " + logicalname + ": "
+ espexception.getSource() + espexception.getMessage());
}
}
throw e;
Expand Down

0 comments on commit 39a06a4

Please sign in to comment.