Skip to content

Commit

Permalink
use MVBatch print method to print logging messages #484
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaBurek committed Jul 10, 2023
1 parent d2760f0 commit 3854514
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 80 deletions.
24 changes: 10 additions & 14 deletions java/edu/ucar/metviewer/MVBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void print(String message) {
this.printStream.println(message);
this.printStream.flush();
}else {
System.out.println(message);
logger.info(message);
}
}

Expand All @@ -101,7 +101,7 @@ public void printSql(String message) {
this.printStreamSql.print(message);
this.printStreamSql.flush();
}else {
System.out.println(message);
logger.info(message);
}
}

Expand All @@ -110,7 +110,7 @@ public void printError(String message) {
this.printStreamEr.print(message);
this.printStreamEr.flush();
}else {
System.out.println(message);
logger.error(message);
}
}

Expand Down Expand Up @@ -311,11 +311,12 @@ public static void main(String[] argv) throws Exception {
if (!listJobNamesInput.isEmpty()) {
listJobNames = MVUtil.toArray(listJobNamesInput);
}
mvBatch.print((boolList ? "" : "processing ") + listJobNames.length + " jobs:");
StringBuilder mes = new StringBuilder();
mes.append(boolList ? "" : "processing ").append(listJobNames.length).append(" jobs:");
for (String listJobName : listJobNames) {
mvBatch.print(" " + listJobName);
mes.append(listJobName).append("\\n");
}

mvBatch.print(mes.toString());

// if only a list of plot jobs is requested, return
if (boolList) {
Expand All @@ -330,11 +331,7 @@ public static void main(String[] argv) throws Exception {
ArrayList listJobs = new ArrayList();
for (String listJobName : listJobNames) {
if (!mapJobs.containsKey(listJobName)) {
if (mvBatch.printStream == null){
logger.info(" ** WARNING: unrecognized job \"" + listJobName + "\"");
}else {
mvBatch.printStream.println(" ** WARNING: unrecognized job \"" + listJobName + "\"");
}
mvBatch.print(" ** WARNING: unrecognized job \"" + listJobName + "\"");
continue;
}
listJobs.add(mapJobs.get(listJobName));
Expand Down Expand Up @@ -431,14 +428,13 @@ public static void main(String[] argv) throws Exception {

mvBatch.numPlotsRun++;
jobsStopWatch.stop();
mvBatch.print("\n" + "Job " + (intJob + 1) + " execution time " + jobsStopWatch.getFormattedDuration());
mvBatch.print("Job " + (intJob + 1) + " execution time " + jobsStopWatch.getFormattedDuration());

}
stopWatch.stop();
long plotAvg = (jobsStopWatch.getTotalDuration() / 1000000) / (long) mvBatch.numPlots;

mvBatch.print("\n"
+ MVUtil.padBegin("Plots run: ") + mvBatch.getNumPlotsRun() + " of " + mvBatch.getNumPlots()
mvBatch.print(MVUtil.padBegin("Plots run: ") + mvBatch.getNumPlotsRun() + " of " + mvBatch.getNumPlots()
+ "\n"
+ MVUtil.padBegin("Total time: ") + jobsStopWatch.getFormattedTotalDuration() + "\n"
+ MVUtil.padBegin("Avg plot time: ") + MVUtil.formatTimeSpan(plotAvg) + "\n");
Expand Down
9 changes: 7 additions & 2 deletions java/edu/ucar/metviewer/MVUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2104,8 +2104,13 @@ private static String buildTemplate(
}

if (!vals.containsKey(strTmplTagName)) {
printStream.println(" ** WARNING: template tag " + strTmplTagName + " not found in agg"
+ " perm");
if(printStream != null) {
printStream.println(" ** WARNING: template tag " + strTmplTagName + " not found in agg"
+ " perm");
}else {
logger.info(" ** WARNING: template tag " + strTmplTagName + " not found in agg"
+ " perm");
}
continue;
}

Expand Down
81 changes: 66 additions & 15 deletions java/edu/ucar/metviewer/db/mysql/MysqlAppDatabaseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,10 @@ public MvResponse executeQueriesAndSaveToFile(
}
String message = null;
try {
message = "Database query time for " + currentDBName + " "
message = "Database query time for database \"" + currentDBName + "\" "
+ dbStopWatch.getFormattedTotalDuration();
if (saveToFileStopWatch.getTotalDuration() != null) {
message = message + "\nSave to file time for " + currentDBName + " "
message = message + "\nSave to file time for database\"" + currentDBName + "\" "
+ saveToFileStopWatch.getFormattedTotalDuration();
}
} catch (StopWatchException e) {
Expand Down Expand Up @@ -1246,8 +1246,12 @@ public List<String> buildPlotSql(
selRpsProb = selRpsProb + " AND " + plotFixWhere;
}
selRpsProb = selRpsProb + " AND ld.stat_header_id = h.stat_header_id;";
printStreamSql.println(selRpsProb + "\n");
printStreamSql.flush();
if(printStreamSql != null) {
printStreamSql.println(selRpsProb + "\n");
printStreamSql.flush();
}else {
logger.info(selRpsProb);
}
// run the PCT thresh query
List<String> errors = new ArrayList<>();
for (int i = 0; i < job.getCurrentDBName().size(); i++) {
Expand Down Expand Up @@ -1354,8 +1358,12 @@ public List<String> buildPlotSql(
}
selPctThresh = selPctThresh + " AND ld.stat_header_id = h.stat_header_id;";

printStreamSql.println(selPctThresh + "\n");
printStreamSql.flush();
if(printStreamSql != null) {
printStreamSql.println(selPctThresh + "\n");
printStreamSql.flush();
}else {
logger.info(selPctThresh);
}


// run the PCT thresh query
Expand Down Expand Up @@ -1495,9 +1503,14 @@ public List<String> buildPlotSql(
selMctcNcat = selMctcNcat + commonSelect;
selMctcEcValue = selMctcEcValue + commonSelect;

printStreamSql.println(selMctcNcat + "\n");
printStreamSql.println(selMctcEcValue + "\n");
printStreamSql.flush();
if(printStreamSql != null) {
printStreamSql.println(selMctcNcat + "\n");
printStreamSql.println(selMctcEcValue + "\n");
printStreamSql.flush();
}else {
logger.info(selMctcNcat);
logger.info(selMctcEcValue);
}


// run the MCTC thresh query
Expand Down Expand Up @@ -3251,6 +3264,8 @@ public String buildAndExecuteQueriesForHistJob(
if (printStreamSql != null) {
printStreamSql.println(strNumSelect + "\n");
printStreamSql.flush();
}else {
logger.info(strNumSelect);
}


Expand All @@ -3266,7 +3281,11 @@ public String buildAndExecuteQueriesForHistJob(
for (int i = 0; i < listNum.size(); i++) {
strMsg += (0 < i ? ", " : "") + listNum.get(i);
}
printStream.println(strMsg + "\n");
if(printStream != null) {
printStream.println(strMsg + "\n");
}else {
logger.info(strMsg);
}
}


Expand Down Expand Up @@ -3308,6 +3327,8 @@ public String buildAndExecuteQueriesForHistJob(
if (printStreamSql != null) {
printStreamSql.println(strPlotDataSelect + "\n");
printStreamSql.flush();
}else {
logger.info(strPlotDataSelect);
}

// get the data for the current plot from the plot_data temp table and write it to a data file
Expand All @@ -3320,9 +3341,15 @@ public String buildAndExecuteQueriesForHistJob(
job.getCurrentDBName().get(i),
i == 0);
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
if(printStream != null) {
printStream.println(mvResponse.getInfoMessage());
}else {
logger.info(mvResponse.getInfoMessage());
}
}
if(printStream != null) {
printStream.println();
}
printStream.println();
}
return strMsg;
}
Expand Down Expand Up @@ -3385,6 +3412,8 @@ public int buildAndExecuteQueriesForRocRelyJob(

if (printStreamSql != null) {
printStreamSql.println(strObsThreshSelect + "\n");
}else {
logger.info(strObsThreshSelect);
}


Expand All @@ -3411,6 +3440,8 @@ public int buildAndExecuteQueriesForRocRelyJob(

if (printStreamSql != null) {
printStreamSql.println(strFcstThreshSelect + "\n");
}else {
logger.info(strFcstThreshSelect);
}

listFcstThresh = getNumbers(strFcstThreshSelect, job.getCurrentDBName().get(0));
Expand Down Expand Up @@ -3510,6 +3541,8 @@ public int buildAndExecuteQueriesForRocRelyJob(

if (printStreamSql != null) {
printStreamSql.println(strPlotDataSelect + "\n");
}else {
logger.info(strPlotDataSelect);
}


Expand Down Expand Up @@ -3563,7 +3596,11 @@ public int buildAndExecuteQueriesForRocRelyJob(
job.getCurrentDBName().get(i),
i == 0);
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage() + "\n");
if(printStream != null) {
printStream.println(mvResponse.getInfoMessage() + "\n");
}else {
logger.info(mvResponse.getInfoMessage());
}
}
}

Expand Down Expand Up @@ -3628,6 +3665,8 @@ public int buildAndExecuteQueriesForEclvJob(

if (printStreamSql != null) {
printStreamSql.println(strNumSelect + "\n");
}else {
logger.info(strNumSelect);
}
// run the rank number query and warn, if necessary
String strMsg = "";
Expand All @@ -3641,7 +3680,11 @@ public int buildAndExecuteQueriesForEclvJob(
for (int i = 0; i < listNum.size(); i++) {
strMsg += (0 < i ? ", " : "") + listNum.get(i);
}
printStream.println(strMsg + "\n");
if(printStream != null) {
printStream.println(strMsg + "\n");
}else {
logger.info(strMsg);
}
}


Expand All @@ -3660,6 +3703,8 @@ public int buildAndExecuteQueriesForEclvJob(
+ "AND ld.line_data_id = ldt.line_data_id;";
if (printStreamSql != null) {
printStreamSql.println(strSelPctThresh + "\n");
}else {
logger.info(strSelPctThresh);
}

// run the PCT thresh query
Expand Down Expand Up @@ -3713,6 +3758,8 @@ public int buildAndExecuteQueriesForEclvJob(

if (printStreamSql != null) {
printStreamSql.println(strPlotDataSelect + "\n");
}else {
logger.info(strPlotDataSelect);
}


Expand All @@ -3734,7 +3781,11 @@ public int buildAndExecuteQueriesForEclvJob(
job.getCurrentDBName().get(i),
i == 0);
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
if(printStream != null) {
printStream.println(mvResponse.getInfoMessage());
}else {
logger.info(mvResponse.getInfoMessage());
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion java/edu/ucar/metviewer/jobManager/SeriesJobManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ protected void run(MVPlotJob job) throws ParseException, ValidationException, IO
job.getCurrentDBName().get(i),
i == 0);
if (mvResponse.getInfoMessage() != null) {
mvBatch.getPrintStream().println(mvResponse.getInfoMessage());
mvBatch.print(mvResponse.getInfoMessage());
}
}

Expand Down
2 changes: 1 addition & 1 deletion java/edu/ucar/metviewer/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Appenders>
<Console name="appLog" target="SYSTEM_OUT">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%L}{blue}] [%style{%M}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" />
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%L}{blue}] [%style{%M}{bright,blue}] %style{%C{1.}}{bright,yellow}: \r\n%msg%n%throwable\r\n" />
</Console>
</Appenders>

Expand Down
2 changes: 1 addition & 1 deletion java/edu/ucar/metviewer/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Appenders>
<Console name="appLog" target="SYSTEM_OUT">
<PatternLayout
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%L}{blue}] [%style{%M}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" />
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%L}{blue}] [%style{%M}{bright,blue}] %style{%C{1.}}{bright,yellow}: \r\n%msg%n%throwable\r\n" />
</Console>
</Appenders>

Expand Down
Loading

0 comments on commit 3854514

Please sign in to comment.