| [reply] |
Derby,
Thank you for the reply. I am very new to this DB modules of PERL. I have seen the examples link earlier. What I found out was, I can print the message code and message statements on standard error or console. But, what I need is to capture the entire message in a single string.
I came to know that "CS_HAFAILOVER" variable will hold the Error code. Similarly, do we have any vatiable which holds the entire error message, because I need to print the error message in a Log file
| [reply] |
| [reply] |
package Foo;
sub foo { warn "blorf!" }
1;
#!/usr/bin/perl
use Foo;
use strict;
use warnings;
sub call (&);
call {
Foo::foo();
};
if ($@) {
warn "foo reported: '$@'\n";
}
## subs
#
sub call (&) {
my $coderef = shift;
my $message;
open my $fh , '>&', \*STDERR;
close STDERR;
open STDERR, '>', \$message;
$coderef->();
open STDERR, ">&", $fh;
$@ = $message;
}
__END__
foo reported: 'blorf! at Foo.pm line 3.
'
That way all you have to do is wrap the places where you call into Sybase::CTlib into a block and dispatch that to the call() function. | [reply] [d/l] [select] |
Hi shmem,
Thank you very much.
I have executed the above code, and I have got the expected result.
I still need some help. Sorry if it is silly.
Still, my question is,
where can I send the below err statements into log file. I have tried them and was not able to throw into log file.
ct_callback(CS_CLIENTMSG_CB, \&msg_cb);
ct_callback(CS_SERVERMSG_CB, "srv_cb");
sub msg_cb {
my($layer, $origin, $severity, $number, $msg, $osmsg, $dbh) = @_;
printf STDERR "\nOpen Client Message: (In msg_cb)\n";
printf STDERR "Message number: LAYER = (%ld) ORIGIN = (%ld) ",
$layer, $origin;
printf STDERR "SEVERITY = (%ld) NUMBER = (%ld)\n",
$severity, $number;
printf STDERR "Message String: %s\n", $msg;
if (defined($osmsg)) {
printf STDERR "Operating System Error: %s\n", $osmsg;
}
CS_SUCCEED;
}
sub srv_cb {
my($dbh, $number, $severity, $state, $line, $server,
$proc, $msg) = @_;
# If $dbh is defined, then you can set or check attributes
# in the callback, which can be tested in the main body
# of the code.
printf STDERR "\nServer message: (In srv_cb)\n";
printf STDERR "Message number: %ld, Severity %ld, ",
$number, $severity;
printf STDERR "State %ld, Line %ld\n", $state, $line;
if (defined($server)) {
printf STDERR "Server '%s'\n", $server;
}
if (defined($proc)) {
printf STDERR " Procedure '%s'\n", $proc;
}
printf STDERR "Message String: %s\n", $msg; CS_SUCCEED;
}
please, help required...
Thanks in advance!!!
| [reply] |
open file, print to filehandle you opened, close filehandle
| [reply] |