Skip to content

Commit

Permalink
Update from testing with francois
Browse files Browse the repository at this point in the history
  • Loading branch information
jodygarnett committed Aug 23, 2022
1 parent 06bd5b4 commit 0318f7d
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 524 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,18 @@ protected void setContext(ServiceContext context) {

private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");

/**
* Filename safe representation of harvester name (using '_' as needed).
*
* @return filename safe harvester name
*/
protected String harvesterName(){
return this.getParams().getName().replaceAll("\\W+", "_");
}

/**
* Used to configure Log4J to route harvester messages to an individual file.
*
* Log4J uses the precense of a {@code ThreadContext.put("harvester", name)} to determine
* log file location.
* This method has the side effect of setting Log4J ThreadContext values:
* <ul>
* <li>harvester</li>
* <li>logfile</li>
* <li>timeZone</li>
* </ul>
*
* Log4J checks for {@code ThreadContext.put("logfile", name)} to route messages
* the logfile location.
*
* @return the location of the logfile
*/
Expand All @@ -218,32 +216,46 @@ private String initializeLog() {
String packagename = getClass().getPackage().getName();
String[] packages = packagename.split("\\.");
String packageType = packages[packages.length - 1];
final String harvesterName = harvesterName();

// log = Log.createLogger(harvesterName, "geonetwork.harvester");

String directoryPath = log.getFileAppender();
// Filename safe representation of harvester name (using '_' as needed).
final String harvesterName = this.getParams().getName().replaceAll("\\W+", "_");

if (directoryPath == null || directoryPath.isEmpty()) {
directoryPath = context.getBean(GeonetworkDataDirectory.class).getSystemDataDir() + "/harvester_logs/";
}
File directoryFile = new File(directoryPath);
if (!directoryFile.isDirectory()) {
if( directoryFile.getParentFile() != null){
directoryFile = directoryFile.getParentFile();
}
String logfile = "harvester_"
+ packageType
+ "_" + harvesterName
+ "_" + dateFormat.format(new Date(System.currentTimeMillis()))
+ ".log";

String timeZoneSetting = settingManager.getValue(Settings.SYSTEM_SERVER_TIMEZONE);
if (StringUtils.isBlank(timeZoneSetting)) {
timeZoneSetting = TimeZone.getDefault().getID();
}
File logFile = new File(directoryFile, "harvester_" + packageType + "_"
+ harvesterName + "_"
+ dateFormat.format(new Date(System.currentTimeMillis()))
+ ".log");

String logPath = logFile.getName();
ThreadContext.put("harvest",harvesterName);
ThreadContext.putIfNull("logfile",logfile);
ThreadContext.put("timeZone",timeZoneSetting);

// String timeZoneSetting = settingManager.getValue(Settings.SYSTEM_SERVER_TIMEZONE);
// if (StringUtils.isBlank(timeZoneSetting)) {
// timeZoneSetting = TimeZone.getDefault().getID();
return logfile;



// log = Log.createLogger(harvesterName, "geonetwork.harvester");

// String directoryPath = log.getFileAppender();

// if (directoryPath == null || directoryPath.isEmpty()) {
// directoryPath = context.getBean(GeonetworkDataDirectory.class).getSystemDataDir() + "/harvester_logs/";
// }
// File directoryFile = new File(directoryPath);
// if (!directoryFile.isDirectory()) {
// if( directoryFile.getParentFile() != null){
// directoryFile = directoryFile.getParentFile();
// }
// }




// ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();

Expand All @@ -261,7 +273,7 @@ private String initializeLog() {

// log.setAppender(fa);

return logPath;
// return logPath;
}
//--------------------------------------------------------------------------
//---
Expand All @@ -285,7 +297,7 @@ public void init(Element node, ServiceContext context) throws BadInputEx, Schedu

initInfo(context);

initializeLog();
// initializeLog();
if (status == Status.ACTIVE) {
doSchedule();
}
Expand Down Expand Up @@ -696,8 +708,6 @@ protected OperResult harvest() {
try {

String logfile = initializeLog();
ThreadContext.put("harvest",harvesterName());
ThreadContext.putIfNull("logfile",logfile);

this.log.info("Starting harvesting of " + this.getParams().getName());
error = null;
Expand Down
213 changes: 0 additions & 213 deletions web/src/main/webapp/WEB-INF/classes/log4j-index.xml

This file was deleted.

Loading

0 comments on commit 0318f7d

Please sign in to comment.