Writing debug messages into an external (.txt) file using utl_file package.
465930Feb 26 2006 — edited Feb 27 2006Hi All,
I basically want to write debug messages into an external (.txt) file.
So I am using the utl_file package for that purpose.
Here is the procedure I am using to write the debug messages.
create or replace procedure debugfile(str varchar2) as
f1 utl_file.file_type;
begin
f1 := utl_file.fopen('\tmp', 'debug.txt', 'W');
utl_file.put_line(f1, string);
utl_file.fclose(f1);
end;
And here is the sample code where I am calling this procedure.
declare
a number;
b number;
c number;
begin
a := 10;
debugfile('a = '||a); --calling the debugfile procedure to wirte the debug message.
b := 20;
debugfile('b = '||b); --calling the debugfile procedure to wirte the debug message.
c := a + b;
debugfile('c = '||c); --calling the debugfile procedure to wirte the debug message.
end;
Now whats happening is that only the last message is being written into the file.
That is because every time the procedure is being called, the file gets rewritten and the
previous messages are getting overwritten.
So how do I get all the 3 messages in the above piece of code into a single file.
I may have hundreds of messages in my code. How do I write all of them into a single file.
Can anyone please help me in this regard.
Thanks in advance.
Vijay.