Addition to LOG4PLSQL to make loglevel adjustments at runtime. americas cup win 2682133k1

Addition to LOG4PLSQL to make loglevel adjustments at runtime.

I have recently used the LOG4PLSQL software for logging in a small application. I missed the possibility to change the logging level at runtime. In the production environment code changes are only allowed during specified deploy time windows, so changing the DEFAULT_LEVEL parameter in the PLOGPARAM package specification was not an option to change the logging level.

I adjusted the DEFAULT_LEVEL constant in the BLOGPARAM package to a function with the name DEFAULT_LEVEL, returning the level as it is stored in the database (In a table with global parameters for the application). To avoid a read of this table everytime the DEFAULT_LEVEL is used in the logging code, I store the value in a package variable (lv_default_level).

The package variable is updated at regular intervals (lv_check_db_interval), to avoid that changing the database parameter only will have effect on the sessions that are started after the parameter change.
code of the package specification


CREATE OR REPLACE PACKAGE PLOGPARAM IS
/**
* package name : PLOGPARAM
*
*
*See : http://log4plsql.sourceforge.net
*
*
*Objectif : Store updatable paramter for PLOG.
*

* This package is create befort PLOG
*

*
*
*@headcom
*
*
*
*History who date comment
*V3 Guillaume Moulard 05-AUG-03 Creation
*
*
* 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:

*
*/

-------------------------------------------------------------------
-- Constants (tools general parameter)
-- you can update regard your context
-------------------------------------------------------------------

-- LERROR default level for production system.
-- DEFAULT_LEVEL CONSTANT TLOG.LLEVEL%type := 30 ; -- LERROR
-- LDEBUG for developement phase
-- adjusted by ddijksho to have availability to change logging on the fly
--- DEFAULT_LEVEL TLOG.LLEVEL%type := 70 ; -- LERROR
-- pkg variable to store date time in when global parameter table was last checked
-- for logging level.
--
lv_last_db_check date := to_date('01011999','ddmmyyyy');
lv_default_level TLOG.LLEVEL%type := 30; -- LERROR

-- number of seconds to wait for rechecking the db for any changes.
lv_check_db_interval constant integer := 60;

-- 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 := lv_default_level ;

-- default level for call_stack_level
DEFAULT_FULL_CALL_STACK_LEVEL CONSTANT TLOG.LLEVEL%type := lv_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';

function default_level return TLOG.LLEVEL%type;

END PLOGPARAM;
/

The code of the package body:


PLACE PACKAGE BODY PLOGPARAM IS

--
-- This function wil get LOG_LEVEL parameter from global_parameters table
-- if no parameter value found default will be returned.
--
function get_default_level_param return TLOG.LLEVEL%type
is
cursor c_gpa (b_gpa_name in varchar2) is
select gpa.GPA_VALUE_INTEGER
from global_parameters gpa
where gpa.gpa_name = b_gpa_name
;
r_gpa c_gpa%rowtype;
l_found boolean;
begin
open c_gpa('LOG_LEVEL');
fetch c_gpa into r_gpa;
l_found := c_gpa%found;
close c_gpa;
if l_found then
return r_gpa.GPA_VALUE_INTEGER;
else
return lv_default_level;
end if;
exception
when others
then
if c_gpa%isopen
then
close c_gpa;
end if;
return lv_default_level;
end;

--
-- function to return the default_level
-- will check the database if the interval time has passed and update the
-- package variable lv_default_level.
--
function default_level return TLOG.LLEVEL%type is
lv_date date;
begin
lv_date := lv_last_db_check+(lv_check_db_interval/(3600*24));
-- dbms_output.put_line(' time last check = '||to_char(lv_date,'ddmmyyyy hh24:mi:ss'));
-- dbms_output.put_line(' time sysdate = '||to_char(sysdate,'ddmmyyyy hh24:mi:ss'));
if (lv_date < sysdate ) then -- dbms_output.put_line(' set level'); lv_default_level := get_default_level_param; lv_last_db_check := sysdate; else null; end if; return lv_default_level; end default_level; END PLOGPARAM; /

4 Comments

  1. Sagarwal February 20, 2008
  2. amihay November 23, 2007
  3. vinod May 9, 2007
  4. amihay January 24, 2005