|
|
|
|
||||||
| comp.unix.shell Using and programming the Unix shell. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I am maintaining a Java application that consist of a lot of code
using exception.printstacktrace() to print exception messages to standard error stream. I am not allowed to update the code to make it log properly. Then I try to start my application using script like java -cp xxx MainClass > log.txt 2&>1 & so that the exception message will be logged. However, we found out that the exception message is not logged. Is there any problem about this approach? How can I log the standard error stream? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfield@gmail.com>
wrote: >I am maintaining a Java application that consist of a lot of code >using exception.printstacktrace() to print exception messages to >standard error stream. I am not allowed to update the code to make it >log properly. > >Then I try to start my application using script like java -cp xxx >MainClass > log.txt 2&>1 & so that the exception message will be >logged. However, we found out that the exception message is not >logged. Is there any problem about this approach? How can I log the >standard error stream? .... 2>&1 Scott McMillan |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfield@gmail.com>
wrote: >I am maintaining a Java application that consist of a lot of code >using exception.printstacktrace() to print exception messages to >standard error stream. I am not allowed to update the code to make it >log properly. > >Then I try to start my application using script like java -cp xxx >MainClass > log.txt 2&>1 & so that the exception message will be >logged. However, we found out that the exception message is not >logged. Is there any problem about this approach? How can I log the >standard error stream? .... 2>&1 Scott McMillan |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On Aug 27, 2:23 pm, Carfield Yim <carfi...@gmail.com> wrote:
> I am maintaining a Java application that consist of a lot of code > using exception.printstacktrace() to print exception messages to > standard error stream. I am not allowed to update the code to make it > log properly. It shouldn't necessarily take a code update to make your stderr exception messages into a "proper" log. Rather, you just have to adjust the script that launches the process, so as to pipe stderr into a suitable logging tool. > Then I try to start my application using script like > java -cp xxx MainClass > log.txt 2&>1 & > so that the exception message will be > logged. However, we found out that the exception message is not > logged. As others have pointed out, you have a typo that causes stderr not to be written to your "log.txt" file. The typo has two other side effects: 1) your java command is given the additional extraneous argument "2", and 2) you inadvertantly create a file called "1" in the cwd of the process that launched the java command First off, do you understand why these side effects happened? Do you understand what the correction to your typo does? > Is there any problem about this approach? How can I log the > standard error stream? Any number of ways: java -cp xxx MainClass > log.txt 2>&1 & or java -cp xxx MainClass > log.txt 2>stderror.log.txt & or even some java -cp xxx MainClass 2>&1 >log.txt | logger & (which will send stdout to your log text file, and stderr to the old stdout destination to be piped into logger(1) which (with suitable arguments) will log the text to the syslog) HTH -- Lew |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Aug 27, 2:23 pm, Carfield Yim <carfi...@gmail.com> wrote:
> I am maintaining a Java application that consist of a lot of code > using exception.printstacktrace() to print exception messages to > standard error stream. I am not allowed to update the code to make it > log properly. It shouldn't necessarily take a code update to make your stderr exception messages into a "proper" log. Rather, you just have to adjust the script that launches the process, so as to pipe stderr into a suitable logging tool. > Then I try to start my application using script like > java -cp xxx MainClass > log.txt 2&>1 & > so that the exception message will be > logged. However, we found out that the exception message is not > logged. As others have pointed out, you have a typo that causes stderr not to be written to your "log.txt" file. The typo has two other side effects: 1) your java command is given the additional extraneous argument "2", and 2) you inadvertantly create a file called "1" in the cwd of the process that launched the java command First off, do you understand why these side effects happened? Do you understand what the correction to your typo does? > Is there any problem about this approach? How can I log the > standard error stream? Any number of ways: java -cp xxx MainClass > log.txt 2>&1 & or java -cp xxx MainClass > log.txt 2>stderror.log.txt & or even some java -cp xxx MainClass 2>&1 >log.txt | logger & (which will send stdout to your log text file, and stderr to the old stdout destination to be piped into logger(1) which (with suitable arguments) will log the text to the syslog) HTH -- Lew |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
On 8 28 , 2 43 , Scott McMillan <smcmil...@twmi.rr.com> wrote:
> On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfi...@gmail.com> > wrote: > > >I am maintaining a Java application that consist of a lot of code > >using exception.printstacktrace() to print exception messages to > >standard error stream. I am not allowed to update the code to make it > >log properly. > > >Then I try to start my application using script like java -cp xxx > >MainClass > log.txt 2&>1 & so that the exception message will be > >logged. However, we found out that the exception message is not > >logged. Is there any problem about this approach? How can I log the > >standard error stream? > > ... 2>&1 > > Scott McMillan Typo, it is 2>&1 already |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 8 28 , 2 43 , Scott McMillan <smcmil...@twmi.rr.com> wrote:
> On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfi...@gmail.com> > wrote: > > >I am maintaining a Java application that consist of a lot of code > >using exception.printstacktrace() to print exception messages to > >standard error stream. I am not allowed to update the code to make it > >log properly. > > >Then I try to start my application using script like java -cp xxx > >MainClass > log.txt 2&>1 & so that the exception message will be > >logged. However, we found out that the exception message is not > >logged. Is there any problem about this approach? How can I log the > >standard error stream? > > ... 2>&1 > > Scott McMillan Typo, it is 2>&1 already |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
In article <1188271999.589148.109090@q4g2000prc.googlegroups. com>,
Carfield Yim <carfield@gmail.com> wrote: > On 8 28 , 2 43 , Scott McMillan <smcmil...@twmi.rr.com> wrote: > > On Mon, 27 Aug 2007 18:23:17 -0000, Carfield Yim <carfi...@gmail.com> > > wrote: > > > > >I am maintaining a Java application that consist of a lot of code > > >using exception.printstacktrace() to print exception messages to > > >standard error stream. I am not allowed to update the code to make it > > >log properly. > > > > >Then I try to start my application using script like java -cp xxx > > >MainClass > log.txt 2&>1 & so that the exception message will be > > >logged. However, we found out that the exception message is not > > >logged. Is there any problem about this approach? How can I log the > > >standard error stream? > > > > ... 2>&1 > > > > Scott McMillan > > Typo, it is 2>&1 already Are you sure that exception.printstacktrace() writes to stderr? Maybe it writes to /dev/tty. Perhaps you should ask in a Java newsgroup. Are you sure your command line ended with '>log.txt 2>&1'? If you put these in the wrong order, i.e. '2>&1 >log.txt' then it won't do what you want. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** |
|
![]() |
| Outils de la discussion | |
|
|