Discussion:
[JSch-users] How to set ChannelExec error stream from System.err to log4j
Ravi Joshi
2013-12-29 09:47:32 UTC
Permalink
Hi,

I want to execute a command to remote linux machine. I am referring Exec.java (http://www.jcraft.com/jsch/examples/Exec.java.html) example code.

I just wanted to know How to set ChannelExec error stream from System.err to log4j, so that all of these errors, I can get captured by log4j under error catagory.


-
Thanks
Ravi
Viet H. Phan
2013-12-30 02:26:24 UTC
Permalink
Hi Ravi,

1) Create your own Logger class that implements com.jcraft.jsch.Logger and uses log4j
2) Apply your Logger using com.jcraft.jsch.JSch.setLogger(com.jcraft.jsch.Logger) method
Check Logger class of JSch example for reference.

Hope this helps.

Regards,
Viet




________________________________
From: Ravi Joshi <***@yahoo.com>
To: "jsch-***@lists.sourceforge.net" <jsch-***@lists.sourceforge.net>
Sent: Sunday, 29 December 2013 4:47 PM
Subject: [JSch-users] How to set ChannelExec error stream from System.err to log4j



Hi,

I want to execute a command to remote linux machine. I am referring Exec.java (http://www.jcraft.com/jsch/examples/Exec.java.html) example code.

I just wanted to know How to set ChannelExec error stream from System.err to log4j, so that all of these errors, I can get captured by log4j under error catagory.


-
Thanks
Ravi
Ravi Joshi
2013-12-30 16:59:21 UTC
Permalink
Thanks Viet,

I got your idea and looked over the example code. However I am looking for any short solution for this. Basically the example code (http://www.jcraft.com/jsch/examples/Exec.java.html) line no 67 has following line-

((ChannelExec) channel).setErrStream(System.err);


Now I have a modified class of Exec.java which uses log4j logger like this-

import org.apache.log4j.Logger;

public class Exec{
    private static final Logger logger = Logger.getLogger(Exec.class);
    public void execute(){
        //All of the JSch errors are now written to System.error stream
        ((ChannelExec) channel).setErrStream(System.err);

        //Instead of above line, how can I write these errors to logger
        logger.error(/*set error stream to this*/);
    }
}

How can I achieve this implementation?
 
-
Regards
Ravi



On Monday, 30 December 2013 7:56 AM, Viet H. Phan <***@yahoo.com> wrote:

Hi Ravi,

1) Create your own Logger class that implements com.jcraft.jsch.Logger and uses log4j
2) Apply your Logger using com.jcraft.jsch.JSch.setLogger(com.jcraft.jsch.Logger) method
Check Logger class of JSch example for reference.

Hope this helps.

Regards,
Viet




________________________________
From: Ravi Joshi <***@yahoo.com>
To: "jsch-***@lists.sourceforge.net" <jsch-***@lists.sourceforge.net>
Sent: Sunday, 29 December 2013 4:47 PM
Subject: [JSch-users] How to set ChannelExec error stream from System.err to log4j



Hi,

