Skip to content

Commit

Permalink
Merge pull request #478 from dtcenter/issue_48_user_id
Browse files Browse the repository at this point in the history
added user ID and the command line being executed to the log output a…
  • Loading branch information
TatianaBurek authored May 30, 2023
2 parents bb70962 + 66869bf commit b5ce0c8
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 63 deletions.
15 changes: 8 additions & 7 deletions java/edu/ucar/metviewer/MVBatch.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,14 +255,16 @@ public static void main(String[] argv) throws Exception {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
MVBatch mvBatch = new MVBatch();
String username = System.getProperty("user.name");

logger.info("---- MVBatch started by user " + username + "----\n");

logger.info("---- MVBatch ----\n");
try {
MVPlotJob[] jobs;
// if no input file is present, bail
if (1 > argv.length) {
mvBatch.print(getUsage());
logger.info( "---- MVBatch Done ----");
logger.info("---- MVBatch Done by user " + username + " ----");
return;
}
// parse the command line options
Expand All @@ -275,13 +277,12 @@ public static void main(String[] argv) throws Exception {
mvBatch.setVerbose(true);
}else if ("-h".equalsIgnoreCase(argv[0]) || "--h".equalsIgnoreCase(argv[0]) || "-help".equalsIgnoreCase(argv[0])) {
mvBatch.print(getUsage());
logger.info( "---- MVBatch Done ----");
logger.info("---- MVBatch Done by user " + username + " ----");
return;
} else {
logger.error(" ** ERROR: unrecognized option '" + argv[intArg]);
mvBatch.print(getUsage());
logger.info( "---- MVBatch Done ----");

logger.info("---- MVBatch Done by user " + username + " ----");
return;
}
}
Expand Down Expand Up @@ -318,7 +319,7 @@ public static void main(String[] argv) throws Exception {

// if only a list of plot jobs is requested, return
if (boolList) {
logger.info("---- MVBatch Done ----");
logger.info("---- MVBatch Done by user " + username + " ----");
return;
}

Expand Down Expand Up @@ -450,7 +451,7 @@ public static void main(String[] argv) throws Exception {
}
mvBatch.closeDataSource();

logger.info("---- MVBatch Done ----");
logger.info("---- MVBatch Done by user " + username + " ----");

logger.info("Total execution time " + stopWatch.getFormattedTotalDuration());

Expand Down
6 changes: 5 additions & 1 deletion java/edu/ucar/metviewer/prune/MVPruneDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public static String getUsage() {
public static void main(String[] args) throws Exception {
String filename;
String dbType = "mysql";
String username = System.getProperty("user.name");

if (0 == args.length) {
logger.error(" Error: no arguments!!!");
logger.info(getUsage());
Expand All @@ -81,6 +83,8 @@ public static void main(String[] args) throws Exception {
return;
}
}
logger.info("---- Database pruning started by user " + username + "----\n");

String version = MVUtil.getVersionNumber();
if (!version.isEmpty()){
logger.info("Version: " + version + "\n");
Expand Down Expand Up @@ -109,7 +113,7 @@ public static void main(String[] args) throws Exception {
}

}
logger.info("---- MVPruneDB Done ----");
logger.info("---- MVPruneDB Done by user " + username +" ----");
}

public Set<String> getDirectories() {
Expand Down
7 changes: 7 additions & 0 deletions java/edu/ucar/metviewer/scorecard/Scorecard.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ public static void main(String[] args) throws Exception {
String dbType = "mysql";
StopWatch stopWatch = new StopWatch();
stopWatch.start();
String username = System.getProperty("user.name");
logger.info("---- Scorecard started by user " + username + "----\n");

if (0 == args.length) {
logger.info(" Error: no arguments!!!");
logger.info(getUsage());
logger.info("---- Scorecard Done by user " + username + " ----");

} else {

Expand All @@ -108,12 +112,14 @@ public static void main(String[] args) throws Exception {
dbType = "aurora";
} else if ("-h".equalsIgnoreCase(args[intArg]) || "--h".equalsIgnoreCase(args[intArg]) || "-help".equalsIgnoreCase(args[intArg])) {
logger.info(getUsage());
logger.info("---- Scorecard Done by user " + username + " ----");
return;
}
}

filename = args[intArg];


String version = MVUtil.getVersionNumber();
if (!version.isEmpty()){
logger.info("Version: " + version + "\n");
Expand Down Expand Up @@ -235,6 +241,7 @@ public static void main(String[] args) throws Exception {
}
}
stopWatch.stop();
logger.info("---- Scorecard is done by user " + username + "----\n");
logger.info("\nTotal execution time " + stopWatch.getFormattedTotalDuration());

}
Expand Down
17 changes: 6 additions & 11 deletions java/edu/ucar/metviewer/scorecard/rscript/AggPythonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
import edu.ucar.metviewer.scorecard.model.Field;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.io.IoBuilder;


import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;

import static edu.ucar.metviewer.MVUtil.createYamlFile;
Expand Down Expand Up @@ -119,13 +116,11 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
}
yamlInfo.put("append_to_file", isAppend ? "True" : "False");

try (PrintStream printStream = IoBuilder.forLogger(AggRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
try {
createYamlFile(aggInfoFileName, yamlInfo);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + python + " " + metCalcpyHome + PYTHON_SCRIPT + " " + aggInfoFileName);
logger.info("Running " + python + " " + metCalcpyHome + PYTHON_SCRIPT + " " + aggInfoFileName);


MvResponse mvResponse = MVUtil.runRscript(python,
Expand All @@ -134,12 +129,12 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
new String[]{"PYTHONPATH=" + metCalcpyHome});
stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
logger.info(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
logger.error(mvResponse.getErrorMessage());
}
printStream.println("Python time " + stopWatch.getFormattedTotalDuration());
logger.info("Python time " + stopWatch.getFormattedTotalDuration());
} catch (IOException | StopWatchException e) {
logger.error( e.getMessage());
}
Expand Down
17 changes: 6 additions & 11 deletions java/edu/ucar/metviewer/scorecard/rscript/AggRscriptManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -24,9 +23,7 @@
import edu.ucar.metviewer.scorecard.model.Field;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.io.IoBuilder;


/**
* Constructs and runs Rscript for agg stats
Expand Down Expand Up @@ -138,9 +135,7 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
String thredInfoFileName = strAggInfo.substring(0, lastDot) + threadName + strAggInfo
.substring(lastDot);

try (PrintStream printStream = IoBuilder.forLogger(AggRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
try {

String aggStatTemplScript;
String aggStatTemplFile;
Expand All @@ -151,19 +146,19 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
MVUtil.populateTemplateFile(aggStatTemplFile, thredInfoFileName, tableAggStatInfo);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + rScriptCommand + " " + aggStatTemplScript);
logger.info("Running " + rScriptCommand + " " + aggStatTemplScript);


MvResponse mvResponse = MVUtil.runRscript(rScriptCommand, aggStatTemplScript,
new String[]{thredInfoFileName});
stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
logger.info(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
logger.error(mvResponse.getErrorMessage());
}
printStream.println("Rscript time " + stopWatch.getFormattedTotalDuration());
logger.info("Rscript time " + stopWatch.getFormattedTotalDuration());
} catch (IOException | StopWatchException e) {
logger.error( e.getMessage());
}
Expand Down
26 changes: 10 additions & 16 deletions java/edu/ucar/metviewer/scorecard/rscript/SumPythonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.apache.logging.log4j.io.IoBuilder;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.time.LocalDate;
import java.util.*;

Expand Down Expand Up @@ -117,15 +115,13 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) t
yamlInfo.put("fixed_vars_vals_input", listFixedValEx);


try (PrintStream printStream = IoBuilder.forLogger(SumRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
try {

createYamlFile(sumInfoFileName, yamlInfo);

StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + python + " " + metCalcpyHome + PYTHON_SCRIPT + " " + sumInfoFileName);
logger.info("Running " + python + " " + metCalcpyHome + PYTHON_SCRIPT + " " + sumInfoFileName);


MvResponse mvResponse = MVUtil.runRscript(python,
Expand All @@ -135,12 +131,12 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) t

stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
logger.info(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
logger.error(mvResponse.getErrorMessage());
}
printStream.println("Python time " + stopWatch.getFormattedTotalDuration());
logger.info("Python time " + stopWatch.getFormattedTotalDuration());
} catch (StopWatchException | IOException e) {
logger.error( e.getMessage());
}
Expand Down Expand Up @@ -232,15 +228,13 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) t
yamlInfo.put("sum_stat_input", scorecardInput);
yamlInfo.put("sum_stat_output", scorecardOutput);

try (PrintStream printStream = IoBuilder.forLogger(SumPythonManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
try {

createYamlFile(pythonFileInfo, yamlInfo);

StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + python + " " + metCalcpyHome + "/metcalcpy/scorecard.py" + " " + pythonFileInfo);
logger.info("Running " + python + " " + metCalcpyHome + "/metcalcpy/scorecard.py" + " " + pythonFileInfo);


MvResponse mvResponse = MVUtil.runRscript(python,
Expand All @@ -250,12 +244,12 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) t

stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
logger.info(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
logger.error(mvResponse.getErrorMessage());
}
printStream.println("Python time " + stopWatch.getFormattedTotalDuration());
logger.info("Python time " + stopWatch.getFormattedTotalDuration());
} catch (IOException | StopWatchException e) {
logger.error( e.getMessage());
}
Expand Down
27 changes: 10 additions & 17 deletions java/edu/ucar/metviewer/scorecard/rscript/SumRscriptManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -26,8 +25,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import org.apache.logging.log4j.io.IoBuilder;

import static java.time.temporal.ChronoUnit.DAYS;

/**
Expand Down Expand Up @@ -173,9 +170,7 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
String thredInfoFileName = strSumInfo.substring(0, lastDot)
+ threadName + strSumInfo.substring(lastDot);

try (PrintStream printStream = IoBuilder.forLogger(SumRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
try {
String sumStatTemplScript;
String sumStatTemplFile;

Expand All @@ -185,20 +180,20 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {

StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + rScriptCommand + " " + sumStatTemplScript);
logger.info("Running " + rScriptCommand + " " + sumStatTemplScript);


MvResponse mvResponse = MVUtil.runRscript(rScriptCommand, sumStatTemplScript,
new String[]{thredInfoFileName});

stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
logger.info(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
logger.error(mvResponse.getErrorMessage());
}
printStream.println("Rscript time " + stopWatch.getFormattedTotalDuration());
logger.info("Rscript time " + stopWatch.getFormattedTotalDuration());
} catch (StopWatchException | IOException e) {
logger.error( e.getMessage());
}
Expand All @@ -213,25 +208,23 @@ public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
tableCalcStatInfoCommon.get("sum_stat_output"));


try (PrintStream printStream = IoBuilder.forLogger(SumRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
try {
MVUtil.populateTemplateFile(calcStatTemplScript, strRFile, tableCalcStatInfo);

StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + rScriptCommand + " " + strRFile);
logger.info("Running " + rScriptCommand + " " + strRFile);


MvResponse mvResponse = MVUtil.runRscript(rScriptCommand, strRFile);
stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
logger.info(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
logger.error(mvResponse.getErrorMessage());
}
printStream.println("Rscript time " + stopWatch.getFormattedTotalDuration());
logger.info("Rscript time " + stopWatch.getFormattedTotalDuration());
} catch (IOException | StopWatchException e) {
logger.error( e.getMessage());
}
Expand Down

0 comments on commit b5ce0c8

Please sign in to comment.