In preparation for the release of Logger 2.0.0 I’ve decided to write a few posts highlighting some of the new features.
After using Logger for several years one thing I found that I was doing over and over again is logging the parameters to functions and parameters. The beginning of a procedure usually looked like this:
p_empno in number,
p_hiredate in date,
p_boolean in boolean) -- not really relevant for proc, but good for demo
l_scope logger_logs.scope%type := 'my_proc';
logger.log('p_empno: ' || to_char(p_empno), l_scope);
logger.log('p_hiredate: ' || to_char(p_hiredate, 'DD-MON-YYYY HH24:MI:SS'), l_scope);
logger.log('p_boolean: ' || case when p_boolean then 'TRUE' else 'FALSE' end, l_scope);
When you have data types that aren’t strings the conversion process can become a bit tedious especially if you have to log a lot of parameters. Of course snippets can help reduce some of the time but it was still annoying.
Another issue that I found was that developers would use their own formatting for logging parameters. Some would include a dash instead of a colon, some would include spaces and others wouldn’t, etc. Eventually it became difficult to read the logs with all the different formatting.
To get around these issues Logger now takes in a parameter,
p_params, which is an array of name/value pairs. Besides visual consistency, it will also handle all the formatting of the different data types so you don’t need to spend time on it. The following code snippet is the same as above, but using the new parameters feature:
If you now query
logger_logs you’ll now see the parameters appended to the
extra column (note if you defined something in the
p_extra parameter it would still appear):
select text, scope, extra
You’ll notice that all the formatting and implicit conversions have been taken care of.
Unless you are running Logger in no-op mode then there will be a slight performance hit each time you append a parameter (for the cost of appending to an array and implicit conversion). You’ll need to factor this in when leveraging this feature. Odds are you’ll be able to use the
p_params parameter on most of your procedures and functions, but not on frequently used methods.
Not all people will use the parameters option, and that’s fine. We made it an optional parameter specifically for that reason. We added this feature to support one of the primary goals of Logger which is “to be as simple as possible to use”.