I want to execute a command to remote linux machine. I am referring Exec.java (http://www.jcraft.com/jsch/examples/Exec.java.html) example code.

I just wanted to know How to set ChannelExec error stream from System.err to log4j, so that all of these errors, I can get captured by log4j under error catagory.


-
Thanks
Ravi
Stanley Ipkiss
2013-12-30 20:15:58 UTC
Permalink
Ravi Joshi
2013-12-31 09:08:40 UTC
Permalink
Hi Stan,

Thank you for the suggestion but its not working. I modified the code which is Exec.java (An example code provided by Jsch) and finally it looks like below-

// ((ChannelExec) channel).setErrStream(System.err);
String errorStream = readStream(((ChannelExec) channel).getErrStream());
logger.error(errorStream);

Now the JSch is not working. I mean it is not returning anything. IMO, reading from a stream and setting a stream, both are different things. Isn't it? 

In the original code Exec.java (line no. 67), error stream is being set whereas in your suggestion, error stream is being read. At the same time, this error stream is being closed inside readStream() method, which is causing me to suspect over it. Should we close the error stream of JSch, I think it must be taken care by JSch.

To check the code, you can execute "java -version" command in any remote linux machine, which is written to System.error in original Exec.java

 -
Thanks
Ravi




On Tuesday, 31 December 2013 1:46 AM, Stanley Ipkiss <***@gmail.com> wrote:

Ravi,

I stole this from StackOverflow, haven't tested it, but it should
be fairly straightforward:
    

privateStringreadStream(InputStreamiStream)throwsIOException{//build a Stream Reader, it can read char by charInputStreamReaderiStreamReader =newInputStreamReader(iStream);//build a buffered Reader, so that i can read whole line at onceBufferedReaderbReader =newBufferedReader(iStreamReader);Stringline =null;StringBuilderbuilder =newStringBuilder();while((line =bReader.readLine())!=null){//Read till endbuilder.append(line);}bReader.close();//close all opened stuffiStreamReader.close();iStream.close();returnbuilder.toString();}
// Call the above routine with the error stream
String errorStream = readStream(channel.getErrStream());
// Log it with your preferred logger
logger.error(errorStream);

Many other threads on stack overflow related to this...

http://stackoverflow.com/questions/6902386/how-to-read-jsch-command-output

Stan


On 12/30/2013 8:59 AM, Ravi Joshi wrote:

Thanks Viet,
Post by Ravi Joshi
I got your idea and looked over the example code. However I am looking for any short solution for this. Basically the example code (http://www.jcraft.com/jsch/examples/Exec.java.html) line no 67 has following line-
((ChannelExec) channel).setErrStream(System.err);
Now I have a modified class of Exec.java which uses log4j logger like this-
import org.apache.log4j.Logger;
public class Exec{
    private static final Logger logger = Logger.getLogger(Exec.class);
    public void execute(){
        //All of the JSch errors are now written to System.error stream
        ((ChannelExec) channel).setErrStream(System.err);
        //Instead of above line, how can I write these errors to logger
        logger.error(/*set error stream to this*/);
    }
}
How can I achieve this implementation?
 
-
Regards
Ravi
Hi Ravi,
1) Create your own Logger class that implements com.jcraft.jsch.Logger and uses log4j
2) Apply your Logger using com.jcraft.jsch.JSch.setLogger(com.jcraft.jsch.Logger) method
Check Logger class of JSch example for reference.
Hope this helps.
Regards,
Viet
________________________________
Sent: Sunday, 29 December 2013 4:47 PM
Subject: [JSch-users] How to set ChannelExec error stream from System.err to log4j
Hi,
I want to execute a command to remote linux machine. I am referring Exec.java (http://www.jcraft.com/jsch/examples/Exec.java.html) example code.
I just wanted to know How to set ChannelExec error stream from System.err to log4j, so that all of these errors, I can get captured by log4j under error catagory.
-
Thanks
Ravi
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they
affect your business. Most IT
Post by Ravi Joshi
organizations don't have a clear picture
of how application performance
Post by Ravi Joshi
affects their revenue. With AppDynamics,
you get 100% visibility into your
Post by Ravi Joshi
Java,.NET, & PHP application. Start
your 15-day FREE TRIAL of AppDynamics Pro!
Post by Ravi Joshi
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
JSch-users mailing list
https://lists.sourceforge.net/lists/listinfo/jsch-users
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
Post by Ravi Joshi
_______________________________________________
JSch-users mailing list JSch-***@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jsch-users
Viet H. Phan
2013-12-31 03:29:17 UTC
Permalink
Hi Ravi,

Following please find a solution:
1) Create a class (Log4JOutputStream) that extends OutputStream. Implement write(...)methods of Log4JOutputStream in which you actually use log4j
2) Set a Log4JOutputStreaminstance to the ChannelExec channel

Hope this helps.

Regards,
Viet


________________________________
From: Ravi Joshi <***@yahoo.com>
To: Viet H. Phan <***@yahoo.com>; "jsch-***@lists.sourceforge.net" <jsch-***@lists.sourceforge.net>
Sent: Monday, 30 December 2013 11:59 PM
Subject: Re: [JSch-users] How to set ChannelExec error stream from System.err to log4j



Thanks Viet,

