oos-utils
oos-utils copied to clipboard
Functions to convert a key value pair to a formatted string
The functions are mainly useful for logging.
Example:
v_foo := 42;
-- returns a string: '(v_foo = 42)'
kvn('v_foo', v_foo);
kv('v_foo', v_foo);
v_bar := null;
-- returns a string: '(v_bar = NULL)'
kvn('v_bar', v_bar);
-- returns an empty string (null)
kv('v_bar', v_bar);
Proposed function declarations for common types:
--
-- Return a string: (p_key = p_value) and if p_value is null: (p_key =
-- NULL). Useful for logging.
--
function kvn(p_key in varchar2, p_value in varchar2) return varchar2;
function kvn(p_key in varchar2, p_value in number) return varchar2;
function kvn(p_key in varchar2, p_value in date,
p_fmt in varchar2 default 'YYYY-MM-DD HH24:MI:SS')
return varchar2;
function kvn(p_key in varchar2, p_value in boolean) return varchar2;
--
-- Return a string: (p_key = p_value) and empty string (null) if p_value is
-- null. Useful for logging.
--
function kv(p_key in varchar2, p_value in varchar2) return varchar2;
function kv(p_key in varchar2, p_value in number) return varchar2;
function kv(p_key in varchar2, p_value in date,
p_fmt in varchar2 default 'YYYY-MM-DD HH24:MI:SS')
return varchar2;
function kv(p_key in varchar2, p_value in boolean) return varchar2;
@janihur This sounds similar to what we use for Logger: https://github.com/OraOpenSource/Logger/blob/master/docs/Logger%20API.md#append_param
If this is primarily for logging then perhaps we may not need to add it as Logger has this main feature.
I checked the logger. Yes - the feature is essentially the same. I use these functions to feed data to my super simple logging "framework" that eats strings only (varchar2 and clob). The main reason why variable stringification and logging are separate is A) the evolution of the legacy system I'm current working with and B) the need to feed the same data to different logging systems.
In one way it makes sense to have this with logger but on the other hand I don't think one should assume too much what other libraries oos-util users have available. IMO from oos-util point of view it's irrelevant what features other OraOpenSource projects have.
I think that I'll work on the feature a bit more in https://github.com/janihur/oos-utils-sandbox as I got some inspiration from the Logger. I will let you (@martindsouza) know here when ready. I might also introduce my logging system there (even I think it's not in the scope of oos-util, but maybe an alternative for Logger). Meanwhile this issue can be labelled with enhancement/future/whatever.
An example of the usage scope of kv and kvn functions is now available in https://github.com/janihur/oos-utils-sandbox/blob/master/oos_issue_91_example.sql
I agree with @janihur. The fact that oos-utils is (will be) used in a project does not imply that Logger is used too.
@janihur I agree that we should not assume dependancies on Logger or any other packages.
I've tagged this for a future release. For 1.0.0 we won't add it in.