|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Adding
Custom Messages to the Oracle alert log In
Oracle, all major system messages are written to the Oracle alert log.
In order to create
a single place for all Oracle system messages, the Oracle professional
must develop a method for writing application messages into the alert log
file. By
consolidating all Oracle messages (both system messages and application
messages) database administration is greatly simplified because a central
file exists for all Oracle-related alert messages. The
Oracle DBA can create a global PL/SQL stored procedure handle this
interaction with the alert log file, and the global package can be called,
passing the appropriate message to the procedure.
Here is an example of this type of call: when
others then
dbms_custom.write_alert(:p_sysdate||‘ Application error’||:var1||’
encountered’); This
easy writing to the alert log is accomplished by using Oracle’s utl_file
package. The utl_file package allows Oracle SQL and PL/SQL to read
and write directly from flat files on the server. Writing
custom messages to the Oracle alert log requires the following steps:
Here
is a code example for Oracle9i that illustrates the process: -- ****************************************************** -- Gather the location of the alert log directory -- ****************************************************** select name into :alert_loc from v$parameter where name = ‘background_dump_destination’; -- ****************************************************** -- Set the utl_file_dir -- (prior to Oracle9i, you must bounce the database) -- ****************************************************** alter system set utl_file_dir = ‘:alert_log’); -- ****************************************************** -- Open the alert log file for write access -- ******************************************************
utl_file.fopen(':alert_loc',’alertprod.log’,'W'); -- ****************************************************** -- Write the custom message to the alert log file -- ****************************************************** dbms_output.put_line('invalid_application_error'); -- ****************************************************** -- Close the alert log file -- ****************************************************** utl_file.fclose(':alert_loc'); If
you like Oracle tuning, you might enjoy my latest book “Oracle Tuning: The DefinitiveReference” by Rampant TechPress. (I don’t think it is right to charge a fortune for books!) and you
can buy it right now at this link:
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||