I got your idea and looked over the example code. However I am looking for any short solution for this. Basically the example code (http://www.jcraft.com/jsch/examples/Exec.java.html) line no 67 has following line-

((ChannelExec) channel).setErrStream(System.err);


Now I have a modified class of Exec.java which uses log4j logger like this-

import org.apache.log4j.Logger;

public class Exec{
    private static final Logger logger = Logger.getLogger(Exec.class);
    public void execute(){
        //All of the JSch errors are now written to System.error stream
        ((ChannelExec) channel).setErrStream(System.err);

        //Instead of above line, how can I write these errors to logger
        logger.error(/*set error stream to this*/);
    }
}

How can I achieve this implementation?
 
-
Regards
Ravi



On Monday, 30 December 2013 7:56 AM, Viet H. Phan <***@yahoo.com> wrote:

Hi Ravi,

1) Create your own Logger class that implements com.jcraft.jsch.Logger and uses log4j
2) Apply your Logger using com.jcraft.jsch.JSch.setLogger(com.jcraft.jsch.Logger) method
Check Logger class of JSch example for reference.

Hope this helps.

Regards,
Viet




________________________________
From: Ravi Joshi <***@yahoo.com>
To: "jsch-***@lists.sourceforge.net" <jsch-***@lists.sourceforge.net>
Sent: Sunday, 29 December 2013 4:47 PM
Subject: [JSch-users] How to set ChannelExec error stream from System.err to log4j



Hi,

I want to execute a command to remote linux machine. I am referring Exec.java (http://www.jcraft.com/jsch/examples/Exec.java.html) example code.

I just wanted to know How to set ChannelExec error stream from System.err to log4j, so that all of these errors, I can get captured by log4j under error catagory.


-
Thanks
Ravi
Ravi Joshi
2013-12-31 17:02:48 UTC
Permalink
Hi Viet,

Here we go-

import java.io.IOException;
import java.io.OutputStream;
import org.apache.log4j.Logger;

public class Log4JOutputStream extends OutputStream {
    private static final Logger logger = Logger.getLogger(Log4JOutputStream.class);
    final StringBuilder string = new StringBuilder();

    @Override
    public void write(int b) throws IOException {
    char current = (char) b;
    if (current == '\n') {
            logger.error(string.toString());
            // Reset it
            string.setLength(0);
        } else {
            string.append(current);
        }
    }
}


and the main class is 
((ChannelExec) channel).setErrStream(new Log4JOutputStream());


-
Thanks
Ravi




On Tuesday, 31 December 2013 8:59 AM, Viet H. Phan <***@yahoo.com> wrote:

Hi Ravi,

Following please find a solution:
1) Create a class (Log4JOutputStream) that extends OutputStream. Implement write(...)methods of Log4JOutputStream in which you actually use log4j
2) Set a Log4JOutputStreaminstance to the ChannelExec channel

Hope this helps.

Regards,
Viet


________________________________
From: Ravi Joshi <***@yahoo.com>
To: Viet H. Phan <***@yahoo.com>; "jsch-***@lists.sourceforge.net" <jsch-***@lists.sourceforge.net>
Sent: Monday, 30 December 2013 11:59 PM
Subject: Re: [JSch-users] How to set ChannelExec error stream from System.err to log4j



Thanks Viet,

I got your idea and looked over the example code. However I am looking for any short solution for this. Basically the example code (http://www.jcraft.com/jsch/examples/Exec.java.html) line no 67 has following line-

((ChannelExec) channel).setErrStream(System.err);


Now I have a modified class of Exec.java which uses log4j logger like this-

import org.apache.log4j.Logger;

public class Exec{
    private static final Logger logger = Logger.getLogger(Exec.class);
    public void execute(){
        //All of the JSch errors are now written to System.error stream
        ((ChannelExec) channel).setErrStream(System.err);

        //Instead of above line, how can I write these errors to logger
        logger.error(/*set error stream to this*/);
    }
}

How can I achieve this implementation?
 
-
Regards
Ravi



On Monday, 30 December 2013 7:56 AM, Viet H. Phan <***@yahoo.com> wrote:

Hi Ravi,

1) Create your own Logger class that implements com.jcraft.jsch.Logger and uses log4j
2) Apply your Logger using com.jcraft.jsch.JSch.setLogger(com.jcraft.jsch.Logger) method
Check Logger class of JSch example for reference.

Hope this helps.

Regards,
Viet




________________________________
From: Ravi Joshi <***@yahoo.com>
To: "jsch-***@lists.sourceforge.net" <jsch-***@lists.sourceforge.net>
Sent: Sunday, 29 December 2013 4:47 PM
Subject: [JSch-users] How to set ChannelExec error stream from System.err to log4j



