PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "Larry Martell" <larrym at imsi dot com>
Subject: Re: Client and Server messages
Date: Jul 21 1998 7:19PM

Try setting STDERR and STDOUT for unbuffered output, e.g.:

select(STDERR); $| = 1;
select(STDOUT); $| = 1;


larry


On Jul 21, 14:11, Natarajan (Ravi) Murugaiyan wrote:
> Subject: Client and Server messages
>
>
> I have a need in my sybperl script to log client and server messages to a
> log file.
> All server messages by default come to the xterm. I tried
> to redirect STDERR and STDOUT to logfile as follows:
> 	$ myscript >> logfile 2>&1
> With this approach, server messages are not logged to 'logfile' in the right
> order.  That is, I see server messages(from a stored procedure) even before
> debug output which indicates that a stored procedure is going to be executed.
>
> I tried to register my own client and server message callbacks.
> The callbacks were copied from the code in lib/site_perl/ctutil.pl with
> STDERR changed to my log file handle. When I do this, I get several
> client messages which I don't know how to get around.
>
> Here is a test program which has my own client and server message callbacks:
>
> -----------------------------------------------------------
> use Sybase::CTlib;
>
>
> open(OUTFILE, ">> logfile") || die " cannot open logfile";
>
> $conn = Sybase::CTlib->ct_connect('murugaiy', , 'SYBASE');
>
> ct_callback(CS_CLIENTMSG_CB, \&my_msg_cb);
>
> ct_callback(CS_SERVERMSG_CB, \&my_srv_cb);
>
> $cmd = "use pubs";
>
> if ($conn->ct_sql($cmd)) {
>            print OUTFILE "$cmd succeeded\n"
> } else {
>            print OUTFILE "$cmd failed\n";
> }
>
>
> sub my_msg_cb {
>
> my ($layer, $origin, $severity, $number, $msg, $osmsg) = @_;
>
> printf OUTFILE "\nOpen Client Message: (my_msg_cb)\n";
> printf OUTFILE "Message Number: LAYER = (%ld) ORIGIN = (%ld) ",
>                                 $layer, $origin;
> printf OUTFILE "SEVERITY = (%ld) NUMBER = (%ld) \n",
>                                 $severity, $number;
> printf OUTFILE "Message String: %s\n", $msg;
>
> if (defined($osmsg)) {
>         printf OUTFILE "Operating System Error: %s\n", $osmsg;
> }
>
> CS_SUCCEED;
> }
>
>
> sub my_srv_cb {
>
> my($cmd, $number, $severity, $state, $line, $server, $proc, $msg) = @_;
>
>
> if ($severity > 10) {
>         printf OUTFILE "\n Server message: (my_srv_cb)\n";
>         printf OUTFILE "Message number: %ld, Severity %ld, ",
>                                                 $number, $severity;
>         printf OUTFILE "State %ld, Line %ld\n", $state, $line;
>
>         if (defined($server)) {
>                 printf OUTFILE "Server '%s'\n", $server;
>         }
>
>         if (defined($proc)) {
>                 printf OUTFILE "Procedure '%s'\n", $proc;
>         }
>
>         print OUTFILE "Message String: $msg\n";
> }
>
> }
>
>
> When I run this script, I see following messages in the "logfile":
>
> use pubs succeeded
>
> Open Client Message: (my_msg_cb)
> Message Number: LAYER = (1) ORIGIN = (1) SEVERITY = (1) NUMBER = (50)
> Message String: ct_results(): user api layer: external error: The connection
has
>  been marked dead.
> use pubs succeeded
>
> Open Client Message: (my_msg_cb)
> Message Number: LAYER = (1) ORIGIN = (1) SEVERITY = (1) NUMBER = (50)
> Message String: ct_cmd_drop(): user api layer: external error: The connection
ha
> s been marked dead.
>
> When the two calls to 'ct_callback()' are commented out, above messages
> disappear.
>
>
> How can I get around these messages?
>
>
> Is there a better way to log client and server messages to a log file?
>
> Thanks,
> -------------------------------------------------------------------------
> Natarajan Murugaiyan(Ravi) 		Phone 	(217) 333 - 1112
> Alliance Information Management	  	Email   murugaiy@ncsa.uiuc.edu
> 270 CAB(Mail Code 476)
> NCSA, University of Illinois at Urbana/Champaign
>
>-- End of excerpt from Natarajan (Ravi) Murugaiyan