Re: [mh] Your help re Genericising Error and log handling
Brian M <[email protected]>
| Newsgroups | gmane.comp.misc.misterhouse.user |
|---|---|
| Message-ID | <[email protected]> |
I like this approach. I know there have been some tweaks in subsequent
posts, and that's fine, but generally I think the overall direction is
good. Just make sure print_log_private gets into the docs, please.
-Brian M.
On 1/13/21 1:49 AM, Giles Godart-Brown wrote:
>
> Summarising the comments ; the desire is for print_log to be called
> unchanged for legacy apps, but to allow developers to intercept
> print_log requests and route them accordingly (email, SMS, growl,
> print, tasker, IFTTT...) and to do this with the minimum impact
>
> Here is what I have built and tested today. If its OK with the forum,
> I'll create a pull request.
>
> <changes to mh>
>
> # 13-jan-2021 new print_log added and old print_log renamed
> print_log_simple to allow
> # 1) optional additional parameters severity and source
> # severity should be one of EMERGENCY, ALERT, CRITICAL,
> # ERROR, WARNING, NOTICE, INFORMATIONAL, or DEBUG
> # message is reformatted as [source] severity message
> # 2) substitution of print_log_private() if it exists and severity is
> defined
> # otherwise functions as the old print_log
> sub print_log {
> my ($message,$severity,$source) = @_;
>
> if (defined($severity)) {
> if (defined(&print_log_private)) {
> print_log_private($message,$severity,$source);
> return;
> }
> $message = $severity . " " . $message;
> }
> if (defined($source)) {
> $message = "[" . $source . "] ". $message;
> }
> print_log_simple($message);
> }
>
>
> # renamed from print_log
> sub print_log_simple {
>
> </changes to mh>
>
> *And here are the test cases;*
>
> *test 1 without a print_log_private()*
>
> print_log("message"); produces 13/01/2021 09:23:48 message
>
> print_log("message","WARNING"); produces 13/01/2021 09:23:48 WARNING
> message
>
> print_log("message","ERROR","source"); produces 13/01/2021 09:23:48
> [source] ERROR message
>
> t*est 2 with a print_log_private() *that prepends 'print_log_private'
> to the source and calls print_log_simple() (see attached)
>
> print_log("message"); produces the following because severity wasn't
> set and so print_log_private not called 13/01/2021 09:27:23 message
>
> print_log("message","WARNING"); produces 13/01/2021 09:27:23
> [print_log_private] WARNING message
>
> print_log("message","ERROR","source"); produces 13/01/2021 09:27:23
> [print_log_private-source] ERROR message
>
> Giles
>
> On 12/01/2021 20:10, Brian M wrote:
>>
>>
>> On 1/12/21 11:00 AM, Rick Steeves wrote:
>>> Might it not make more sense to modify print_log, so that, as is, it
>>> keeps working as expected, but in any case that print_log was called
>>> with more than one parameter then new things happened?
>>>
>>> That makes all the existing code keep working, but new code (or
>>> people modifying existing code) could just add parameters.
>>>
>>> If you were going to do a search/replace for print_log, you're still
>>> going to have to find all the cases of it and manually adjust them
>>> for what you want to have happen.
>>>
>>> That would avoid creating a new function, have it keep working as-is
>>> in all the existing code, and let it be adjusted on a case-by-case
>>> basis.
>>
>>
>> I agree with Rick.
>>
>>
>>
>>
>> ________________________________________________________
>> To unsubscribe from this list, go to:
>> https://lists.sourceforge.net/lists/listinfo/misterhouse-users
>>
________________________________________________________
To unsubscribe from this list, go to: https://lists.sourceforge.net/lists/listinfo/misterhouse-users