Hi,

I want to execute a command to remote linux machine. I am referring Exec.java (http://www.jcraft.com/jsch/examples/Exec.java.html) example code.

I just wanted to know How to set ChannelExec error stream from System.err to log4j, so that all of these errors, I can get captured by log4j under error catagory.


-
Thanks
Ravi

unknown
1970-01-01 00:00:00 UTC
Permalink
This is a multi-part message in MIME format.
--------------060903030909030803070705
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Ravi,

I stole this from StackOverflow, haven't tested it, but it should be
fairly straightforward:

| private String readStream(InputStream iStream) throws IOException {
//build a Stream Reader, it can read char by char
InputStreamReader iStreamReader= new InputStreamReader(iStream);
//build a buffered Reader, so that i can read whole line at once
BufferedReader bReader= new BufferedReader(iStreamReader);
String line= null;
StringBuilder builder= new StringBuilder();
while((line= bReader.readLine()) != null) { //Read till end
builder.append(line);
}
bReader.close(); //close all opened stuff
iStreamReader.close();
iStream.close();
return builder.toString();
}|


// Call the above routine with the error stream
String errorStream = readStream(channel.getErrStream());
// Log it with your preferred logger
logger.error(errorStream);

Many other threads on stack overflow related to this...

http://stackoverflow.com/questions/6902386/how-to-read-jsch-command-output

Stan
Post by Ravi Joshi
Thanks Viet,
I got your idea and looked over the example code. However I am looking
for any short solution for this. Basically the example code
(http://www.jcraft.com/jsch/examples/Exec.java.html) line no 67 has
following line-
((ChannelExec) channel).setErrStream(System.err);
Now I have a modified class of Exec.java which uses log4j logger like
this-
import org.apache.log4j.Logger;
public class Exec{
private static final Logger logger = Logger.getLogger(Exec.class);
public void execute(){
//All of the JSch errors are now written to System.error stream
((ChannelExec) channel).setErrStream(System.err);
//Instead of above line, how can I write these errors to logger
logger.error(/*set error stream to this*/);
}
}
How can I achieve this implementation?
-
Regards
Ravi
On Monday, 30 December 2013 7:56 AM, Viet H. Phan
Hi Ravi,
1) Create your own Logger class that implements com.jcraft.jsch.Logger
and uses log4j
2) Apply your Logger using
com.jcraft.jsch.JSch.setLogger(com.jcraft.jsch.Logger) method
Check Logger class of JSch example for reference.
Hope this helps.
Regards,
Viet
------------------------------------------------------------------------
*Sent:* Sunday, 29 December 2013 4:47 PM
*Subject:* [JSch-users] How to set ChannelExec error stream from
System.err to log4j
Hi,
I want to execute a command to remote linux machine. I am referring
Exec.java <http://www.jcraft.com/jsch/examples/Exec.java>
(http://www.jcraft.com/jsch/examples/Exec.java.html) example code.
I just wanted to know How to set ChannelExec error stream from
System.err to log4j, so that all of these errors, I can get captured
by log4j under error catagory.
-
Thanks
Ravi
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into
your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of
AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
JSch-users mailing list
https://lists.sourceforge.net/lists/listinfo/jsch-users
------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
JSch-users mailing list
https://lists.sourceforge.net/lists/listinfo/jsch-users
--------------060903030909030803070705
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Ravi,<br>
<br>
I stole this from StackOverflow, haven't tested it, but it should
be fairly straightforward: <br>
&nbsp;&nbsp;&nbsp;&nbsp; <br>
<pre style="" class="lang-java prettyprint prettyprinted"><code><span class="pln"> </span><span class="kwd">private</span><span class="pln"> </span><span class="typ">String</span><span class="pln"> readStream</span><span class="pun">(</span><span class="typ">InputStream</span><span class="pln"> iStream</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">throws</span><span class="pln"> </span><span class="typ">IOException</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
</span><span class="com">//build a Stream Reader, it can read char by char</span><span class="pln">
</span><span class="typ">InputStreamReader</span><span class="pln"> iStreamReader </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">InputStreamReader</span><span class="pun">(</span><span class="pln">iStream</span><span class="pun">);</span><span class="pln">
</span><span class="com">//build a buffered Reader, so that i can read whole line at once</span><span class="pln">
</span><span class="typ">BufferedReader</span><span class="pln"> bReader </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">BufferedReader</span><span class="pun">(</span><span class="pln">iStreamReader</span><span class="pun">);</span><span class="pln">
</span><span class="typ">String</span><span class="pln"> line </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">;</span><span class="pln">
</span><span class="typ">StringBuilder</span><span class="pln"> builder </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">StringBuilder</span><span class="pun">();</span><span class="pln">
</span><span class="kwd">while</span><span class="pun">((</span><span class="pln">line </span><span class="pun">=</span><span class="pln"> bReader</span><span class="pun">.</span><span class="pln">readLine</span><span class="pun">())</span><span class="pln"> </span><span class="pun">!=</span><span class="pln"> </span><span class="kwd">null</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> </span><span class="com">//Read till end</span><span class="pln">
builder</span><span class="pun">.</span><span class="pln">append</span><span class="pun">(</span><span class="pln">line</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
bReader</span><span class="pun">.</span><span class="pln">close</span><span class="pun">();</span><span class="pln"> </span><span class="com">//close all opened stuff</span><span class="pln">
iStreamReader</span><span class="pun">.</span><span class="pln">close</span><span class="pun">();</span><span class="pln">
iStream</span><span class="pun">.</span><span class="pln">close</span><span class="pun">();</span><span class="pln">
</span><span class="kwd">return</span><span class="pln"> builder</span><span class="pun">.</span><span class="pln">toString</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span></code></pre>
<br>
// Call the above routine with the error stream<br>
String errorStream = readStream(channel.getErrStream()); <br>
// Log it with your preferred logger<br>
logger.error(errorStream);<br>
<br>
Many other threads on stack overflow related to this...<br>
<br>
<a class="moz-txt-link-freetext" href="http://stackoverflow.com/questions/6902386/how-to-read-jsch-command-output">http://stackoverflow.com/questions/6902386/how-to-read-jsch-command-output</a><br>
<br>
Stan<br>
<br>
<br>
On 12/30/2013 8:59 AM, Ravi Joshi wrote:<br>
</div>
<blockquote
cite="mid:***@web163002.mail.bf1.yahoo.com"
type="cite">
<div style="color:#000; background-color:#fff;
font-family:verdana, helvetica, sans-serif;font-size:10pt">
<div><span>Thanks Viet,</span></div>
<div style="color: rgb(0, 0, 0); font-size: 13px; font-family:
verdana, helvetica, sans-serif; background-color: transparent;
font-style: normal;"><span><br>
</span></div>
<div style="color: rgb(0, 0, 0); font-size: 13px; font-family:
verdana, helvetica, sans-serif; background-color: transparent;
font-style: normal;"><span>I got your idea and looked over the
example code. However I am looking for any short solution
for this. Basically the example code (</span><a
moz-do-not-send="true"
href="http://www.jcraft.com/jsch/examples/Exec.java.html"
style="font-size: 10pt;">http://www.jcraft.com/jsch/examples/Exec.java.html</a>)
line no 67 has following line-</div>
<div style="color: rgb(0, 0, 0); font-size: 13px; font-family:
verdana, helvetica, sans-serif; background-color: transparent;
font-style: normal;"><br>
</div>
<div style="background-color: transparent;"><span
class="Apple-tab-span" style="white-space: pre;"> </span>((ChannelExec)
channel).setErrStream(System.err);<br>
</div>
<div style="background-color: transparent; color: rgb(0, 0, 0);
font-size: 13px; font-family: verdana, helvetica, sans-serif;
font-style: normal;"><br>
</div>
<div style="background-color: transparent; color: rgb(0, 0, 0);
font-size: 13px; font-family: verdana, helvetica, sans-serif;
font-style: normal;">Now I have a modified class of Exec.java
which uses log4j logger like this-</div>
<div style="background-color: transparent; color: rgb(0, 0, 0);
font-size: 13px; font-family: verdana, helvetica, sans-serif;
font-style: normal;"><br>
</div>
<div style="background-color: transparent;">import
org.apache.log4j.Logger;</div>
<div style="background-color: transparent;"><br>
</div>
<div style="background-color: transparent;">public class Exec{</div>
<div style="background-color: transparent;">&nbsp; &nbsp; private static
final Logger logger = Logger.getLogger(Exec.class);</div>
<div style="background-color: transparent;">&nbsp; &nbsp; public void
execute(){</div>
<div style="background-color: transparent;">&nbsp; &nbsp; &nbsp; &nbsp; //All of the
JSch errors are now written to System.error stream</div>
<div style="background-color: transparent;">&nbsp; &nbsp; &nbsp; &nbsp;
((ChannelExec) channel).setErrStream(System.err);</div>
<div style="background-color: transparent;"><br>
</div>
<div style="background-color: transparent;">&nbsp; &nbsp; &nbsp; &nbsp; //Instead of
above line, how can I write these errors to logger</div>
<div style="background-color: transparent;">&nbsp; &nbsp; &nbsp; &nbsp;
logger.error(/*set error stream to this*/);</div>
<div style="background-color: transparent;">&nbsp; &nbsp; }</div>
<div style="background-color: transparent;">}</div>
<div><br>
</div>
<div>How can I achieve this implementation?</div>
<div>&nbsp;</div>
<div>-</div>
<div>Regards</div>
<div>Ravi</div>
<div class="yahoo_quoted" style="display: block;"> <br>
<br>
<div style="font-family: verdana, helvetica, sans-serif;
font-size: 10pt;">
<div style="font-family: 'times new roman', 'new york',
times, serif; font-size: 12pt;">
<div dir="ltr"> <font face="Arial" size="2"> On Monday,
30 December 2013 7:56 AM, Viet H. Phan <a class="moz-txt-link-rfc2396E" href="mailto:***@yahoo.com">&lt;***@yahoo.com&gt;</a> wrote:<br>
</font> </div>
<div class="y_msg_container">
<div id="yiv3069917843">
<div>
<div style="color: rgb(0, 0, 0); background-color:
rgb(255, 255, 255); font-family: 'times new
roman', 'new york', times, serif; font-size:
12pt;">
<div><span style="font-size:13px;">Hi Ravi,</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="font-size:small;"><br clear="none">
</span></div>
<div style="background-color:transparent;"><span
style="font-size:small;">1)&nbsp;Create&nbsp;your own
Logger class that
implements&nbsp;com.jcraft.jsch.Logger and uses
log4j</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="font-size:small;"><span>2) Apply your
Logger using com.jcraft.jsch.JSch.setLogger(</span><span>com.jcraft.jsch.Logger</span><span
style="background-color:transparent;">)
method</span></span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="background-color:transparent;font-size:small;">Check
Logger class of JSch example for reference.</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="background-color:transparent;font-size:small;"><br
clear="none">
</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="background-color:transparent;font-size:small;">Hope
this helps.</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="background-color:transparent;font-size:small;"><br
clear="none">
</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="background-color:transparent;font-size:small;">Regards,</span></div>
<div style="font-family: 'times new roman', 'new
york', times, serif; background-color:
transparent; font-style: normal;"><span
style="background-color:transparent;font-size:small;">Viet</span></div>
<div style="color: rgb(0, 0, 0); font-size: 16px;
font-family: 'times new roman', 'new york',
times, serif; background-color: transparent;
font-style: normal;"><span><br clear="none">
</span></div>
<div style="color: rgb(0, 0, 0); font-size: 16px;
font-family: 'times new roman', 'new york',
times, serif; background-color: transparent;
font-style: normal;"><span><br clear="none">
</span></div>
<div><br clear="none">
</div>
<div style="font-family: 'times new roman', 'new
york', times, serif; font-size: 12pt;">
<div style="font-family: 'times new roman', 'new
york', times, serif; font-size: 12pt;">
<div class="yiv3069917843yqt3584844522"
id="yiv3069917843yqt49455">
<div dir="ltr">
<hr size="1"> <font face="Arial" size="2">
<b><span style="font-weight:bold;">From:</span></b>
Ravi Joshi <a class="moz-txt-link-rfc2396E" href="mailto:***@yahoo.com">&lt;***@yahoo.com&gt;</a><br
clear="none"> <b><span style="font-weight:bold;">To:</span></b> <a class="moz-txt-link-rfc2396E" href="mailto:jsch-***@lists.sourceforge.net">"jsch-***@lists.sourceforge.net"</a> <a class="moz-txt-link-rfc2396E" href="mailto:jsch-***@lists.sourceforge.net">&lt;jsch-***@lists.sourceforge.net&gt;</a>
<br clear="none">
<b><span style="font-weight:bold;">Sent:</span></b>
Sunday, 29 December 2013 4:47 PM<br
clear="none">
<b><span style="font-weight:bold;">Subject:</span></b>
[JSch-users] How to set ChannelExec
error stream from System.err to log4j<br
clear="none">
</font> </div>
<div class="yiv3069917843y_msg_container"><br
clear="none">
<div id="yiv3069917843">
<div>
<div style="color: rgb(0, 0, 0);
background-color: rgb(255, 255,
255); font-family: verdana,
helvetica, sans-serif; font-size:
10pt;">
<div><span>Hi,</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span><br
clear="none">
</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span>I want
to execute a command to remote
linux machine. I am referring&nbsp;</span><a
moz-do-not-send="true"
rel="nofollow" shape="rect"
target="_blank"
href="http://www.jcraft.com/jsch/examples/Exec.java"
style="background-color:
rgb(255, 255, 255); color:
rgb(88, 167, 70);
text-decoration: none;
font-weight: bolder;
font-family: arial, helvetica,
sans-serif; font-size: 14px;
line-height: 18px;">Exec.java</a>&nbsp;<span
style="background-color:transparent;">(</span><a moz-do-not-send="true"
rel="nofollow" shape="rect"
target="_blank"
href="http://www.jcraft.com/jsch/examples/Exec.java.html"
style="font-size:10pt;">http://www.jcraft.com/jsch/examples/Exec.java.html</a><span
style="background-color:transparent;">) example code.</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;"><br
clear="none">
</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;">I
just wanted to know&nbsp;How to set
ChannelExec error stream from
System.err to log4j, so that all
of these errors, I can get
captured by log4j under error
catagory.</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;"><br
clear="none">
</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;"><br
clear="none">
</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;">-</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;">Thanks</span></div>
<div style="color: rgb(0, 0, 0);
font-size: 13px; font-family:
verdana, helvetica, sans-serif;
background-color: transparent;
font-style: normal;"><span
style="background-color:transparent;">Ravi</span></div>
<div><br clear="none">
</div>
</div>
</div>
</div>
<br clear="none">
------------------------------------------------------------------------------<br
clear="none">
Rapidly troubleshoot problems before they
affect your business. Most IT <br
clear="none">
organizations don't have a clear picture
of how application performance <br
clear="none">
affects their revenue. With AppDynamics,
you get 100% visibility into your <br
clear="none">
Java,.NET, &amp; PHP application. Start
your 15-day FREE TRIAL of AppDynamics Pro!<br
clear="none">
<a moz-do-not-send="true" rel="nofollow"
shape="rect" target="_blank"
href="http://pubads.g.doubleclick.net/gampad/clk?id=84349831&amp;iu=/4140/ostg.clktrk">http://pubads.g.doubleclick.net/gampad/clk?id=84349831&amp;iu=/4140/ostg.clktrk</a><br
clear="none">
_______________________________________________<br clear="none">
JSch-users mailing list<br clear="none">
<a moz-do-not-send="true" rel="nofollow"
shape="rect"
ymailto="mailto:JSch-***@lists.sourceforge.net"
target="_blank"
href="mailto:JSch-***@lists.sourceforge.net">JSch-***@lists.sourceforge.net</a><br
clear="none">
<a moz-do-not-send="true" rel="nofollow"
shape="rect" target="_blank"
href="https://lists.sourceforge.net/lists/listinfo/jsch-users">https://lists.sourceforge.net/lists/listinfo/jsch-users</a><br
clear="none">
<br clear="none">
<br clear="none">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<br>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT
organizations don't have a clear picture of how application performance
affects their revenue. With AppDynamics, you get 100% visibility into your
Java,.NET, &amp; PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
<a class="moz-txt-link-freetext" href="http://pubads.g.doubleclick.net/gampad/clk?id=84349831&amp;iu=/4140/ostg.clktrk">http://pubads.g.doubleclick.net/gampad/clk?id=84349831&amp;iu=/4140/ostg.clktrk</a></pre>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
JSch-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:JSch-***@lists.sourceforge.net">JSch-***@lists.sourceforge.net</a>
<a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/jsch-users">https://lists.sourceforge.net/lists/listinfo/jsch-users</a>
</pre>
</blockquote>
<br>
</body>
</html>

--------------060903030909030803070705--
Loading...