Http://blog.sina.com.cn/s/blog_76a8411a01010u2h.html
First: When we introduce all the jar packages under the Data-integration\lib folder and run the Java program, we have to introduce log4j, so we can confirm that the information for the console output is log4j:
The procedure is as follows:
public static void Main (string[] args) throws exception{
Kettleenvironment.init ();
try {
Jobmetajobmeta = new Jobmeta ("E:\\BI\\SAMPLE.KJB", null,null);
Job Job = Newjob (null, Jobmeta);
Jobmeta.setarguments (newstring[]{"AAAAA", "BBBBBB"});//Pass parameter
Job.getjobmeta (). Setinternalkettlevariables (Job);
Job.setloglevel (Loglevel.basic);
Start the Job, as it is a Thread itself by kettle.
Job.start ();
Job.waituntilfinished ();
if (Job.getresult ()! = null && Job.getresult (). Getnrerrors ()! = 0) {
Do something here.
}
//Now's job task is finished, mark it as Finished.
job.setfinished (true);
Cleanup the parameters used by the job. Post that INVOKEGC.
Jobmeta.eraseparameters ();
Job.eraseparameters ();
} catch (Exception e) {
E.printstacktrace ();
}
}
Steps to resolve:
1, first think of the source of the view output these logs: Job class
2, through the anti-compilation software or view the source file View Code found: This.log = new Logchannel (this);
3, enter Logchannel find: private staticlogwriter log = Logwriter.getinstance ();
Can be seen as a single case
4. See how the Logwiter is constructed:
Private LogWriter ()
{
This.pentahologger = Logger.getlogger ("Org.pentaho.di");
This.pentahoLogger.setAdditivity (FALSE);
This.pentahoLogger.setLevel (Level.all);
Layout = new Log4jkettlelayout ();
Boolean consoleappenderfound = false;
Enumerationappenders = This.pentahoLogger.getAllAppenders ();
while (Appenders.hasmoreelements ()) {
Appender Appender = (Appender) appenders.nextelement ();
if ((Appender instanceof Consoleappender)) {
Consoleappenderfound = true;
Break
}
}
if (!consoleappenderfound) {
Layout patternlayout = new Patternlayout ("%-5p%d{dd-mmhh:mm:ss,sss}-%m%n");
Consoleappender Consoleappender = Newconsoleappender (patternlayout);
Consoleappender.setname ("ConsoleAppender:org.pentaho.di");
This.pentahoLogger.addAppender (Consoleappender);
}
Logmanager.getlogger ("Org.apache.commons.vfs"). SetLevel (Level.warn);
}
5, see the original they are judged there is no console output, if not added to a console output,
The identifier for log is: Logger.getlogger ("org.pentaho.di");
6, ==============================================================
=================================================================
Thus, we can add a line of code to our program: Manually to join a Fileappender
In the try, the first line joins:
Logger.getlogger ("Org.pentaho.di"). Addappender (Newfileappender (New Simplelayout (), "E:\\logger.log"));
So that we can input the log from the console side directly into a log file.
Output console log-to-text in Java programs