CREATE OR REPLACE PACKAGE PLOG IS
/**
* package name : PLOG
*<br/>
*<br/>
*See : <a href="http://log4plsql.sourceforge.net">http://log4plsql.sourceforge.net</a>
*<br/>
*<br/>
*Objectif : Generic tool of log in a Oracle database
*same prototype and functionality that log4j.
*<a href="http://jakarta.apache.org/log4j">http://jakarta.apache.org/log4j </a>
*<br/><br/><br/>
*<b> for exemple and documentation See: http://log4plsql.sourceforge.net/docs/UserGuide.html</b>
*
* Default table of log level
* 1 The OFF has the highest possible rank and is intended to turn off logging. <BR/>
* 2 The FATAL level designates very severe error events that will presumably lead the application to abort.<BR/>
* 3 The ERROR level designates error events that might still allow the application to continue running.<BR/>
* 4 The WARN level designates potentially harmful situations.<BR/>
* 5 The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.<BR/>
* 6 The DEBUG Level designates fine-grained informational events that are most useful to debug an application.<BR/>
* 7 The ALL has the lowest possible rank and is intended to turn on all logging.<BR/>
*
*
*<br/><br/><br/><br/>
*All data is store in TLOG table<br/>
* ID number,<br/>
* LDate DATE default sysdate,<br/>
* LHSECS number,<br/>
* LLEVEL number,<br/>
* LSECTION varchar2(2000),<br/>
* LTEXTE varchar2(2000),<br/>
* LUSER VARCHAR2(30),<br/>
* CONSTRAINT pk_TLOG PRIMARY KEY (id)<br/>
*<br/><br/><br/>
*
*
*headcom
*<br/>
*<br/>
*<br/>
*History who date comment
*V0 Guillaume Moulard 08-AVR-98 Creation
*V1 Guillaume Moulard 16-AVR-02 Add DBMS_PIPE funtionnality
*V1.1 Guillaume Moulard 16-AVR-02 Increase a date log precision for bench user hundredths of seconds of V$TIMER
*V2.0 Guillaume Moulard 07-MAY-02 Extend call prototype for more by add a default value
*V2.1 Guillaume Moulard 07-MAY-02 optimisation for purge process
*V2.1.1 Guillaume Moulard 22-NOV-02 patch bug length message identify by Lu Cheng
*V2.2 Guillaume Moulard 23-APR-03 use automuns_transaction use Dan Catalin proposition
*V2.3 Guillaume Moulard 30-APR-03 Add is[Debug|Info|Warn|Error]Enabled requested by Dan Catalin
*V2.3.1 jan-pieter 27-JUN-03 supp to_char(to_char line ( line 219 )
*V3 Guillaume Moulard 05-AUG-03 *update default value of PLOGPARAM.DEFAULT_LEVEL -> DEBUG
* *new: log in alert.log, trace file (thank to andreAs for information)
* *new: log with DBMS_OUTPUT (Wait -> SET SERVEROUTPUT ON)
* *new: log full_call_stack
* *upd: now is possible to log in table and in log4j
* *upd: ctx and init funtion parameter.
* *new: getLOG4PLSQVersion return string Version
* * use dynamique *upd: create of PLOGPARAM for updatable parameter
* *new: getLevelInText return the text level for one level
* **************************************************************
* I read a very interesting article write by Steven Feuerstein
* - Handling Exceptional Behavior -
* this 2 new features is inspired direcly by this article
* **************************************************************
* * new: assert procedure
* * new: new procedure error prototype from log SQLCODE and SQLERRM
*V3.1 Guillaume Moulard 23-DEC-03 add functions for customize the log level
*V3.1.1 Guillaume Moulard 29-JAN-04 increase perf : propose by Detlef
*V3.1.2 Guillaume Moulard 02-FEV-04 *new: Log4JbackgroundProcess create a thread for each database connexion
*V3.1.2 Guillaume Moulard 02-FEV-04 *new: Log4JbackgroundProcess create a thread for each database connexion
*V3.1.2.1 Guillaume Moulard 12-FEV-04 *BUG: bad version number, bad log with purge and isXxxxEnabled Tx to Pascal Mwakuye
*V3.1.2.2 Guillaume Moulard 27-FEV-04 *BUG: pbs with call stack
*V3.2 Greg Woolsey 29-MAR-04 add MDC (Mapped Domain Context) Feature
*<br/>
*<br/>
* Copyright (C) LOG4PLSQL project team. All rights reserved.<br/>
*<br/>
* This software is published under the terms of the The LOG4PLSQL <br/>
* Software License, a copy of which has been included with this<br/>
* distribution in the LICENSE.txt file. <br/>
* see: <http://log4plsql.sourceforge.net> <br/><br/>
*
*/ -------------------------------------------------------------------
-- Constants (no modification please)
------------------------------------------------------------------- NOLEVEL CONSTANT NUMBER := -999.99 ;
DEFAULTEXTMESS CONSTANT VARCHAR2(20) := 'GuillaumeMoulard'; SUBTYPE TOPER IS VARCHAR2(30); -- 操作员
SUBTYPE TADDRESS IS VARCHAR(30); -- 操作站点
SUBTYPE TFUNCNO IS NUMBER(9); -- 功能编号
SUBTYPE TERRCODE IS NUMBER(9); -- 错误代码
SUBTYPE TERRMSG IS VARCHAR2(255); -- 错误信息
SUBTYPE TLSTR IS VARCHAR2(4000); -- 长字符串类
-------------------------------------------------------------------
-- Constants (tools general parameter)
-- you can update regard your context
-------------------------------------------------------------------
-- in V3 this section is now store in plogparam. Is note necessary for
-- the end user to update this curent package. -------------------------------------------------------------------
-- Constants (tools internal parameter)
------------------------------------------------------------------- -- The OFF has the highest possible rank and is intended to turn off logging.
LOFF CONSTANT number := 10 ;
-- The FATAL level designates very severe error events that will presumably lead the application to abort.
LFATAL CONSTANT number := 20 ;
-- The ERROR level designates error events that might still allow the application to continue running.
LERROR CONSTANT number := 30 ;
-- The WARN level designates potentially harmful situations.
LWARN CONSTANT number := 40 ;
-- The INFO level designates informational messages that highlight the progress of the application at coarse-grained level.
LINFO CONSTANT number := 50 ;
-- The DEBUG Level designates fine-grained informational events that are most useful to debug an application.
LDEBUG CONSTANT number := 60 ;
-- The ALL has the lowest possible rank and is intended to turn on all logging.
LALL CONSTANT number := 70 ; -- raise constante
ERR_CODE_DBMS_PIPE CONSTANT NUMBER := -20503;
MES_CODE_DBMS_PIPE CONSTANT VARCHAR2(100) := 'error DBMS_PIPE.send_message. return code :'; -------------------------------------------------------------------
-- Public declaration of package
-------------------------------------------------------------------
TYPE LOG_CTX IS RECORD ( -- Context de log
isDefaultInit BOOLEAN default FALSE ,
LLEVEL TLOG.LLEVEL%type ,
LSECTION TLOG.LSECTION%type ,
LTEXTE TLOG.LTEXTE%type ,
USE_LOG4J BOOLEAN ,
USE_OUT_TRANS BOOLEAN ,
USE_LOGTABLE BOOLEAN ,
USE_ALERT BOOLEAN ,
USE_TRACE BOOLEAN ,
USE_DBMS_OUTPUT BOOLEAN ,
INIT_LSECTION TLOG.LSECTION%type ,
INIT_LLEVEL TLOG.LLEVEL%type ,
DBMS_PIPE_NAME VARCHAR2(255) ,
DBMS_OUTPUT_WRAP PLS_INTEGER
); -------------------------------------------------------------------
-- Public Procedure and function
------------------------------------------------------------------- /**
For use a log debug level
*/
PROCEDURE debug
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
); PROCEDURE debug
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
); PROCEDURE debug
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errmsg IN TLSTR --出错信息
); PROCEDURE info
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errmsg IN TLSTR --出错信息
); PROCEDURE warn
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errmsg IN TLSTR --出错信息
); PROCEDURE error
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errcode IN TERRCODE,
o_errmsg IN TLSTR --出错信息
); PROCEDURE state
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
i_state_code IN TLSTR,--状态编码
i_state_msg IN TLSTR--状态信息
); PROCEDURE fatal
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errcode OUT TERRCODE,
o_errmsg OUT TLSTR --出错信息
); /**
For use a log info level
*/
PROCEDURE info
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
);
PROCEDURE info
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
); /**
For use a log warning level
*/
PROCEDURE warn
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
);
PROCEDURE warn
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
); /**
For use a log error level
new V3 call without argument or only with one context, SQLCODE - SQLERRM is log.
*/
PROCEDURE error
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
); PROCEDURE error
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
);
/**
For use a log fatal level
*/
PROCEDURE fatal
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
);
PROCEDURE fatal
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
); /**
Generique procedure (use only for define your application level DEFINE_APPLICATION_LEVEL=TRUE)
*/ PROCEDURE log
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOG.LLEVEL%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
);
PROCEDURE log
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOGLEVEL.LCODE%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
);
PROCEDURE log
(
pLEVEL IN TLOG.LLEVEL%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
); PROCEDURE log
(
pLEVEL IN TLOGLEVEL.LCODE%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
) ; PROCEDURE scm_log
(
PLEVEL IN TLOG.LLEVEL%TYPE, -- log level
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errcode IN TERRCODE, -- 错误代码
o_errmsg IN TLSTR --出错信息
); /*
context initialisation
*@param pSECTION default = NULL => PLSQL CALL STACK
*@param pLEVEL default = PLOGPARAM.DEFAULT_LEVEL -> LDEBUG
*@param pLOG4J default = PLOGPARAM.DEFAULT_USE_LOG4J -> FALSE (If true backgroun process is require)
*@param pLOGTABLE default = PLOGPARAM.DEFAULT_LOG_TABLE -> TRUE
*@param pOUT_TRANS default = PLOGPARAM.DEFAULT_LOG_OUT_TRANS -> TRUE
*@param pALERT default = PLOGPARAM.DEFAULT_LOG_ALERT -> FALSE
*@param pTRACE default = PLOGPARAM.DEFAULT_LOG_TRACE -> FALSE
*@param pDBMS_OUTPUT default = PLOGPARAM.DEFAULT_DBMS_OUTPUT -> FALSE
*return new context LOG_CTX
*/
FUNCTION init
(
pSECTION IN TLOG.LSECTION%type default NULL , -- root of the tree section
pLEVEL IN TLOG.LLEVEL%type default PLOGPARAM.DEFAULT_LEVEL , -- log level (Use only for debug)
pLOG4J IN BOOLEAN default PLOGPARAM.DEFAULT_USE_LOG4J, -- if true the log is send to log4j
pLOGTABLE IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_TABLE, -- if true the log is insert into tlog
pOUT_TRANS IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_OUT_TRANS, -- if true the log is in transactional log
pALERT IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_ALERT, -- if true the log is write in alert.log
pTRACE IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_TRACE, -- if true the log is write in trace file
pDBMS_OUTPUT IN BOOLEAN default PLOGPARAM.DEFAULT_DBMS_OUTPUT, -- if true the log is send in standard output (DBMS_OUTPUT.PUT_LINE)
pDBMS_PIPE_NAME IN VARCHAR2 default PLOGPARAM.DEFAULT_DBMS_PIPE_NAME, --
pDBMS_OUTPUT_WRAP IN PLS_INTEGER default PLOGPARAM.DEFAULT_DBMS_OUTPUT_LINE_WRAP
)
RETURN LOG_CTX; /**
<B>Sections management</B> : init a new section
*/
PROCEDURE setBeginSection
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pSECTION IN TLOG.LSECTION%type -- log text
); /**
<B>Sections management</B> : get a current section
return current section
*/
FUNCTION getSection
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN TLOG.LSECTION%type;
/**
<B>Sections management</B> : get a default section
*@return current section
*/
FUNCTION getSection
RETURN TLOG.LSECTION%type; /**
<B>Sections management</B> : close a Section<BR/>
without pSECTION : clean all section
*/
PROCEDURE setEndSection
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pSECTION IN TLOG.LSECTION%type default 'EndAllSection' -- log text
); /*
<B>Levels Management</B> : increase level<BR/>
it is possible to dynamically update with setLevell the level of log<BR/>
call of setLevel without paramettre repositions the levels has that specifier <BR/>
in the package<BR/>
erreur possible : -20501, 'Set Level not in LOG predefine constantes'<BR/>
*/
PROCEDURE setLevel
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOG.LLEVEL%type default NOLEVEL -- Higher level to allot dynamically
); PROCEDURE setLevel
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOGLEVEL.LCODE%type -- Higher level to allot dynamically
); /**
<B>Levels Management</B> : Get a current level
*/
FUNCTION getLevel
(
pCTX IN LOG_CTX -- Context
)
RETURN TLOG.LLEVEL%type; /**
<B>Levels Management</B> : Get a default level
*/
FUNCTION getLevel
RETURN TLOG.LLEVEL%type; /**
<B>Levels Management</B> : return true if current level is Debug
*/
FUNCTION isDebugEnabled
(
pCTX IN LOG_CTX -- Context
)
RETURN boolean; /**
<B>Levels Management</B> : return true if default level is Debug
*/
FUNCTION isDebugEnabled
RETURN boolean; /**
<B>Levels Management</B> : return true if current level is Info
*/
FUNCTION isInfoEnabled
(
pCTX IN LOG_CTX -- Context
)
RETURN boolean; /**
<B>Levels Management</B> : return true if default level is Info
*/
FUNCTION isInfoEnabled
RETURN boolean; /**
<B>Levels Management</B> : return true if current level is Warn
*/
FUNCTION isWarnEnabled
(
pCTX IN LOG_CTX -- Context
)
RETURN boolean; /**
<B>Levels Management</B> : return true if default level is Warn
*/
FUNCTION isWarnEnabled
RETURN boolean; /**
<B>Levels Management</B> : return true if current level is Error
*/
FUNCTION isErrorEnabled
(
pCTX IN LOG_CTX -- Context
)
RETURN boolean; /**
<B>Levels Management</B> : return true if default level is Error
*/
FUNCTION isErrorEnabled
RETURN boolean; /**
<B>Levels Management</B> : return true if current level is Fatal
*/
FUNCTION isFatalEnabled
(
pCTX IN LOG_CTX -- Context
)
RETURN boolean; /**
<B>Levels Management</B> : return true if default level is Fatal
*/
FUNCTION isFatalEnabled
RETURN boolean; /*
<B>Transactional management </B> : define a transaction mode<BR/>
parameter transactional mode <BR/>
TRUE => Log in transaction <BR/>
FALSE => Log out off transaction <BR/>
*/
PROCEDURE setTransactionMode
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inTransaction IN boolean default TRUE -- TRUE => Log in transaction
-- FALSE => Log out off transaction
); /**
<B>Transactional management </B> : retun a transaction mode<BR/>
TRUE => Log in transaction <BR/>
FALSE => Log out off transaction <BR/>
*/
FUNCTION getTransactionMode
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean;
/**
<B>Transactional management </B> : retun a default transaction mode<BR/>
TRUE => Log in transaction <BR/>
FALSE => Log out off transaction <BR/>
*/
FUNCTION getTransactionMode
RETURN boolean; /**
<B>USE_LOG4J management </B> : define a USE_LOG4J destination mode<BR/>
TRUE => Log is send to log4j<BR/>
FALSE => Log is not send to log4j<BR/>
*/
PROCEDURE setUSE_LOG4JMode
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inUSE_LOG4J IN boolean default TRUE -- TRUE => Log is send to USE_LOG4J
-- FALSE => Log is not send to USE_LOG4J
); /**
<B>USE_LOG4J management </B> : retun a USE_LOG4J mode<BR/>
TRUE => Log is send to USE_LOG4J<BR/>
FALSE => Log is not send to USE_LOG4J<BR/>
*/
FUNCTION getUSE_LOG4JMode
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean;
/**
<B>USE_LOG4J management </B> : retun a USE_LOG4J mode<BR/>
TRUE => Log is send to USE_LOG4J<BR/>
FALSE => Log is not send to USE_LOG4J<BR/>
*/
FUNCTION getUSE_LOG4JMode
RETURN boolean; /**
<B>LOG_TABLE management </B> : define a LOG_TABLE destination mode<BR/>
TRUE => Log is send to LOG_TABLE<BR/>
FALSE => Log is not send to LOG_TABLE<BR/>
*/
PROCEDURE setLOG_TABLEMode
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inLOG_TABLE IN boolean default TRUE -- TRUE => Log is send to LOG_TABLE
-- FALSE => Log is not send to LOG_TABLE
); /**
<B>LOG_TABLE management </B> : retun a LOG_TABLE mode<BR/>
TRUE => Log is send to LOG_TABLE<BR/>
FALSE => Log is not send to LOG_TABLE<BR/>
*/
FUNCTION getLOG_TABLEMode
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean;
/**
<B>LOG_TABLE management </B> : retun a LOG_TABLE mode<BR/>
TRUE => Log is send to LOG_TABLE<BR/>
FALSE => Log is not send to LOG_TABLE<BR/>
*/
FUNCTION getLOG_TABLEMode
RETURN boolean; /**
<B>LOG_ALERT management </B> : define a LOG_ALERT destination mode<BR/>
TRUE => Log is send to LOG_ALERT<BR/>
FALSE => Log is not send to LOG_ALERT<BR/>
*/
PROCEDURE setLOG_ALERTMode
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inLOG_ALERT IN boolean default TRUE -- TRUE => Log is send to LOG_ALERT
-- FALSE => Log is not send to LOG_ALERT
); /**
<B>LOG_ALERT management </B> : retun a LOG_ALERT mode<BR/>
TRUE => Log is send to LOG_ALERT<BR/>
FALSE => Log is not send to LOG_ALERT<BR/>
*/
FUNCTION getLOG_ALERTMode
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean;
/**
<B>LOG_ALERT management </B> : retun a LOG_ALERT mode<BR/>
TRUE => Log is send to LOG_ALERT<BR/>
FALSE => Log is not send to LOG_ALERT<BR/>
*/
FUNCTION getLOG_ALERTMode
RETURN boolean; /**
<B>LOG_TRACE management </B> : define a LOG_TRACE destination mode<BR/>
TRUE => Log is send to LOG_TRACE<BR/>
FALSE => Log is not send to LOG_TRACE<BR/>
*/
PROCEDURE setLOG_TRACEMode
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inLOG_TRACE IN boolean default TRUE -- TRUE => Log is send to LOG_TRACE
-- FALSE => Log is not send to LOG_TRACE
); /**
<B>LOG_TRACE management </B> : retun a LOG_TRACE mode<BR/>
TRUE => Log is send to LOG_TRACE<BR/>
FALSE => Log is not send to LOG_TRACE<BR/>
*/
FUNCTION getLOG_TRACEMode
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean;
/**
<B>LOG_TRACE management </B> : retun a LOG_TRACE mode<BR/>
TRUE => Log is send to LOG_TRACE<BR/>
FALSE => Log is not send to LOG_TRACE<BR/>
*/
FUNCTION getLOG_TRACEMode
RETURN boolean; /**
<B>DBMS_OUTPUT management </B> : define a DBMS_OUTPUT destination mode<BR/>
TRUE => Log is send to DBMS_OUTPUT<BR/>
FALSE => Log is not send to DBMS_OUTPUT<BR/>
*/
PROCEDURE setDBMS_OUTPUTMode
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inDBMS_OUTPUT IN boolean default TRUE -- TRUE => Log is send to DBMS_OUTPUT
-- FALSE => Log is not send to DBMS_OUTPUT
); /**
<B>DBMS_OUTPUT management </B> : retun a DBMS_OUTPUT mode<BR/>
TRUE => Log is send to DBMS_OUTPUT<BR/>
FALSE => Log is not send to DBMS_OUTPUT<BR/>
*/
FUNCTION getDBMS_OUTPUTMode
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean;
/**
<B>DBMS_OUTPUT management </B> : retun a DBMS_OUTPUT mode<BR/>
TRUE => Log is send to DBMS_OUTPUT<BR/>
FALSE => Log is not send to DBMS_OUTPUT<BR/>
*/
FUNCTION getDBMS_OUTPUTMode
RETURN boolean; /*
<B>assert</B> log a messge is pCondition is FALSE if pRaiseExceptionIfFALSE = TRUE the message is raise<BR/>
*@param pCTX IN OUT NOCOPY LOG_CTX -> Context
*@param pCONDITION IN BOOLEAN -> error condition
*@param pLogErrorMessageIfFALSE IN VARCHAR2 default 'assert condition error' -> message if pCondition is true
*@param pLogErrorCodeIfFALSE IN NUMBER default -20000 -> error code is pCondition is true range -20000 .. -20999
*@param pRaiseExceptionIfFALSE IN BOOLEAN default FALSE -> if true raise pException_in if pCondition is true
*@param pLogErrorReplaceError IN BOOLEAN default FALSE -> TRUE, the error is placed on the stack of previous errors. If FALSE (the default), the error replaces all previous errors (see Oracle Documentation RAISE_APPLICATION_ERROR)
*return log a messge if pCondition is FALSE. If pRaiseExceptionIfFALSE = TRUE the message is raise
*/
PROCEDURE assert (
pCONDITION IN BOOLEAN , -- error condition
pLogErrorMessageIfFALSE IN VARCHAR2 default 'assert condition error' , -- message if pCondition is true
pLogErrorCodeIfFALSE IN NUMBER default -20000 , -- error code is pCondition is true range -20000 .. -20999
pRaiseExceptionIfFALSE IN BOOLEAN default FALSE , -- if true raise pException_in if pCondition is true
pLogErrorReplaceError in BOOLEAN default FALSE -- TRUE, the error is placed on the stack of previous errors.
-- If FALSE (the default), the error replaces all previous errors
-- see Oracle Documentation RAISE_APPLICATION_ERROR
);
/*
<B>assert</B> log a messge is pCondition is FALSE if pRaiseExceptionIfFALSE = TRUE the message is raise<BR/>
*@param pCTX IN OUT NOCOPY LOG_CTX -> Context
*@param pCONDITION IN BOOLEAN -> error condition
*@param pLogErrorMessageIfFALSE IN VARCHAR2 default 'assert condition error' -> message if pCondition is true
*@param pLogErrorCodeIfFALSE IN NUMBER default -20000 -> error code is pCondition is true range -20000 .. -20999
*@param pRaiseExceptionIfFALSE IN BOOLEAN default FALSE -> if true raise pException_in if pCondition is true
*@param pLogErrorReplaceError IN BOOLEAN default FALSE -> TRUE, the error is placed on the stack of previous errors. If FALSE (the default), the error replaces all previous errors (see Oracle Documentation RAISE_APPLICATION_ERROR)
*return log a messge if pCondition is FALSE. If pRaiseExceptionIfFALSE = TRUE the message is raise */
PROCEDURE assert (
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pCONDITION IN BOOLEAN , -- error condition
pLogErrorMessageIfFALSE IN VARCHAR2 default 'assert condition error' , -- message if pCondition is true
pLogErrorCodeIfFALSE IN NUMBER default -20000 , -- error code is pCondition is true range -20000 .. -20999
pRaiseExceptionIfFALSE IN BOOLEAN default FALSE , -- if true raise pException_in if pCondition is true
pLogErrorReplaceError in BOOLEAN default FALSE -- TRUE, the error is placed on the stack of previous errors.
-- If FALSE (the default), the error replaces all previous errors
-- see Oracle Documentation RAISE_APPLICATION_ERROR
); /**
<B>full_call_stack</B> log result of dbms_utility.format_call_stack<BR/>
some time is necessary for debug code.
*/
PROCEDURE full_call_stack;
PROCEDURE full_call_stack (
pCTX IN OUT NOCOPY LOG_CTX -- Context
); /*
<B>getLOG4PLSQVersion</B> return a string with a current version<BR/>
*/
FUNCTION getLOG4PLSQVersion return varchar2; /*
<B>getLevelInText</B> return a string with a level in send in parameter<BR/>
*/
FUNCTION getLevelInText (
pLevel TLOG.LLEVEL%type default PLOGPARAM.DEFAULT_LEVEL
) return varchar2; /*
<B>getTextInLevel</B> return a level with a String in send in parameter<BR/>
*/
FUNCTION getTextInLevel (
pCode TLOGLEVEL.LCODE%type
) return TLOG.LLEVEL%type ; /*
<B>DBMS_PIPE_NAME management </B>
*/
FUNCTION getDBMS_PIPE_NAME
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN varchar2; FUNCTION getDBMS_PIPE_NAME
RETURN varchar2; PROCEDURE setDBMS_PIPE_NAME
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inDBMS_PIPE_NAME IN VARCHAR2
); -------------------------------------------------------------------
--
-------------------------------------------------------------------
/**
<B>admin functionality </B> : delete rows in table TLOG and commit
*/
PROCEDURE purge ;
PROCEDURE purge
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
); /**
<B>admin functionality </B> : delete rows in table TLOG with date max and commit
*/
PROCEDURE purge
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
DateMax IN Date -- All record to old as deleted
);
FUNCTION calleurname return varchar2;
END PLOG; ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE OR REPLACE PACKAGE BODY PLOG IS
-------------------------------------------------------------------
--
-- Nom package : PLOG
--
-- Objectif : plog code
--
-- Version : 3.0
-------------------------------------------------------------------
-- see package spec for history
------------------------------------------------------------------- -------------------------------------------------------------------
-- Variable global priv?au package
-------------------------------------------------------------------
/*
* Copyright (C) LOG4PLSQL project team. All rights reserved.
*
* This software is published under the terms of the The LOG4PLSQL
* Software License, a copy of which has been included with this
* distribution in the LICENSE.txt file.
* see: <http://log4plsql.sourceforge.net> */ ------------------------------------------------------------------- LOG4PLSQL_VERSION VARCHAR2(200) := '3.1.3.1'; -------------------------------------------------------------------
-- Code priv?au package
-------------------------------------------------------------------
------------------------------------------------------------------- --------------------------------------------------------------------
FUNCTION getNextID
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
) RETURN TLOG.ID%type
IS
temp number;
BEGIN
select SLOG.nextval into temp from dual;
return temp; end getNextID; ----------------------------------------------------------------------
--function instrLast(ch1 varchar2, ch2 varchar2) return number
--is
--ret number := 0;
--begin
-- FOR i IN REVERSE 0..length(Ch1) LOOP
-- if instr(substr(ch1,i),ch2) > 0 then
-- return i;
-- end if;
-- end loop;
-- return ret;
--end; --------------------------------------------------------------------
FUNCTION calleurname return varchar2
IS
endOfLine constant char(1) := chr(10);
endOfField constant char(1) := chr(32);
nbrLine number;
ptFinLigne number;
ptDebLigne number;
ptDebCode number;
pt1 number;
cpt number;
linenum VARCHAR2(4000);
allLines varchar2(4000);
resultat varchar2(4000);
Line varchar2(4000);
UserCode varchar2(4000);
myName varchar2(2000) := '.PLOG';
ptLineS number;
ptLineE number;
begin
allLines := dbms_utility.format_call_stack;
cpt := 2;
ptFinLigne := length(allLines);
ptDebLigne := ptFinLigne; While ptFinLigne > 0 and ptDebLigne > 83 loop
ptDebLigne := INSTR (allLines, endOfLine, -1, cpt) + 1 ;
cpt := cpt + 1;
-- traite ligne
Line := REGEXP_REPLACE(SUBSTR(allLines, ptDebLigne, ptFinLigne - ptDebLigne),'[[:space:]]+',' ');
ptDebCode := INSTR (Line, endOfField, -1, 1);
UserCode := SUBSTR(Line, ptDebCode+1);
ptLineS := INSTR (Line, endOfField, 1, 1);
ptLineE := INSTR (Line, endOfField, 1, 2);
--DBMS_OUTPUT.put_line(Line);
--DBMS_OUTPUT.put_line('start:'||ptLineS);
--DBMS_OUTPUT.put_line('end:'||ptLineE);
linenum := SUBSTR(Line, ptLineS+1,ptLineE - ptLineS - 1);
IF instr(UserCode,myName) = 0 then
IF cpt > 3 then
resultat := resultat||'.';
end IF;
resultat := resultat||UserCode||':'||linenum;
end if;
ptFinLigne := ptDebLigne - 1;
end loop; return resultat;
end calleurname; --------------------------------------------------------------------
FUNCTION getDefaultContext
-- Cette fonction est priv? Elle retourne le contexte par default
-- quand il n'est pas pr閏iss?
RETURN LOG_CTX
IS
newCTX LOG_CTX;
lSECTION TLOG.LSECTION%type;
BEGIN
lSECTION := calleurname;
newCTX := init (pSECTION => lSECTION);
RETURN newCTX;
END getDefaultContext; --------------------------------------------------------------------
PROCEDURE checkAndInitCTX(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
IS
lSECTION TLOG.LSECTION%type;
BEGIN
IF pCTX.isDefaultInit = FALSE THEN
lSECTION := calleurname;
pCTX := init (pSECTION => lSECTION);
END IF;
END; --------------------------------------------------------------------
procedure addRow
(
pID in TLOG.id%type,
pLDate in TLOG.ldate%type,
pLHSECS in TLOG.lhsecs%type,
pLLEVEL in TLOG.llevel%type,
pLSECTION in TLOG.lsection%type,
pLUSER in TLOG.luser%type,
pLTEXTE in TLOG.ltexte%type,
OPER in TLOG.OPER%TYPE DEFAULT 'SYSTEM',
ADDRESS in TLOG.ADDRESS%TYPE DEFAULT '127.0.0.1',
FUNC_NO in TLOG.FUNC_NO%TYPE DEFAULT 0,
ERRCODE in TLOG.ERRCODE%TYPE DEFAULT 0
)
is
begin
insert into TLOG
(
ID ,
LDate ,
LHSECS ,
LLEVEL ,
LSECTION ,
LUSER ,
LTEXTE ,
OPER ,
ADDRESS ,
FUNC_NO ,
ERRCODE
) VALUES (
pID,
pLDate,
pLHSECS,
pLLEVEL,
pLSECTION,
pLUSER,
pLTEXTE,
OPER,
ADDRESS,
FUNC_NO,
ERRCODE
);
end; --------------------------------------------------------------------
procedure addRowAutonomous
(
pID in TLOG.id%type,
pLDate in TLOG.ldate%type,
pLHSECS in TLOG.lhsecs%type,
pLLEVEL in TLOG.llevel%type,
pLSECTION in TLOG.lsection%type,
pLUSER in TLOG.luser%type,
pLTEXTE in TLOG.ltexte%type,
OPER in TLOG.OPER%TYPE DEFAULT 'SYSTEM',
ADDRESS in TLOG.ADDRESS%TYPE DEFAULT '127.0.0.1',
FUNC_NO in TLOG.FUNC_NO%TYPE DEFAULT 0,
ERRCODE in TLOG.ERRCODE%TYPE DEFAULT 0
)
is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
addRow
(
pID => pID,
pLDate => pLDate,
pLHSECS => pLHSECS,
pLLEVEL => pLLEVEL,
pLSECTION => pLSECTION,
pLUSER => pLUSER,
pLTEXTE => pLTEXTE,
OPER => OPER,
ADDRESS => ADDRESS,
FUNC_NO => FUNC_NO,
ERRCODE => ERRCODE
);
commit;
exception when others then
PLOG.ERROR;
rollback;
raise;
end; /*procedure addLogState
(
msg IN VARCHAR2,
state IN VARCHAR2
)
is
PRAGMA AUTONOMOUS_TRANSACTION;
begin
INSERT INTO ULOG.LOG_STATE(LOG_DATE,LOG_TIME,LOG_EVENT,LOG_STATE)
VALUES(TO_CHAR(SYSDATE,'YYYYMMDD'),TO_CHAR(SYSDATE,'HH24:MI:SS'),msg,state);
commit;
exception when others then
PLOG.ERROR;
rollback;
raise;
end;*/ --------------------------------------------------------------------
PROCEDURE log
-- procedure priv?pour int間rer les donn閑s dans la table
-- RAISE : -20503 'error DBMS_PIPE.send_message.
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pID IN TLOG.ID%type ,
pLDate IN TLOG.LDATE%type ,
pLHSECS IN TLOG.LHSECS%type ,
pLLEVEL IN TLOG.LLEVEL%type ,
pLSECTION IN TLOG.LSECTION%type ,
pLUSER IN TLOG.LUSER%type ,
pLTEXTE IN TLOG.LTEXTE%type ,
OPER IN TLOG.OPER%TYPE default 'SYSTEM' ,
ADDRESS IN TLOG.ADDRESS%TYPE default '127.0.0.1',
FUNC_NO IN TLOG.FUNC_NO%TYPE default 0 ,
ERRCODE IN TLOG.ERRCODE%TYPE default 0
)
IS
ret number;
LLTEXTE TLOG.LTEXTE%type ;
pt number;
v_msg_line VARCHAR2(4000);
BEGIN IF pCTX.isDefaultInit = FALSE THEN
plog.error('please is necessary to use plog.init for yours contexte.');
END IF; IF PLTEXTE is null then
LLTEXTE := 'SQLCODE:'||SQLCODE ||' SQLERRM:'||SQLERRM;
ELSE
BEGIN
LLTEXTE := pLTEXTE;
EXCEPTION
WHEN VALUE_ERROR THEN
ASSERT (pCTX, length(pLTEXTE) <= 2000, 'Log Message id:'||pID||' too long. ');
LLTEXTE := substr(pLTEXTE, 0, 2000);
WHEN OTHERS THEN
PLOG.FATAL;
END; END IF; IF pCTX.USE_LOGTABLE = TRUE then
IF pLLEVEL <> 60 THEN -- add by ab 20071024
IF pCTX.USE_OUT_TRANS = FALSE then
addRow
(
pID => pID,
pLDate => pLDate,
pLHSECS => pLHSECS,
pLLEVEL => pLLEVEL,
pLSECTION => pLSECTION,
pLUSER => pLUSER,
pLTEXTE => LLTEXTE,
OPER => OPER,
ADDRESS => ADDRESS,
FUNC_NO => FUNC_NO,
ERRCODE => ERRCODE
);
ELSE
addRowAutonomous
(
pID => pID,
pLDate => pLDate,
pLHSECS => pLHSECS,
pLLEVEL => pLLEVEL,
pLSECTION => pLSECTION,
pLUSER => pLUSER,
pLTEXTE => LLTEXTE,
OPER => OPER,
ADDRESS => ADDRESS,
FUNC_NO => FUNC_NO,
ERRCODE => ERRCODE
);
END IF;
END IF;
END IF; IF pCTX.USE_LOG4J = TRUE then
v_msg_line := pLDATE || MOD(pLHSECS,100) || ' | '
|| pLLEVEL || ' | '
|| PLOGPARAM.APP_ID || '|'
|| CASE WHEN pLLEVEL = 30 AND ERRCODE = 0 THEN '' ELSE LPAD(ERRCODE,9,' ') END || ' | '
|| LLTEXTE || ' | ';
/*DBMS_PIPE.pack_message(pID); -- SEQUENTIAL ID
DBMS_PIPE.pack_message(pLDATE); -- TIMESTAMP OF LOG STATEMENT
DBMS_PIPE.pack_message(MOD(pLHSECS,100)); -- HUNDREDTHS OF SECONDS FOR TIMESTAMP
DBMS_PIPE.pack_message(pLLEVEL); -- LOG LEVEL
--|| ' | ' ||PLOGPARAM.APP_ID
DBMS_PIPE.pack_message(pLSECTION); -- LOG SECTION - ANALOGUE TO LOG4J Logger NAME
DBMS_PIPE.pack_message(CASE WHEN pLLEVEL = 30 AND ERRCODE = 0 THEN ' 0000' ELSE LPAD(ERRCODE,9,' ') END||' | '||LLTEXTE); -- LOG MESSAGE
DBMS_PIPE.pack_message(pLUSER); -- CALLING USER
DBMS_PIPE.pack_message('SAVE_IN_LOG'); -- MESSAGE TYPE?
--DBMS_PIPE.pack_message(PMDC.getKeyString); -- MAPPED DOMAIN CONTEXT KEYS FOR LOG4J
--DBMS_PIPE.pack_message(PMDC.getValueString); -- MAPPED DOMAIN CONTEXT VALUES FOR LOG4J
--DBMS_PIPE.pack_message(PMDC.getSeparator); -- MAPPED DOMAIN CONTEXT SEPARATOR FOR LOG4J
*/
DBMS_PIPE.PACK_MESSAGE(v_msg_line);
ret := DBMS_PIPE.send_message(PLOG_UTL.fn_pipe_name);
IF (RET <> 0) THEN
raise_application_error(ERR_CODE_DBMS_PIPE, MES_CODE_DBMS_PIPE || RET);
END IF;
END IF; IF pCTX.USE_ALERT = TRUE then
sys.dbms_system.ksdwrt(2,'PLOG:'||TO_CHAR(pLDATE, 'YYYY-MM-DD HH24:MI:SS')||':'||LTRIM(TO_CHAR(MOD(pLHSECS,100),''))||' user: '||PLUSER||' level: '||getLevelInText(pLLEVEL)||' logid: '||pID ||' '||pLSECTION);
sys.dbms_system.ksdwrt(2,substr(LLTEXTE,0,1000));
if (length(LLTEXTE) >= 1000) then
sys.dbms_system.ksdwrt(2,substr(LLTEXTE,1000));
end if;
END IF; IF pCTX.USE_TRACE = TRUE then
sys.dbms_system.ksdwrt(1,'PLOG:'||TO_CHAR(pLDATE, 'YYYY-MM-DD HH24:MI:SS')||':'||LTRIM(TO_CHAR(MOD(pLHSECS,100),''))||' user: '||PLUSER||' level: '||getLevelInText(pLLEVEL)||' logid: '||pID ||' '||pLSECTION);
sys.dbms_system.ksdwrt(1,substr(LLTEXTE,0,1000));
if (length(LLTEXTE) >= 1000) then
sys.dbms_system.ksdwrt(1,substr(LLTEXTE,1000));
end if;
END IF; IF pCTX.USE_DBMS_OUTPUT = TRUE then
DECLARE
pt number;
hdr varchar2(4000);
hdr_len pls_integer;
line_len pls_integer;
wrap number := pCTX.DBMS_OUTPUT_WRAP; --length to wrap long text.
BEGIN
hdr := TO_CHAR(pLDATE, 'HH24:MI:SS')||':'||LTRIM(TO_CHAR(MOD(pLHSECS,100),''))||'-'||getLevelInText(pLLEVEL)||'-'||pLSECTION||' ';
hdr_len := length(hdr);
line_len := wrap - hdr_len;
sys.DBMS_OUTPUT.PUT(hdr);
pt := 1;
while pt <= length(LLTEXTE) loop
if pt = 1 then
sys.DBMS_OUTPUT.PUT_LINE(substr(LLTEXTE,pt,line_len));
else
sys.DBMS_OUTPUT.PUT_LINE(lpad(' ',hdr_len)||substr(LLTEXTE,pt,line_len));
end if;
pt := pt + line_len;
end loop;
END;
END IF; end log; -------------------------------------------------------------------
-------------------------------------------------------------------
-- Code public du package
-------------------------------------------------------------------
------------------------------------------------------------------- --------------------------------------------------------------------
FUNCTION init
-- initialisation du contexte
(
pSECTION IN TLOG.LSECTION%type default NULL , -- log section
pLEVEL IN TLOG.LLEVEL%type default PLOGPARAM.DEFAULT_LEVEL , -- log level (Use only for debug)
pLOG4J IN BOOLEAN default PLOGPARAM.DEFAULT_USE_LOG4J, -- if true the log is send to log4j
pLOGTABLE IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_TABLE, -- if true the log is insert into tlog
pOUT_TRANS IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_OUT_TRANS, -- if true the log is in transactional log
pALERT IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_ALERT, -- if true the log is write in alert.log
pTRACE IN BOOLEAN default PLOGPARAM.DEFAULT_LOG_TRACE, -- if true the log is write in trace file
pDBMS_OUTPUT IN BOOLEAN default PLOGPARAM.DEFAULT_DBMS_OUTPUT, -- if true the log is send in standard output (DBMS_OUTPUT.PUT_LINE)
pDBMS_PIPE_NAME IN VARCHAR2 default PLOGPARAM.DEFAULT_DBMS_PIPE_NAME, -- name of pipe to log to for Log4J output
pDBMS_OUTPUT_WRAP IN PLS_INTEGER default PLOGPARAM.DEFAULT_DBMS_OUTPUT_LINE_WRAP -- length to wrap output to when using DBMS_OUTPUT )
RETURN LOG_CTX
IS
pCTX LOG_CTX;
BEGIN pCTX.isDefaultInit := TRUE;
pCTX.LSection := nvl(pSECTION, calleurname);
pCTX.INIT_LSECTION := pSECTION;
pCTX.LLEVEL := pLEVEL;
pCTX.INIT_LLEVEL := pLEVEL;
pCTX.USE_LOG4J := pLOG4J;
pCTX.USE_OUT_TRANS := pOUT_TRANS;
pCTX.USE_LOGTABLE := pLOGTABLE;
pCTX.USE_ALERT := pALERT;
pCTX.USE_TRACE := pTRACE;
pCTX.USE_DBMS_OUTPUT := pDBMS_OUTPUT;
pCTX.DBMS_PIPE_NAME := pDBMS_PIPE_NAME;
pCTX.DBMS_OUTPUT_WRAP := pDBMS_OUTPUT_WRAP; return pCTX;
end init; --------------------------------------------------------------------
PROCEDURE setBeginSection
-- initialisation d'un debut de niveaux hierarchique de log
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pSECTION IN TLOG.LSECTION%type -- Texte du log
) IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.LSection := pCTX.LSection||PLOGPARAM.DEFAULT_Section_sep||pSECTION; end setBeginSection; --------------------------------------------------------------------
FUNCTION getSection
-- renvoie la section en cours
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN TLOG.LSECTION%type
IS
BEGIN return pCTX.LSection; end getSection; --------------------------------------------------------------------
FUNCTION getSection
-- renvoie la section en cours
RETURN TLOG.LSECTION%type
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN return getSection(pCTX =>generiqueCTX) ; end getSection; --------------------------------------------------------------------
PROCEDURE setEndSection
-- fin d'un niveau hierarchique de log et dee tout c'est sup閞ieur
-- par default [/]
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pSECTION IN TLOG.LSECTION%type default 'EndAllSection' -- Texte du log
) IS
BEGIN
checkAndInitCTX(pCTX);
if pSECTION = 'EndAllSection' THEN
pCTX.LSection := nvl(pCTX.INIT_LSECTION, calleurname);
RETURN;
END IF; pCTX.LSection := substr(pCTX.LSection,1,instr(UPPER(pCTX.LSection), UPPER(pSECTION), -1)-2); end setEndSection; -------------------------------------------------------------------
PROCEDURE setTransactionMode
-- utlisation des log dans ou en dehors des transactions
-- TRUE => Les log sont dans la transaction
-- FALSE => les log sont en dehors de la transaction
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inTransaction IN boolean default TRUE -- TRUE => Les log sont dans la transaction,
-- FALSE => les log sont en dehors de la transaction
)
IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.USE_OUT_TRANS := inTransaction; end setTransactionMode; -------------------------------------------------------------------
FUNCTION getTransactionMode
-- TRUE => Les log sont dans la transaction
-- FALSE => les log sont en dehors de la transaction
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean
IS
BEGIN
return pCTX.USE_OUT_TRANS;
end getTransactionMode;
-------------------------------------------------------------------
FUNCTION getTransactionMode
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getTransactionMode(pCTX => generiqueCTX);
end getTransactionMode; -------------------------------------------------------------------
PROCEDURE setUSE_LOG4JMode
--TRUE => Log is send to USE_LOG4J
--FALSE => Log is not send to USE_LOG4J
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inUSE_LOG4J IN boolean default TRUE -- TRUE => Log is send to USE_LOG4J,
-- FALSE => Log is not send to USE_LOG4J
)
IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.USE_LOG4J := inUSE_LOG4J; end setUSE_LOG4JMode; -------------------------------------------------------------------
FUNCTION getUSE_LOG4JMode
--TRUE => Log is send to USE_LOG4J
--FALSE => Log is not send to USE_LOG4J
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean
IS
BEGIN
return pCTX.USE_LOG4J;
end getUSE_LOG4JMode;
-------------------------------------------------------------------
FUNCTION getUSE_LOG4JMode
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getTransactionMode(pCTX => generiqueCTX);
end getUSE_LOG4JMode; -------------------------------------------------------------------
PROCEDURE setLOG_TABLEMode
--TRUE => Log is send to LOG_TABLEMODE
--FALSE => Log is not send to LOG_TABLEMODE
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inLOG_TABLE IN boolean default TRUE -- TRUE => Log is send to LOG_TABLEMODE,
-- FALSE => Log is not send to LOG_TABLEMODE
)
IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.USE_LOGTABLE := inLOG_TABLE; end setLOG_TABLEMode; -------------------------------------------------------------------
FUNCTION getLOG_TABLEMode
--TRUE => Log is send to LOG_TABLEMODE
--FALSE => Log is not send to LOG_TABLEMODE
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean
IS
BEGIN
return pCTX.USE_LOGTABLE;
end getLOG_TABLEMode;
-------------------------------------------------------------------
FUNCTION getLOG_TABLEMode
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getTransactionMode(pCTX => generiqueCTX);
end getLOG_TABLEMode; -------------------------------------------------------------------
PROCEDURE setLOG_ALERTMode
--TRUE => Log is send to LOG_ALERT
--FALSE => Log is not send to LOG_ALERT
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inLOG_ALERT IN boolean default TRUE -- TRUE => Log is send to LOG_ALERT,
-- FALSE => Log is not send to LOG_ALERT
)
IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.USE_ALERT := inLOG_ALERT; end setLOG_ALERTMode; -------------------------------------------------------------------
FUNCTION getLOG_ALERTMode
--TRUE => Log is send to LOG_ALERT
--FALSE => Log is not send to LOG_ALERT
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean
IS
BEGIN
return pCTX.USE_ALERT;
end getLOG_ALERTMode;
-------------------------------------------------------------------
FUNCTION getLOG_ALERTMode
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getTransactionMode(pCTX => generiqueCTX);
end getLOG_ALERTMode; -------------------------------------------------------------------
PROCEDURE setLOG_TRACEMode
--TRUE => Log is send to LOG_TRACE
--FALSE => Log is not send to LOG_TRACE
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inLOG_TRACE IN boolean default TRUE -- TRUE => Log is send to LOG_TRACE,
-- FALSE => Log is not send to LOG_TRACE
)
IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.USE_TRACE := inLOG_TRACE; end setLOG_TRACEMode; -------------------------------------------------------------------
FUNCTION getLOG_TRACEMode
--TRUE => Log is send to LOG_TRACE
--FALSE => Log is not send to LOG_TRACE
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean
IS
BEGIN
return pCTX.USE_TRACE;
end getLOG_TRACEMode;
-------------------------------------------------------------------
FUNCTION getLOG_TRACEMode
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getTransactionMode(pCTX => generiqueCTX);
end getLOG_TRACEMode; -------------------------------------------------------------------
PROCEDURE setDBMS_OUTPUTMode
--TRUE => Log is send to DBMS_OUTPUT
--FALSE => Log is not send to DBMS_OUTPUT
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inDBMS_OUTPUT IN boolean default TRUE -- TRUE => Log is send to DBMS_OUTPUT,
-- FALSE => Log is not send to DBMS_OUTPUT
)
IS
BEGIN
checkAndInitCTX(pCTX);
pCTX.USE_DBMS_OUTPUT := inDBMS_OUTPUT; end setDBMS_OUTPUTMode; -------------------------------------------------------------------
FUNCTION getDBMS_OUTPUTMode
--TRUE => Log is send to DBMS_OUTPUT
--FALSE => Log is not send to DBMS_OUTPUT
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN boolean
IS
BEGIN
checkAndInitCTX(pCTX);
return pCTX.USE_DBMS_OUTPUT;
end getDBMS_OUTPUTMode;
-------------------------------------------------------------------
FUNCTION getDBMS_OUTPUTMode
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getTransactionMode(pCTX => generiqueCTX);
end getDBMS_OUTPUTMode; -------------------------------------------------------------------
PROCEDURE setLevel
-- il est possible de modifier avec setLevell dynamiquement le niveau de log
-- l'appel de setLevel sans paramettre re-poossitionne le niveaux a celuis specifier
-- dans le package.
-- erreur possible : -20501, 'Set Level not in LOG predefine constantes'
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOG.LLEVEL%type default NOLEVEL -- Level sup閞ieur attribuer dynamiquement
) IS
nbrl number;
BEGIN
checkAndInitCTX(pCTX);
IF pLEVEL = NOLEVEL then
pCTX.LLEVEL := pCTX.INIT_LLEVEL;
END IF; select count(*) into nbrl FROM TLOGLEVEL where TLOGLEVEL.LLEVEL=pLEVEL;
IF nbrl > 0 then
pCTX.LLEVEL := pLEVEL;
ELSE
raise_application_error(-20501, 'SetLevel ('||pLEVEL||') not in TLOGLEVEL table');
END IF;
EXCEPTION
WHEN OTHERS THEN
PLOG.ERROR;
end setLevel; PROCEDURE setLevel
-- il est possible de modifier avec setLevell dynamiquement le niveau de log
-- l'appel de setLevel sans paramettre re-poossitionne le niveaux a celuis specifier
-- dans le package.
-- erreur possible : -20501, 'Set Level not in LOG predefine constantes'
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOGLEVEL.LCODE%type -- Level sup閞ieur attribuer dynamiquement
) IS
nbrl number;
BEGIN setLevel (pCTX, getTextInLevel(pLEVEL)); end setLevel; -------------------------------------------------------------------
FUNCTION getLevel
-- Retourne le level courant
(
pCTX IN LOG_CTX -- Context
)
RETURN TLOG.LLEVEL%type
IS
BEGIN
return pCTX.LLEVEL;
end getLevel; FUNCTION getLevel
RETURN TLOG.LLEVEL%type
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getLevel( pCTX => generiqueCTX);
end getLevel; -------------------------------------------------------------------------
FUNCTION islevelEnabled
-- fonction outil appeler par les is[Debug|Info|Warn|Error]Enabled
(
pCTX IN LOG_CTX, -- Context
pLEVEL IN TLOG.LLEVEL%type -- Level a tester
)
RETURN boolean
IS
BEGIN
if getLevel(pCTX) >= pLEVEL then
return TRUE;
else
return FALSE;
end if;
end islevelEnabled; FUNCTION islevelEnabled
(
pLEVEL IN TLOG.LLEVEL%type -- Level a tester
)
RETURN boolean
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return islevelEnabled( pCTX => generiqueCTX, pLEVEL => pLEVEL);
end islevelEnabled;
-------------------------------------------------------------------
FUNCTION isFatalEnabled RETURN boolean is begin return islevelEnabled(getTextInLevel('FATAL')); end;
FUNCTION isErrorEnabled RETURN boolean is begin return islevelEnabled(getTextInLevel('ERROR')); end;
FUNCTION isWarnEnabled RETURN boolean is begin return islevelEnabled(getTextInLevel('WARN')) ; end;
FUNCTION isInfoEnabled RETURN boolean is begin return islevelEnabled(getTextInLevel('INFO')) ; end;
FUNCTION isDebugEnabled RETURN boolean is begin return islevelEnabled(getTextInLevel('DEBUG')); end;
FUNCTION isFatalEnabled ( pCTX IN LOG_CTX ) RETURN boolean is begin return islevelEnabled(pCTX, getTextInLevel('FATAL')); end;
FUNCTION isErrorEnabled ( pCTX IN LOG_CTX ) RETURN boolean is begin return islevelEnabled(pCTX, getTextInLevel('ERROR')); end;
FUNCTION isWarnEnabled ( pCTX IN LOG_CTX ) RETURN boolean is begin return islevelEnabled(pCTX, getTextInLevel('WARN')) ; end;
FUNCTION isInfoEnabled ( pCTX IN LOG_CTX ) RETURN boolean is begin return islevelEnabled(pCTX, getTextInLevel('INFO')) ; end;
FUNCTION isDebugEnabled ( pCTX IN LOG_CTX ) RETURN boolean is begin return islevelEnabled(pCTX, getTextInLevel('DEBUG')); end; --------------------------------------------------------------------
PROCEDURE purge
-- Purge de la log
IS
tempLogCtx PLOG.LOG_CTX;
BEGIN
purge(tempLogCtx);
end purge;
--------------------------------------------------------------------
PROCEDURE purge
-- Purge de la log
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
) IS
BEGIN
checkAndInitCTX(pCTX);
execute immediate ('truncate table tlog');
purge(pCTX, sysdate+1);
end purge; --------------------------------------------------------------------
PROCEDURE purge
-- Purge de la log avec date max
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
DateMax IN Date -- Tout les enregistrements supperieur a
-- la date sont purg? ) IS
tempLogCtx PLOG.LOG_CTX := PLOG.init(pSECTION => 'plog.purge', pLEVEL => PLOG.LINFO);
BEGIN
checkAndInitCTX(pCTX); delete from tlog where ldate < DateMax;
INFO(tempLogCtx, 'Purge by user:'||USER); end purge; --------------------------------------------------------------------
PROCEDURE log
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOG.LLEVEL%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
) IS lId TLOG.ID%type ;
lLSECTION TLOG.LSECTION%type := getSection(pCTX);
lLHSECS TLOG.LHSECS%type ;
m varchar2(100); BEGIN
checkAndInitCTX(pCTX);
IF pLEVEL > getLevel(pCTX) THEN
RETURN;
END IF;
lId := getNextID(pCTX); log ( pCTX =>pCTX,
pID =>lId,
pLDate =>sysdate,
pLHSECS =>DBMS_UTILITY.GET_TIME,
pLLEVEL =>pLEVEL,
pLSECTION =>lLSECTION,
pLUSER =>user,
pLTEXTE =>pTEXTE
); end log; PROCEDURE log
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pLEVEL IN TLOGLEVEL.LCODE%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel(pLEVEL), pCTX => pCTX, pTEXTE => pTEXTE);
end log; PROCEDURE log
(
pLEVEL IN TLOG.LLEVEL%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
) IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
LOG(pLEVEL => pLEVEL, pCTX => generiqueCTX, pTEXTE => pTEXTE);
end log; PROCEDURE log
(
pLEVEL IN TLOGLEVEL.LCODE%type , -- log level
pTEXTE IN TLOG.LTEXTE%type default DEFAULTEXTMESS -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel(pLEVEL), pTEXTE => pTEXTE);
end log; PROCEDURE scm_log
(
PLEVEL IN TLOG.LLEVEL%TYPE, -- log level
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errcode IN TERRCODE , -- 错误代码
o_errmsg IN TLSTR --出错信息
) IS
pCTX PLOG.LOG_CTX := PLOG.getDefaultContext; -- Context
lId TLOG.ID%type ;
lLSECTION TLOG.LSECTION%type := getSection(pCTX);
lLHSECS TLOG.LHSECS%type ;
m varchar2(100);
v_len NUMBER;
v_start NUMBER;
BEGIN checkAndInitCTX(pCTX);
IF pLEVEL > getLevel(pCTX) THEN
RETURN;
END IF;
lId := getNextID(pCTX); log ( pCTX =>pCTX,
pID =>lId,
pLDate =>sysdate,
pLHSECS =>DBMS_UTILITY.GET_TIME,
pLLEVEL =>PLEVEL,
pLSECTION =>lLSECTION,
pLUSER =>user,
pLTEXTE =>o_errmsg,
OPER =>i_operator,
ADDRESS =>i_address,
FUNC_NO =>i_func_no,
ERRCODE =>o_errcode
);
--dbms_output.put_line(o_errmsg); /*v_len := length(o_errmsg);
v_start := 1; WHILE v_len > 0
LOOP
dbms_output.put_line(substr(o_errmsg,v_start,250));
v_start := v_start + 250;
v_len := v_len - 250;
end loop;*/ end scm_log; --------------------------------------------------------------------
PROCEDURE debug
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('DEBUG'), pCTX => pCTX, pTEXTE => pTEXTE);
end debug; PROCEDURE debug
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('DEBUG'), pTEXTE => pTEXTE);
end debug; PROCEDURE debug
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errmsg IN TLSTR --出错信息
) IS
BEGIN
scm_log(
PLEVEL => LDEBUG,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => 0,
o_errmsg => o_errmsg
); END debug; PROCEDURE info
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errmsg IN TLSTR --出错信息
) IS
BEGIN
scm_log(
PLEVEL => LINFO,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => 0,
o_errmsg => o_errmsg
); END info; PROCEDURE warn
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errmsg IN TLSTR --出错信息
) IS
BEGIN
scm_log(
PLEVEL => LWARN,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => 0,
o_errmsg => o_errmsg
);
END warn; PROCEDURE error
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errcode IN TERRCODE,
o_errmsg IN TLSTR --出错信息
) IS
BEGIN
scm_log(
PLEVEL => LERROR,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => o_errcode,
o_errmsg => o_errmsg
);
END error; PROCEDURE state
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
i_state_code IN TLSTR,--状态编码
i_state_msg IN TLSTR--状态信息
) IS
BEGIN
scm_log(
PLEVEL => LERROR,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => 0,
o_errmsg => i_state_code || ' | ' || i_state_msg
);
END state; PROCEDURE fatal
(
i_operator IN TOPER, --操作员代码
i_address IN TADDRESS, --操作员地址
i_func_no IN TFUNCNO, --功能号
o_errcode OUT TERRCODE,
o_errmsg OUT TLSTR --出错信息
) IS
v_errmsg VARCHAR2(4000);
v_exist INTEGER;
BEGIN
o_errcode := ROUND(i_func_no /100,0)*100 + 99;
o_errcode := CASE WHEN NVL(o_errcode,0) = 0 THEN 99 ELSE o_errcode END;
v_errmsg := 'SQLCODE:' || SQLCODE || 'SQLERRM:' || SQLERRM;
v_errmsg := v_errmsg || 'ERROR_BACKTRACE:' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE;
scm_log(
PLEVEL => LFATAL,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => o_errcode,
o_errmsg => v_errmsg
);
o_errmsg := SUBSTR(v_errmsg,1,255);
IF (SQLCODE = -6508) THEN
--SELECT COUNT(ROWID) INTO v_exist FROM INTERFACE.TP_WEEKEND;
--IF (v_exist > 0) THEN
DBMS_SESSION.RESET_PACKAGE;
DBMS_SESSION.FREE_UNUSED_USER_MEMORY;
scm_log(
PLEVEL => LFATAL,
i_operator => i_operator,
i_address => i_address,
i_func_no => i_func_no,
o_errcode => o_errcode,
o_errmsg => 'could find program error occur,reset package'
);
--END IF;
END IF;
END fatal; --------------------------------------------------------------------
PROCEDURE info
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('INFO'), pCTX => pCTX, pTEXTE => pTEXTE);
end info;
PROCEDURE info
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('INFO'), pTEXTE => pTEXTE);
end info; --------------------------------------------------------------------
PROCEDURE warn
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('WARN'), pCTX => pCTX, pTEXTE => pTEXTE);
end warn;
PROCEDURE warn
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('WARN'), pTEXTE => pTEXTE);
end warn; --------------------------------------------------------------------
PROCEDURE error
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('ERROR'), pCTX => pCTX, pTEXTE => pTEXTE);
end error;
PROCEDURE error
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('ERROR'), pTEXTE => pTEXTE);
end error; --------------------------------------------------------------------
PROCEDURE fatal
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('FATAL'), pCTX => pCTX, pTEXTE => pTEXTE);
end fatal; PROCEDURE fatal
(
pTEXTE IN TLOG.LTEXTE%type default null -- log text
) IS
BEGIN
LOG(pLEVEL => getTextInLevel('FATAL'), pTEXTE => pTEXTE);
end fatal; --------------------------------------------------------------------
PROCEDURE assert (
pCTX IN OUT NOCOPY LOG_CTX , -- Context
pCONDITION IN BOOLEAN , -- error condition
pLogErrorMessageIfFALSE IN VARCHAR2 default 'assert condition error' , -- message if pCondition is true
pLogErrorCodeIfFALSE IN NUMBER default -20000 , -- error code is pCondition is true range -20000 .. -20999
pRaiseExceptionIfFALSE IN BOOLEAN default FALSE , -- if true raise pException_in if pCondition is true
pLogErrorReplaceError in BOOLEAN default FALSE -- TRUE, the error is placed on the stack of previous errors.
-- If FALSE (the default), the error replaces all previous errors
-- see Oracle Documentation RAISE_APPLICATION_ERROR )
IS
BEGIN
checkAndInitCTX(pCTX);
IF not islevelEnabled(pCTX, PLOGPARAM.DEFAULT_ASSET_LEVEL) then
RETURN;
END IF; IF NOT pCONDITION THEN
LOG (pLEVEL => PLOGPARAM.DEFAULT_ASSET_LEVEL, pCTX => pCTX, pTEXTE => 'AAS'||pLogErrorCodeIfFALSE||': '||pLogErrorMessageIfFALSE);
IF pRaiseExceptionIfFALSE THEN
raise_application_error(pLogErrorCodeIfFALSE, pLogErrorMessageIfFALSE, pLogErrorReplaceError);
END IF;
END IF;
END assert; PROCEDURE assert (
pCONDITION IN BOOLEAN , -- error condition
pLogErrorMessageIfFALSE IN VARCHAR2 default 'assert condition error' , -- message if pCondition is true
pLogErrorCodeIfFALSE IN NUMBER default -20000 , -- error code is pCondition is true range -20000 .. -20999
pRaiseExceptionIfFALSE IN BOOLEAN default FALSE , -- if true raise pException_in if pCondition is true
pLogErrorReplaceError in BOOLEAN default FALSE -- TRUE, the error is placed on the stack of previous errors.
-- If FALSE (the default), the error replaces all previous errors
-- see Oracle Documentation RAISE_APPLICATION_ERROR
)
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
assert (
pCTX => generiqueCTX,
pCONDITION => pCONDITION,
pLogErrorCodeIfFALSE => pLogErrorCodeIfFALSE,
pLogErrorMessageIfFALSE => pLogErrorMessageIfFALSE,
pRaiseExceptionIfFALSE => pRaiseExceptionIfFALSE,
pLogErrorReplaceError => pLogErrorReplaceError );
END assert ; --------------------------------------------------------------------
PROCEDURE full_call_stack
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
full_call_stack (Pctx => generiqueCTX);
END full_call_stack; PROCEDURE full_call_stack (
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
IS
BEGIN
checkAndInitCTX(pCTX);
LOG (pLEVEL => PLOGPARAM.DEFAULT_FULL_CALL_STACK_LEVEL, pCTX => pCTX, pTEXTE => dbms_utility.format_call_stack );
END full_call_stack; --------------------------------------------------------------------
FUNCTION getLOG4PLSQVersion return varchar2
IS
begin return LOG4PLSQL_VERSION; end getLOG4PLSQVersion; --------------------------------------------------------------------
FUNCTION getLevelInText (
pLevel TLOG.LLEVEL%type default PLOGPARAM.DEFAULT_LEVEL
) return varchar2
IS
ret varchar2(1000);
BEGIN SELECT LCODE into ret
FROM TLOGLEVEL
WHERE LLEVEL = pLevel;
RETURN ret;
EXCEPTION
WHEN OTHERS THEN
return 'UNDEFINED';
END getLevelInText; --------------------------------------------------------------------
FUNCTION getTextInLevel (
pCode TLOGLEVEL.LCODE%type
) return TLOG.LLEVEL%type
IS
ret TLOG.LLEVEL%type ;
BEGIN SELECT LLEVEL into ret
FROM TLOGLEVEL
WHERE LCODE = pCode;
RETURN ret;
EXCEPTION
WHEN OTHERS THEN
return PLOGPARAM.DEFAULT_LEVEL;
END getTextInLevel; FUNCTION getDBMS_PIPE_NAME
(
pCTX IN OUT NOCOPY LOG_CTX -- Context
)
RETURN varchar2
IS
BEGIN
return pCTX.DBMS_PIPE_NAME;
END getDBMS_PIPE_NAME; FUNCTION getDBMS_PIPE_NAME
RETURN varchar2
IS
generiqueCTX PLOG.LOG_CTX := PLOG.getDefaultContext;
BEGIN
return getDBMS_PIPE_NAME( pCTX => generiqueCTX);
end getDBMS_PIPE_NAME; PROCEDURE setDBMS_PIPE_NAME
(
pCTX IN OUT NOCOPY LOG_CTX , -- Context
inDBMS_PIPE_NAME IN VARCHAR2
)
IS
BEGIN
pCTX.DBMS_PIPE_NAME := inDBMS_PIPE_NAME;
END setDBMS_PIPE_NAME; --------------------------------------------------------------------
--------------------------------------------------------------------
END PLOG;
--PLOGPARAM
CREATE OR REPLACE PACKAGE PLOGPARAM IS
/**
* package name : PLOGPARAM
*<br/>
*<br/>
*See : <a href="http://log4plsql.sourceforge.net">http://log4plsql.sourceforge.net</a>
*<br/>
*<br/>
*Objectif : Store updatable paramter for PLOG.
*<br/><br/><br/><br/>
* This package is create befort PLOG
*<br/><br/><br/>
*
*
*@headcom
*<br/>
*<br/>
*<br/>
*History who date comment
*V3 Guillaume Moulard 05-AUG-03 Creation
*V3.2 Greg Woolsey 29-MAR-04 add MDC (Mapped Domain Context) Feature
*<br/>
*<br/>
* Copyright (C) LOG4PLSQL project team. All rights reserved.<br/>
*<br/>
* This software is published under the terms of the The LOG4PLSQL <br/>
* Software License, a copy of which has been included with this<br/>
* distribution in the LICENSE.txt file. <br/>
* see: <http://log4plsql.sourceforge.net> <br/><br/>
*
*/ -------------------------------------------------------------------
-- Constants (tools general parameter)
-- you can update regard your context
------------------------------------------------------------------- -- LERROR default level for production system.
-- DEFAULT_LEVEL CONSTANT TLOG.LLEVEL%type := 30 ; -- LERROR APP_ID CONSTANT VARCHAR2(255) := 'bizdb';
-- LDEBUG for developement phase
DEFAULT_LEVEL CONSTANT TLOG.LLEVEL%type := 70 ; -- LERROR -- TRUE default value for Logging in table
DEFAULT_LOG_TABLE CONSTANT BOOLEAN := TRUE; -- if DEFAULT_USE_LOG4J is TRUE log4j Log4JbackgroundProcess are necessary
DEFAULT_USE_LOG4J CONSTANT BOOLEAN := FALSE; -- TRUE default value for Logging out off transactional limits
DEFAULT_LOG_OUT_TRANS CONSTANT BOOLEAN := TRUE; -- if DEFAULT_LOG_ALERTLOG is true the log is write in alert.log file
DEFAULT_LOG_ALERT CONSTANT BOOLEAN := FALSE; -- if DEFAULT_LOG_TRACE is true the log is write in trace file
DEFAULT_LOG_TRACE CONSTANT BOOLEAN := FALSE; -- if DEFAULT_DBMS_OUTPUT is true the log is send in standard output (DBMS_OUTPUT.PUT_LINE)
DEFAULT_DBMS_OUTPUT CONSTANT BOOLEAN := FALSE; -- default level for asset
DEFAULT_ASSET_LEVEL CONSTANT TLOG.LLEVEL%type := DEFAULT_LEVEL ; -- default level for call_stack_level
DEFAULT_FULL_CALL_STACK_LEVEL CONSTANT TLOG.LLEVEL%type := DEFAULT_LEVEL ; -- use for build a string section
DEFAULT_Section_sep CONSTANT TLOG.LSECTION%type := '.'; -- default PIPE_NAME
DEFAULT_DBMS_PIPE_NAME CONSTANT VARCHAR2(255) := 'LOG_PIPE'; -- Formats output sent to DBMS_OUTPUT to this width.
DEFAULT_DBMS_OUTPUT_LINE_WRAP CONSTANT NUMBER := 100; END PLOGPARAM;
--PLOG_UTL
CREATE OR REPLACE PACKAGE PLOG_UTL AS
--get oracle database instant name
FUNCTION fn_inst_name RETURN VARCHAR2;
--get oracle database pipe name
FUNCTION fn_pipe_name RETURN VARCHAR2;
--get log file name
FUNCTION fn_log_fname RETURN VARCHAR2;
--write log to pipe
PROCEDURE sp_log;
PROCEDURE sp_open_pipe;
PROCEDURE sp_close_pipe;
--write log file
PROCEDURE sp_write_log_file;
--start job
PROCEDURE sp_start_job(IF_ASYC BOOLEAN);
--stop job
PROCEDURE sp_stop_job(TIME_OUT INT,IF_FORCE BOOLEAN);
--set cancel flag
PROCEDURE sp_set_cancel_flag(i_if_cancel CHAR);
END; CREATE OR REPLACE PACKAGE BODY PLOG_UTL AS --get oracle database instant name
FUNCTION fn_inst_name RETURN VARCHAR2
AS
v_instant_name VARCHAR2(255);
BEGIN
SELECT SYS_CONTEXT('USERENV','INSTANCE_NAME') INTO v_instant_name FROM DUAL;
RETURN v_instant_name;
END;
--get oracle database pipe name
FUNCTION fn_pipe_name RETURN VARCHAR2
AS
BEGIN
RETURN 'LOG_PIPE@' || UPPER(fn_inst_name);
END;
--get log file name
FUNCTION fn_log_fname RETURN VARCHAR2
AS
BEGIN
RETURN 'log_' || LOWER(fn_inst_name) || '_' || TO_CHAR(SYSDATE,'YYYYMMDD') || '.log';
END;
/*FUNCTIN fn_plogfile RETURN UTL_FILE.FILE_TYPE
AS
BEGIN END; */
--write log to pipe
PROCEDURE sp_log
AS
v_pipe_name VARCHAR2(255);
v_line VARCHAR2(4000);
v_ret_code NUMBER;
BEGIN
v_pipe_name := fn_pipe_name;
--DBMS_OUTPUT.PUT_LINE(v_pipe_name);
FOR i IN 1..100
LOOP
v_line := 'LINE' || i || 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
DBMS_PIPE.PACK_MESSAGE(v_line);
v_ret_code := DBMS_PIPE.SEND_MESSAGE(v_pipe_name);
--DBMS_OUTPUT.PUT_LINE(v_ret_code);
END LOOP;
END;
PROCEDURE sp_open_pipe
AS
v_ret_code NUMBER;
BEGIN
v_ret_code := DBMS_PIPE.CREATE_PIPE(fn_pipe_name);
--DBMS_OUTPUT.PUT_LINE(v_ret_code);
END;
PROCEDURE sp_close_pipe
AS
v_ret_code NUMBER;
BEGIN
v_ret_code := DBMS_PIPE.REMOVE_PIPE(fn_pipe_name);
--DBMS_OUTPUT.PUT_LINE(v_ret_code);
END;
--write log file
PROCEDURE sp_write_log_file
AS
v_dir VARCHAR2(255) := 'TMP';
v_pfile UTL_FILE.FILE_TYPE;
v_line VARCHAR2(4000);
v_pipe_name VARCHAR2(255);
v_ret_code NUMBER;
--v_exit BOOLEAN := FALSE;
v_if_cancel CHAR(1);
BEGIN
v_pipe_name := fn_pipe_name;
--DBMS_OUTPUT.PUT_LINE(fn_pipe_name);
--DBMS_OUTPUT.PUT_LINE(fn_log_fname);
v_pfile := UTL_FILE.FOPEN(v_dir,fn_log_fname,'W',4000);
<<L_LOOP>>
LOOP
v_ret_code := DBMS_PIPE.RECEIVE_MESSAGE(v_pipe_name,1);
--DBMS_OUTPUT.PUT_LINE('RECEIVE MESSAGE'||v_ret_code);
IF (v_ret_code = 1) THEN
SELECT IF_CANCEL INTO v_if_cancel FROM TLOG_INFO
WHERE INST_NAME = fn_inst_name;
IF (v_if_cancel = '') THEN
--DBMS_OUTPUT.PUT_LINE('CANCEL RECEIVE'||v_ret_code);
EXIT;
END IF;
--DBMS_OUTPUT.PUT_LINE('LOOP RECEIVE MESSAGE'||v_ret_code);
UTL_FILE.FFLUSH(v_pfile);
GOTO L_LOOP;
END IF;
--DBMS_LOCK.SLEEP(5);
--DBMS_OUTPUT.PUT_LINE('UNPACK MESSAGE'||v_ret_code);
DBMS_PIPE.UNPACK_MESSAGE(v_line);
DBMS_OUTPUT.PUT_LINE(v_line);
UTL_FILE.PUT_LINE(v_pfile,v_line);
END LOOP;
UTL_FILE.FFLUSH(v_pfile);
UTL_FILE.FCLOSE(v_pfile);
END;
--set cancel status
PROCEDURE sp_set_cancel_flag(i_if_cancel CHAR)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
v_if_cancel CHAR(1);
BEGIN
DBMS_OUTPUT.PUT_LINE('SET IF_CANCLE:'||i_if_cancel);
UPDATE TLOG_INFO SET IF_CANCEL = i_if_cancel
WHERE INST_NAME = fn_inst_name
RETURNING IF_CANCEL INTO v_if_cancel;
DBMS_OUTPUT.PUT_LINE('IF_CANCLE:'||v_if_cancel);
COMMIT;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
RAISE;
END;
--start job
PROCEDURE sp_start_job(IF_ASYC BOOLEAN)
AS
v_exist INTEGER;
BEGIN
--若JOB不存在则创建JOB
SELECT COUNT(*) INTO v_exist FROM ALL_SCHEDULER_JOBS WHERE JOB_NAME = 'LOG_JOB';
DBMS_OUTPUT.PUT_LINE('EXIT:'||v_exist);
IF (v_exist = 0) THEN
DBMS_SCHEDULER.CREATE_JOB('LOG_JOB','STORED_PROCEDURE','plog_utl.sp_write_log_file',0,NULL,NULL,NULL,'DEFAULT_JOB_CLASS',FALSE,TRUE,NULL);
DBMS_OUTPUT.PUT_LINE('CREATE JOB');
END IF;
--若JOB未运行则启动JOB
SELECT COUNT(*) INTO v_exist FROM ALL_SCHEDULER_RUNNING_JOBS WHERE JOB_NAME = 'LOG_JOB';
DBMS_OUTPUT.PUT_LINE('EXIT:'||v_exist);
IF (v_exist = 0) THEN
--清除退出标志
sp_set_cancel_flag('');
DBMS_OUTPUT.PUT_LINE('RESET JOB CANCEL FLAG');
DBMS_SCHEDULER.RUN_JOB('LOG_JOB',NOT IF_ASYC);
DBMS_OUTPUT.PUT_LINE('START JOB');
END IF;
END; PROCEDURE sp_stop_job(TIME_OUT INT,IF_FORCE BOOLEAN)
AS
v_exist INTEGER;
BEGIN
--设置退出标志
sp_set_cancel_flag('');
DBMS_LOCK.SLEEP(TIME_OUT);
--若JOB未停止则强行停止JOB
SELECT COUNT(*) INTO v_exist FROM ALL_SCHEDULER_RUNNING_JOBS WHERE JOB_NAME = 'LOG_JOB';
IF (v_exist > 0 AND IF_FORCE) THEN
DBMS_SCHEDULER.STOP_JOB('LOG_JOB',IF_FORCE);
DBMS_OUTPUT.PUT_LINE('STOP JOB FORCE');
ELSE
DBMS_OUTPUT.PUT_LINE('STOP JOB');
END IF;
END;
END;
--PMDC
CREATE OR REPLACE PACKAGE BODY PMDC AS
-------------------------------------------------------------------
--
-- Nom package : PMDC
--
-- Objectif : MDC Features
--
-- Version : 1.0
-------------------------------------------------------------------
-- see package spec for history
------------------------------------------------------------------- -------------------------------------------------------------------
-- Variable global priv?au package
-------------------------------------------------------------------
/*
* Copyright (C) LOG4PLSQL project team. All rights reserved.
*
* This software is published under the terms of the The LOG4PLSQL
* Software License, a copy of which has been included with this
* distribution in the LICENSE.txt file.
* see: <http://log4plsql.sourceforge.net> */ -------------------------------------------------------------------
gSeparator constant varchar2(1) := chr(29);
gSepLength pls_integer := length(gSeparator); gKeys varchar2(4096) := gSeparator;
gValues varchar2(4096) := gSeparator;
--
function getPos(pKey varchar2) return pls_integer
is
cnt pls_integer := 0;
pos pls_integer := 0;
sep pls_integer := 1;
begin
if gKeys = gSeparator then return 0; end if;
pos := instr(gKeys, pKey || gSeparator);
if pos = 0 then return 0; end if;
--
while sep > 0 and sep <= pos loop
cnt := cnt + 1;
sep := instr(gKeys, gSeparator, sep+gSepLength);
end loop;
return cnt;
end getPos;
--
procedure put(pKey varchar2, pValue varchar2)
is
idx pls_integer := 0;
posStart pls_integer := 0;
begin
idx := getPos(pKey);
if idx = 0 then -- new key, add to end
gKeys := gKeys || pKey || gSeparator;
gValues := gValues || pValue || gSeparator;
else -- replace value for existing key
posStart := instr(gValues, gSeparator, 1, idx);
gValues := substr(gValues, 1, posStart + (gSepLength -1) ) ||
pValue ||
substr(gValues, instr(gValues, gSeparator, posStart+gSepLength, 1));
end if;
end put;
--
function get(pKey varchar2) return varchar2
is
idx pls_integer := 0;
lStart pls_integer := 0;
lEnd pls_integer := 0;
begin
idx := getPos(pKey);
if idx = 0 then return ''; end if;
--
lStart := instr(gValues, gSeparator, 1, idx);
lEnd := instr(gValues, gSeparator, lStart+gSepLength, 1);
return substr(gValues, lStart+gSepLength, lEnd-lStart-gSepLength);
end get;
--
procedure remove(pKey varchar2)
is
idx pls_integer := 0;
lStart pls_integer := 0;
lEnd pls_integer := 0;
begin
idx := getPos(pKey);
if idx = 0 then return; end if; -- key doesn't exist, nothing to do.
--
lStart := instr(gValues, gSeparator, 1, idx);
lEnd := instr(gValues, gSeparator, lStart+gSepLength, 1);
gValues := substr(gValues, 1, lStart) || substr(gValues, lEnd+gSepLength);
--
lStart := instr(gKeys, gSeparator, 1, idx);
lEnd := instr(gKeys, gSeparator, lStart+gSepLength, 1);
gKeys := substr(gKeys, 1, lStart) || substr(gKeys, lEnd+gSepLength);
end remove;
--
function getKeyString return varchar2 is
begin
return gKeys;
end getKeyString;
--
function getValueString return varchar2 is
begin
return gValues;
end getValueString;
--
function getSeparator return varchar2 is
begin
return gSeparator;
end getSeparator;
--
END PMDC;