tmuth / Logger---A-PL-SQL-Logging-Utility

Logger is used by Oracle developers to instrument their PL/SQL code
55 stars 145 forks source link

Substitution Strings #32

Closed martindsouza closed 9 years ago

martindsouza commented 11 years ago

Thanks to John Scott for this idea.

Would like the ability to support substitution strings. For example: "Updated %num_rows% in table out of %total_rows%".

John and I discussed possible implementation options. For now here's what is purposed:

Ex:

logger.append_param(l_params, 'p_empno', p_empno);
logger.log('Employee %P_EMPNO%', p_params => l_params, p_do_substitutions => true)

Alternatively, instead of p_do_substitutions we can us p_param_type with 'DEFAULT'/'PARAMS' and 'SUBSTITUTION' (or something like that). We can create global constants to manage. This may be the better option.

martindsouza commented 10 years ago

This is still very much up for debate as to how to implement this. Several options:

  1. Recommend developers to just use sys.utl_lms.format_message (see http://vbegun.blogspot.ca/2005/10/simple-plsql-printf.html)
    • Pro: Build right into Oracle and no work from Logger
    • Con: Only supported 10g and up
  2. Build a wrapper to handle functionality
    • Wrapper would use sys.utl_lms.format_message if available

Decision: Built a wrapper to support option 2. This just takes in a set of strings for the substitution strings.

Example:

declare
  l_ename varchar2(255) := 'bob';
  l_sal number := 3;
  l_scope logger_logs.scope%type := 'test';
begin
  logger.log(logger.get_fmt_msg('My name is %s. My sal is %d. Unreferenced: %s', l_ename, l_sal), l_scope);
end;
/

My name is bob. My sal is 3. Unreferenced:

Still need to decide how to implement this:

  1. Use function (like above) and all other logger calls behave as is.
  2. Create a new procedure called printf (or similar) that looks like: logger.printf(p_msg, p_s01, p_s02..., p_scope, p_level)
    • User would need to explicitly defined scope and level each time. This could slow down development time.
  3. Write wrapper functions for printf. ex: logger.log_printf(p_msg, p_scope, p_s01 ...)
    • Again, names are up for debate

My preference is for option 1 as it keeps things consistent with logger. If we keep option 1 need to determine name.

  1. get_fmt_msg
  2. f
  3. getf
  4. printf

Though printf is more standard, it is not a true "print" procedure as it's not printing, rather returning a value.

rimblas commented 10 years ago

I like the printf idea and sys.utl_lms with a wrapper sounds like the perfect way to go. My suggestion, add "f" or "printf" as a function that log can use. logger.log(logger.f(p_msg, p_arg1, p_arg2...), p_scope);

Alternatively, there would be value to a "logf" that merges log and printf into one call. In this case I would just have scope as the first parameter and forgo the others and follow with msg and args. Perhaps even skip the scope and set it manually in a separate call as you had mentioned. That seems like a useful approach too.

JuergenSchuster commented 10 years ago

I'm not a 100% sure if I understood Jorge's approach, but if it is working the way I think it is, I like the idea, and the printf :-)

goodwish commented 9 years ago

When will 2.2.0 release?

Thanks, Charlie 木匠 | DBA

goodwish commented 9 years ago

Howdy,

When will we get this feature ? Is there an estimate ?

Or, can I contribute on it?

Thanks, Charlie 木匠 | Database Architect Developer

martindsouza commented 9 years ago

This issue was moved to OraOpenSource/Logger#32