Override compile time log levels of specific messages/modules
Override compile time log levels of specific messages/modules
PostgreSQL Development, 24x7 Support, Training & Services
Re: Override compile time log levels of specific messages/modules
On 6 Sep. 2016 17:28, "Pavan Deolasee" <pavan.deolasee@gmail.com> wrote:
>>
> The patch uses some preprocessing and scripting magic to assign distinct identifiers to each module (a subdir in the source code), to each file and to each elog message. It then provides a set of functions by which an user can increase/decrease/set log levels for either individual messages or all messages within a source file or source module. The log levels can be changed only for specific backends or all current or future backends. If you configure with --enable-genmsgids switch, a MSGMODULES and MSGIDS file is created in $srcdir, which can later be used to know ids assigned to various modules/messages.I think it's worth looking at how Java handles logging. We can't achieve an exact parallel in C as we don't really have a class hierarchy ... but we do have subsystems roughly grouped by file and directory structure.
Being able to promote/demote these or selective lower the log level threshold on a directory, file, function and line level would be exceedingly handy. Pretty much all of that can be magic'd up from macro output so hopefully no postprocessing should be needed. (Though only gcc has _FUNC_ or _FUNCTION_ I think so we'd have selective support there.)
Re: Override compile time log levels of specific messages/modules
I think it's worth looking at how Java handles logging. We can't achieve an exact parallel in C as we don't really have a class hierarchy ... but we do have subsystems roughly grouped by file and directory structure.
Being able to promote/demote these or selective lower the log level threshold on a directory, file, function and line level would be exceedingly handy. Pretty much all of that can be magic'd up from macro output so hopefully no postprocessing should be needed. (Though only gcc has _FUNC_ or _FUNCTION_ I think so we'd have selective support there.)
PostgreSQL Development, 24x7 Support, Training & Services
Re: Override compile time log levels of specific messages/modules
On 6 Sep. 2016 17:57, "Pavan Deolasee" <pavan.deolasee@gmail.com> wrote:
>
>
>
> On Tue, Sep 6, 2016 at 3:06 PM, Craig Ringer <craig.ringer@2ndquadrant.com> wrote:
>>
>>
>> I think it's worth looking at how Java handles logging. We can't achieve an exact parallel in C as we don't really have a class hierarchy ... but we do have subsystems roughly grouped by file and directory structure.
>
> Sure. In some large, popular enterprise softwares I've worked with many years ago, we used to define modules within each source file and then manually assign distinct integer IDs to each message and then provide various utilities to turn on/off specific messages or range of messages within a module.Yeah, there same has been discussed for Pg many times and firmly shot down each time. I certainly see the argument against making specific elog calls part of a sort of api people might expect to be stable ish. That's what we have ERRCODE / SQLSTATE for right? Concerns about backpatch pain were also raised. Probably more. I'm not especially for or against it myself, just saying that based on past discussion such a proposal isn't likely to fly.
I think something automatic that we clearly define as unstable and not to be relied upon would be preferable. Plus we already have much of the infrastructure in elog.c as used by errcontext etc.
> Well, __FUNCTION__ expands to function name and lookup based on string identifiers will always be costly, especially if you want to sprinkle the code with lot many debug messages. Same with __FILE__. I believe we need an unique integer constant to make it a fast, O(1) lookup. I couldn't find any other method to do that when I wrote the facility and hence did what I did.
Yeah. High performance logging and filtering isnt easy. Looking at existing C logging libraries with dynamic filtering might be informative. Though I can't imagine there being agreement to adopt one, this must be a reasonably solved problem...
>
> Thanks,
> Pavan
> --
> Pavan Deolasee http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Training & Services
Re: Override compile time log levels of specific messages/modules
On 9/6/16 5:18 AM, Craig Ringer wrote: > I think something automatic that we clearly define as unstable and not > to be relied upon would be preferable. Plus we already have much of the > infrastructure in elog.c as used by errcontext etc. Actually, I wish this was a straight-up logging level feature, because I need it all the time when debugging complicated user-level code. Specifically, I wish there was a GUC that would alter (client|log)_min_messages upon entering a specific function, either for just that function or for anything that function subsequently called. Bonus points if you could also specify a regex that the message text had to match. I realize that code-wise that's completely incompatible with what you're discussing here, but I think the same API could be used (maybe as a different GUC). -- Jim Nasby, Data Architect, Blue Treble Consulting, Austin TX Experts in Analytics, Data Architecture and PostgreSQL Data in Trouble? Get it in Treble! http://BlueTreble.com 855-TREBLE2 (855-873-2532) mobile: 512-569-9461
Re: Override compile time log levels of specific messages/modules
On 11 Sep. 2016 11:31, "Jim Nasby" <Jim.Nasby@bluetreble.com> wrote:
> Actually, I wish this was a straight-up logging level feature, because I need it all the time when debugging complicated user-level code. Specifically, I wish there was a GUC that would alter (client|log)_min_messages upon entering a specific function, either for just that function or for anything that function subsequently called.
We have that or close to it, but it's restricted for security. IIRC you can't SET log_min_messages as non superuser including as part of CREATE FUNCTION ... SET. Presumably because lowering it would let the user hide activity admins expect to be recorded. Raising it would let them possibly DoS via log spam - though that argument is rather undermined by the ability to write plpgsql that does RAISE in a tight loop.
I'd like to be able to let users make logging more detailed but not less, so they can only SET it to something equal to or more detailed to what their session has art the start. Should actually be pretty trivial to implement too.
You can then SET at session level, function level, SET LOCAL, etc. If you want to control it dynamically via GUC you add calls to your functions to check a custom user GUC and SET log level accordingly. Using whatever logic you like.
> Bonus points if you could also specify a regex that the message text had to match.
>An errfinish() hook would be nice for that.