AnsweredAssumed Answered

Having Problem writing log using custom scripting.

Question asked by nirupama110156 on Jul 17, 2017
Latest reply on Jul 18, 2017 by daniel.santana

We are using the Data Process shape to write log (using custom scripting).

Below is the code:

import org.apache.log4j.Appender;
import org.apache.log4j.FileAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.DailyRollingFileAppender;

 

SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
Logger logger = Logger.getLogger("");

//CREATES PATTERN LAYOUT.
PatternLayout layout = new PatternLayout();
String conversionPattern = "[%p] %d %c %M - %m%n";
layout.setConversionPattern(conversionPattern);

// CREATES DAILY ROLLING FILE APPENDER.
DailyRollingFileAppender fh = new DailyRollingFileAppender();
logger.addAppender(fh);
fh.setFile("MyLogFile_" + format.format(Calendar.getInstance().getTime()) + ".log");
fh.setDatePattern("'.'yyyy-MM-dd");
fh.setLayout(layout);
fh.activateOptions();

// CONFIGURES THE ROOT LOGGER
//Logger rootLogger = Logger.getRootLogger();
//rootLogger.setLevel(Level.DEBUG);
//rootLogger.addAppender(rollingAppender);

//CREATES A CUSTOM LOG MESSAGE.
logger.info("Initializing: Executing Process.1");

logger.info("Initializing: Reading files.");

 

But each time we are running the process the log is written something like this:

 

1st transaction:

[INFO] 2017-07-17 14:46:06,332  invoke - Initializing:        Executing Process.1

[INFO] 2017-07-17 14:46:06,403  invoke - Initializing:       Reading files.

 

2nd transaction:

[INFO] 2017-07-17 14:46:06,332  invoke - Initializing:        Executing Process.1

[INFO] 2017-07-17 14:46:06,403  invoke - Initializing:       Reading files.

[INFO] 2017-07-17 14:47:01,027  invoke - Initializing:        Executing Process.1

[INFO] 2017-07-17 14:47:01,027  invoke - Initializing:        Executing Process.1

[INFO] 2017-07-17 14:47:01,029  invoke - Initializing:       Reading files.

[INFO] 2017-07-17 14:47:01,029  invoke - Initializing:       Reading files.

 

But in 2nd transaction it should be like,

[INFO] 2017-07-17 14:46:06,332  invoke - Initializing:        Executing Process.1

[INFO] 2017-07-17 14:46:06,403  invoke - Initializing:       Reading files.

[INFO] 2017-07-17 14:47:01,027 invoke - Initializing:        Executing Process.1

[INFO] 2017-07-17 14:47:01,029  invoke - Initializing:       Reading files.

 

How this issue cane be resolved?

Outcomes