I have a faint idea of what the question is about, can you explain more
A reader, August 25, 2001 - 2:57 pm UTC
Tom
Can you briefly explain what all you are doing in the
explanation in the given link.
Where are you getting the buffer output from an another session in the given link.
If possible can you discuss that again.
August 25, 2001 - 7:44 pm UTC
Sorry, I clarified the answer above -- it was a little vague previously.
H
ray, September 21, 2001 - 1:22 am UTC
How can we use the debug.f program a procedure to debug it.
September 21, 2001 - 8:51 am UTC
ummm, by adding lots of calls to debug.f to generate a trace file you can read to see what your program is doing. It is just a facility to allow you to generate a log file easily.
how can I be sure that debug.f is working
ray, September 25, 2001 - 5:47 pm UTC
i tested it , but got no output
SQL> set serveroutput on
SQL> execute debug.f('sdfsdfsdfsdfsdfsdf');
PL/SQL procedure successfully completed.
September 25, 2001 - 7:47 pm UTC
umm, debug.f (our utility to be found at the above URL) doesn't write to the screen. It writes to a file -- and only after calling debug.init and setting up your utl_file_dir init.ora parameter.
The spec of the debug package, which you should read, has all of the details -- repeated here:
-- PACKAGE TO DUMP DEBUG INFORMATION OF PL/SQL ROUTINE
-- TO A FILE DURING EXECUTION
--
--
-- This package allows the developer to selectively produce debug
-- iformation for pl/sql process.
--
-- Setup:
-- Make sure the utl_file_dir paramter is assigned in the init.ora
-- file. You need an entry for each dir that you want to be able to
-- write to.
-- eg.
-- utl_file_dir = /tmp
-- utl_file_dir = /home/clbeck/sql/debug
--
-- Usage:
-- There are two procedure to write debug information ( f and fa ).
-- Anywhere in your code that you want to print debug information use:
--
-- debug.f( 'Expected %s bytes, got %s bytes', l_expect, l_got );
--
-- This will replace the the first %s with the value of l_expect and the
-- second %s with the value of l_got.
--
-- If you have more than 10 %s in your string then you will need to use the fa
-- procedure like:
--
-- debug.fa( 'List: %s,%s,%s,%s,%s,%s',
-- argv( 1, 2, l_num, 'Chris', l_cnt, 10 ) );
--
-- Runtime:
-- To enable the debug run:
--
-- debug.init( 'myProc' );
--
-- This will cause only debug for the procedure/package named
-- myProc to be generated.
-- All other debug statements will generate no output.
-- To debug all procedures/packages,
-- set p_modules = 'ALL';
--
-- To stop debug run:
--
-- debug.clear;
--
-- Output:
-- The output looks like:
--
-- 981013 130530 (CLBECK.MYPROC, 221) this is my debug output
-- ^^^^^^ ^^^^^^ ^^^^^^^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-- date time owner.proc lineno message
--
--
-- Enhancements and Bugs:
--
-- Send all enhancements requests and bugs to me,
-- Christopher Beck (clbeck@us.oracle.com)
--
read through the code as well -- its pretty straightforward.
We are doing too much of work with debug.f , whey cant we
A reader, September 26, 2001 - 3:29 pm UTC
just create a table with a varchar2 columns, and keep updating it with all the debug info, isnt this much more easy.
Tom, why should I use debug.f , when I can do the above.
What are the advantages of debug.f over the method I suggested above
September 26, 2001 - 4:27 pm UTC
You need to use autonomous transactions with your method (so you can commit, so another session can see it)
with debug.f -- I can "tail -f filename" and watch the stuff in "real time" -- it scrolls by on my screen without me having to query it.
I put debug.f in my code that others use so I can tell them to generate a trace file and mail it to me. Don't have to teach them how to run it, query it, spool it, etc. Its just in a file.
You can use a table, sure. It is just nice to use a file sometimes. That is where I prefer to put my traces.
DBA
Robert Wood, May 09, 2002 - 2:49 pm UTC
Hi Tom,
You have talked a lot about the debug.f module, but you have never showed us the code for it!
Can you show us the code?
Thanks!
Robert.
May 09, 2002 - 7:48 pm UTC
follow the link in the answer. download the script. it is in there.
Code for debug package
raju, January 18, 2003 - 1:32 pm UTC
Hi Tom,
I just downloaded the code samples from the wrox website as I wanted to get the debug package as mentioned in your book on page 955. I couldn't find the code for this package in the Zip file or maybe I don't know the right file name.
However, I can access the code for the package at the above link.
If the code is there in the zip file downloaded from the wrox site then please let me know the file name. Maybe, this info might help others as well.
Thanks
January 18, 2003 - 1:40 pm UTC
Use the download for "Beginning Oracle Programing" not Expert one on one. It has the "latest release" with the best implementation.
That book goes into big detail on how to use it as well.
Changing the debug package
Pratap, February 25, 2003 - 12:37 am UTC
Hi Tom
I was thinking of adding a debug_level in the package.
The debug_level can be passed to the f procedure and decided by the programmer. Do you think this will help.
E.g. -
Level 1 - Debug at entry and exit of procedures - Maybe to get elapsed time for each procedure
Level 2 - Non-Repetitive code and main information
Level 3 - Repetitive code, like inside a loop or more detailed information
The debugging can be turned on for any level. This might help in reducing the unwanted information in the trace file.
My concern is the debugging of batch processes which would process huge amount of data.
Thanks
Pratap
Other suggested enhancement
Matt, June 19, 2003 - 10:08 pm UTC
Regarding the previous post.
How about defining a PL/SQL daemon that will manage printing out the debug? In this way you could change the debug level at run time by sending a message to the daemon.
Imagine you have a process running that is taking a long while you could increase the debug level dynamically to increase the amount of debug sent to the file. You can then work out whay is taking so long.
If you implement any of these enhancements, why don't you post the results here?
Cheers,
A reader, August 15, 2003 - 3:39 pm UTC
debug.f
A reader, August 20, 2003 - 12:44 pm UTC
at </code>
http://asktom.oracle.com/~tkyte/article2/index.html#Errors <code>
has compile errors. You need to change the following line
in procedure init (in the body)
from
p_modules in varchar2 default 'all',
to
p_modules in varchar2 default 'ALL',
for it to compile.
Haven'te tested it - it is possible that we need
the procedure spec's default value from 'ALL' to 'all'
instead.
Please keep up the awesome work!
Thanx!
August 21, 2003 - 4:59 pm UTC
thanks!
DEBUG.f is great but...
Robert Boyle, October 21, 2003 - 5:45 am UTC
...what if you are looking to get debug information from a front end process as it happens from the front end (ie on a web application). How can you invoke DEBUG.init from there? Would you have it built into your JSP code say, and if you switch on debugging you would invoke DEBUG.init before executing the procedure call?
Currently I just log to a table depdending on whether debug is on or off, I am looking to create an advanced version of this with different debug levels but was having looked at DEBUG.f was wondering if I would be better going with that.
Cheers
Robert.
October 21, 2003 - 7:50 am UTC
when I wrote a palm sync program in java -- i used debug.f and just had the java code call debug.init and debug.f whenever. that way my plsql, java everything went into the database.
its what I used there -- especially since the java clients where all over the place (on the desktops).
In your case, you have to decide if you want to use 2 techniques (debug.f in plsql, maybe log4j in java) or just one -- up to you.
Debug.f is good stuff
Dave, July 22, 2004 - 3:51 pm UTC
Hi -
In case anyone is interested, I created a small server-side java class that uses debug.f .. I used it to debug some java stored procs. This way, all of my debug info (pl/sql and java sps) would go to the same debug file...No promises on code quality, I just used it temporarily.
Dave
--------------------------------------
set define off
create or replace and compile
java source named "RUtl_Debug"
as
import java.sql.*;
import oracle.jdbc.*;
import java.io.*;
public final class RUtl_Debug
{
private static boolean m_connected;
private static Connection conn;
private static CallableStatement cstmt;
private static final String sql = "{CALL DEBUG.f(?)}";
public static void f (String msg) throws Exception
{
if ( !m_connected )
connect();
cstmt.setString(1, msg);
cstmt.executeUpdate();
}
public static void f (Exception e) throws Exception
{
f(e.toString());
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
pw.close();
f(sw.toString());
}
private static void connect() throws Exception
{
try
{
conn = DriverManager.getConnection("jdbc:default:connection:");
cstmt = conn.prepareCall(sql);
m_connected = true;
}
catch (Exception e)
{
try
{
if ( conn != null ) conn.close();
throw e;
}
catch (SQLException ex) { throw e; }
}
}
public void finalize()
{
try
{
conn.close();
}
catch (SQLException ignore) {}
}
}
/
show errors
Using debug.f efficiently in production
Mathew Butler, September 12, 2006 - 10:24 am UTC
I've just been going through the debug package as published in Mastering Oracle PL/SQL Practical Solutions ( Chris Beck et al. ). What concerns me is the described workaround that the book describes for avoiding the overhead of having the debug.f and debug.fa calls included in production code. The authors suggest just re-compiling these package with a "return" being the first line of these routines. As such this avoids any code execution overhead ( and a select to the debugtab table to work out what should be debugged ). I don't like this as it means that I am less likely to be able to remotely debug my code - there is more involved and the people involved need to have more privileges.
I had considered attempting to cache the driving data ( debugtab ) which defines the attributes of the debug ( who, what, how ). I then have the problem of how to keep the package state in sync with the table contents. Further though, as someone may well want to debug another running session other than their own I need to be able to initiate a package state refresh from a different session.
This leaves me with the following options;
a) leave the code as is in production
b) come up with a mechanism for refreshing a package state in someone elses session
c) wait until 10G and use some conditional compilation flags
Is there anyway that I can achieve b) on 9.2? How about 10G?
I have looked as dbms_session.reset_package, but this clears the package state for all packages and does not achieve b).
Do you have any thoughts on how this might be achieved?
Regards,
September 12, 2006 - 11:03 am UTC
then do what I do.
leave it in, forever, for always, for it is what you want.
I don't compile it out, I just leave it in there and it becomes part of the processing of my code, forever and ever.
I refuse to think of it as overhead.
I think of the code I have to write for end users as overhead - the debug stuff, that is what I put there for myself.
You could have debug be "more efficient" by only check the debug tab every N calls or something if you like.
I agree
Mathew Butler, September 12, 2006 - 1:00 pm UTC
I totally agree with you that this stuff should just stay put. I don't even like the 10G option. I'm more concerned to make sure that the code I leave in is efficient.
So, options other than to reduce the number checks against the table then? I might give that a whirl.
THanks,
Debug code in database package or Java.
Dave Fowler, September 12, 2006 - 4:54 pm UTC
Debug logic absolutely needed, for dev, and finding problems quick once in production.
If you can't create files on oracle server with utl_file
Use a log table have a plsql procedure make autonomous_transaction calls to fill it with debug info.
Just call this package procedure for debugging anything.
Have a cleanup procedure to run weekly to remove old debug table data thru dbms_job.
Broken Link
djb, December 06, 2006 - 10:38 am UTC
Tom, the link above to the debug package is broken. Do you have an updated link?
December 07, 2006 - 8:39 am UTC
The link is still broken
A reader, March 19, 2010 - 8:26 am UTC
The Link is still broken
Eddie, April 28, 2011 - 7:34 am UTC
Tom,
Please upload it again for an admirer’s sake.
April 28, 2011 - 7:58 am UTC
debug.f rocks
Dana, April 28, 2011 - 8:48 pm UTC
I've used debug.f in several projects and package code over the years. It is absolutely indispensable. And the overhead is nothing compared to the value add. Especially when you're still developing and refining. The only drawback I see is developers don't use it when I have to look at their code!
Dead link
John, September 24, 2018 - 7:25 pm UTC
September 26, 2018 - 12:49 am UTC
Thanks for letting us know - we'll update the question to point a newer tool Logger.