From: | Andrew Perrin <clists(at)perrin(dot)socsci(dot)unc(dot)edu> |
---|---|
To: | David Wheeler <david(at)wheeler(dot)net> |
Cc: | Bruno Wolff III <bruno(at)wolff(dot)to>, pgsql-admin(at)postgresql(dot)org |
Subject: | Re: Silencing NOTICEs in Perl Pg |
Date: | 2002-08-30 16:01:46 |
Message-ID: | Pine.LNX.4.21.0208301159170.27669-100000@perrin.socsci.unc.edu |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-admin |
I don't know the Pg module at all, but if it uses warn() to dump those
notices to STDERR, you can use a sig handler to catch them:
$SIG{'__WARN__'} = sub {
return if $_[0] =~ /^NOTICE:/;
print STDERR join ("\n",@_);
print STDERR "...at line " . caller(1) . "\n";
}
----------------------------------------------------------------------
Andrew J Perrin - http://www.unc.edu/~aperrin
Assistant Professor of Sociology, U of North Carolina, Chapel Hill
clists(at)perrin(dot)socsci(dot)unc(dot)edu * andrew_perrin (at) unc.edu
On Thu, 29 Aug 2002, David Wheeler wrote:
> On Thursday, August 29, 2002, at 01:02 PM, Bruno Wolff III wrote:
>
> > On Thu, Aug 29, 2002 at 12:17:16 -0700,
> > David Wheeler <david(at)wheeler(dot)net> wrote:
> >> BTW, I missed the beginning of this thread, but based on the subject,
> >> I'd sure like to find out if there's a simple way to suppress NOTICEs
> >> using DBI/DBD::Pg. I've tried a number of tricks, but short of closing
> >> STDOUT and STDERR in my Perl script, I've not found a way to do it.
> >> PrintError => 0 doesn't do the trick.
> >
> > I do the following before doing anything with the database:
> > open(OLDERR, '>&STDERR');
> > close(STDERR);
> > open(STDERR, '>/dev/null');
>
> Thanks for the suggestion. Unfortunately, that doesn't allow me to
> filter out just the NOTICEs, and let everything else be printed. The
> solution I've come up with, for those who are interested, is either
> this:
>
> open STDERR, "| perl -e 'while (<>) { print unless /^NOTICE: / }'"
> or die "Cannot pipe STDERR: $!\n";
>
> Or this:
>
> open STDERR, "| grep -v '^NOTICE: '"
> or die "Cannot pipe STDERR to grep\n";
>
> The former will be more portable, since we already know we have Perl ;-)
>
> Thanks for the help!
>
> David
>
> --
> David Wheeler AIM: dwTheory
> david(at)wheeler(dot)net ICQ: 15726394
> http://david.wheeler.net/ Yahoo!: dew7e
> Jabber: Theory(at)jabber(dot)org
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Treat | 2002-08-30 16:04:32 | Re: Postgres Hidden Pitfalls |
Previous Message | Robert Treat | 2002-08-30 15:57:41 | Re: Running postgres on a read-only file system |