Link to home
Start Free TrialLog in
Avatar of bozer
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
Avatar of Mick Barry
Mick Barry
Flag of Australia image

> Does it open and close the text file every time the example code is repeated?

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
Avatar of bozer
bozer

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?
no close() *is* a real close.
Avatar of bozer

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
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bozer

ASKER

Thanks