Click to See Complete Forum and Search --> : Which method is a better way to code?


gandolf989
12-08-2005, 07:44 PM
let the logging package decide when to log.


BEGIN
my_log_package.start_logging (
'test', 'test', my_log_package.g_no_logging,
TRUE, FALSE, 80 );

FOR i IN 1..10000000
LOOP
my_log_package.record_event('TEST','TRUE',
my_log_package.g_detail_logging);
END LOOP;
END;
/


or putting an if statement in the code to decide
whether or not to call the logging package.

BEGIN
my_log_package.start_logging (
'test', 'test', my_log_package.g_no_logging,
TRUE, FALSE, 80 );

FOR i IN 1..10000000
LOOP
IF my_log_package.g_detail_logging <=
my_log_package.g_no_logging
THEN
my_log_package.record_event('TEST','TRUE',
my_log_package.g_detail_logging);
END IF;
END LOOP;
END;
/

Scorby
12-09-2005, 05:22 AM
I would go for the first one because the logging leaves less of a footprint in the code. Also, a lot of people think it's a bad idea to accesss the global variables of another package directly - you should always do it via some sort of function, so that you have more control over what is done to the variable. You can always check the global variable as the first statement in the start_logging package. Either way, you're having to make a call to the get_logging package - either to call the function or to access its global variable, so I doubt if there would be much difference in performance.

gandolf989
12-09-2005, 11:29 AM
I would go for the first one because the logging leaves less of a footprint in the code. Also, a lot of people think it's a bad idea to accesss the global variables of another package directly - you should always do it via some sort of function, so that you have more control over what is done to the variable. You can always check the global variable as the first statement in the start_logging package. Either way, you're having to make a call to the get_logging package - either to call the function or to access its global variable, so I doubt if there would be much difference in performance.

The variable is really a constant. And using a constant in the header might have less of an impact of performance than using a funtion. I ran the segments of code through 100 million loops and with that number of executions there was an 18 minute difference in time. However over 10 million executions the difference was only about 10 seconds. I don't plan on the code being executed that many times.

slimdave
12-09-2005, 12:36 PM
I like option 1

gandolf989
12-09-2005, 01:20 PM
I like option 1

Even though it might take up an extra 7 - 10 minutes over 100 million executions and the average procedure will have 3-4 logging statements? :rolleyes: I need to justify the change in the logging package to my boss, who is a Java programmer. The old logging package had hardcoded values with if statements all over the place and did not log messages evenly. We only have 10 packages spread over two schemas. I also want to combine the schemas. There is a separate schema for logging, and I don't see why we need to keep that separate.

slimdave
12-09-2005, 04:09 PM
7-10 minutes out of how many total?

It depends as well on how many places you call this from. If you call my_log_package.start_logging from twenty different places it would be crazy to repeat the same g_detail_logging check in all of them.