bozer
asked on
Logging with PrintStream in Java
Hello experts,
We are trying to understand how PrintStream works when used for logging. There are several examples over the internet but we need to understand how that writes data in a text file. Here is the example:
ps = new PrintStream(fos);
ps.print(midLog+"/"+data1+ "\r\n");
ps.close();
Let's say we have that piece of logging in a web application and that application is used frequently, how will it work? Does it open and close the text file every time the example code is repeated?
Thanks
We are trying to understand how PrintStream works when used for logging. There are several examples over the internet but we need to understand how that writes data in a text file. Here is the example:
ps = new PrintStream(fos);
ps.print(midLog+"/"+data1+
ps.close();
Let's say we have that piece of logging in a web application and that application is used frequently, how will it work? Does it open and close the text file every time the example code is repeated?
Thanks
ASKER
Thank you,
So 'close' method is not a real 'close' in that sense. So how do we destroy that object? (Printstream) And if that does not gets destroyed, what are the consequences?
So 'close' method is not a real 'close' in that sense. So how do we destroy that object? (Printstream) And if that does not gets destroyed, what are the consequences?
no close() *is* a real close.
ASKER
Can you please give more information? It's not an actual 'open' and append of a text file but 'close' closes the file?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
that code appears to
to avoid that keep a reference to the PrintStream and don't close it
though why not use a logging framework