FAQ
I would look to using Log::Log4perl for all your logging needs. But for
what you are doing try setting $| = 1 (autoflush).

________________________________

From: Vergara, Michael (TEM)
Sent: Wednesday, November 09, 2005 1:25 PM
To: dbi-users@perl.org
Subject: Logging Question


Hello Everyone:

I have a Perl script that connects to multiple Oracle databases. I have
the script write some status information to
a log file. There is one particular database that hangs in processing,
and I don't know why. The log file does not seem
to be written until the file is closed.

I am wondering, is there a Perl command or technique that will force
lines that are logically written to a log file to be
physically written to that file?

Here's my opening code:
#
#
------------------------------------------------------------------------
-
# Open Log file
#
------------------------------------------------------------------------
-
my $logFileName = "${HomeDir}/work/monitor/output/logs/db_status.log";
open( LOGF, ">>" . $logFileName ) or die "\nCannot open log file\n\n";
print LOGF "\n----------\n";
print LOGF sprintf("db_status started at %02d-%02d-%04d
%02d:%02d:%02d\n",
$Tm->mon+1, $Tm->mday, $Tm->year+1900, $Tm->hour,
$Tm->min, $Tm->sec );


The line that says 'db_status started...' does not get written for the
hanging system because I usually 'kill -9' or 'Ctrl-C'
the process. I'd like to force a write after each section so I can see
there the process is hanging.

Any help will be appreciated.

Thanks,
Mike

________________________________

Michael P. Vergara Be good and you will be lonesome
Oracle Database Administrator Mark Twain
(951) 914-2000 (Voice)
(951) 914-2990 (FAX)
www.guidant.com <http://www.guidant.com/>

Any views expressed herein are not necessarily those of Guidant
Corporation.

Search Discussions

  • Chris Sarnowski at Nov 9, 2005 at 8:48 pm

    On Nov 9, 2005, at 3:40 PM, Ian Harisay wrote:

    I would look to using Log::Log4perl for all your logging needs.
    But for
    what you are doing try setting $| = 1 (autoflush).

    and on Nov 9, 2005, at 3:38 PM, Chris Sarnowski wrote:
    This is a perl issue, not a DBI issue, but try

    autoflush LOGF 1;

    after you open LOGF.

    This should force a flush after every print statement. If it
    doesn't work I hope that at least it points you the right direction.
    I hate to extend an off-topic thread too far, but
    $| = 1
    only works on the 'select'ed file handle (default STDOUT)

    and for my suggestion, you need to

    use FileHandle;

    -Chris
  • Chris Gehring at Nov 9, 2005 at 8:54 pm
    I agree, a bit off topic, but for my log files I use the following code:

    my $TempSelect = select( LOGF );
    $| = 1;
    select( $TempSelect );





    Chris Sarnowski <csarnows@pcbi.upenn.edu>
    11/09/2005 03:48 PM

    To
    dbi-users@perl.org
    cc

    Subject
    Re: Logging Question






    On Nov 9, 2005, at 3:40 PM, Ian Harisay wrote:

    I would look to using Log::Log4perl for all your logging needs.
    But for
    what you are doing try setting $| = 1 (autoflush).

    and on Nov 9, 2005, at 3:38 PM, Chris Sarnowski wrote:
    This is a perl issue, not a DBI issue, but try

    autoflush LOGF 1;

    after you open LOGF.

    This should force a flush after every print statement. If it
    doesn't work I hope that at least it points you the right direction.
    I hate to extend an off-topic thread too far, but
    $| = 1
    only works on the 'select'ed file handle (default STDOUT)

    and for my suggestion, you need to

    use FileHandle;

    -Chris
  • Vergara, Michael \(TEM\) at Nov 9, 2005 at 8:52 pm
    Eeewww! Not a good option!

    ______________________________________________________________________________

    Michael P. Vergara Be good and you will be lonesome
    Oracle Database Administrator Mark Twain
    (951) 914-2000 (Voice)
    (951) 914-2990 (FAX)
    www.guidant.com

    Any views expressed herein are not necessarily those of Guidant Corporation.


    -----Original Message-----
    From: Stephan Harren
    Sent: Wednesday, November 09, 2005 12:37 PM
    To: Vergara, Michael (TEM)
    Cc: dbi-users@perl.org
    Subject: Re: Logging Question

    Close the Filehandle and re-open it after each line.

    HTH,

    Stephan
    Hello Everyone:

    I have a Perl script that connects to multiple Oracle databases. I
    have the script write some status information to
    a log file. There is one particular database that hangs in
    processing, and I don't know why. The log file does not seem
    to be written until the file is closed.

    I am wondering, is there a Perl command or technique that will force
    lines that are logically written to a log file to be
    physically written to that file?

    Here's my opening code:
    #
    #
    -------------------------------------------------------------------------
    # Open Log file
    #
    -------------------------------------------------------------------------
    my $logFileName = "${HomeDir}/work/monitor/output/logs/db_status.log";
    open( LOGF, ">>" . $logFileName ) or die "\nCannot open log file\n\n";
    print LOGF "\n----------\n";
    print LOGF sprintf("db_status started at %02d-%02d-%04d %02d:%02d:%02d\n",
    $Tm->mon+1, $Tm->mday, $Tm->year+1900, $Tm->hour,
    $Tm->min, $Tm->sec );
  • Fuat Anat at Nov 9, 2005 at 9:02 pm
    Hi,

    I have the following error message when I try to connect to Oracle 10g DB
    from perl in Linux. Could you please help me.

    Best Regards
    Fuat Anat

    install_driver(Oracle) failed: Can't load
    '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so'
    for module DBD::Oracle: libclntsh.so.10.1: Kann die Shared-Object-Datei
    nicht öffnen: Datei oder Verzeichnis nicht gefunden at
    /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230.
    at (eval 1) line 3
    Compilation failed in require at (eval 1) line 3.
    Perhaps a required shared library or dll isn't installed where expected
    at ./conn.pl line 18


    My program is like following



    #!/usr/bin/perl -w
    # the -w turns on various warnings
    use strict; # always code strictly or you'll be sorry!
    use DBI;

    # create a database handle. the syntax for this is very flexible.
    # the quoted string second argument is of the form USERNAME/PASSWORD.
    # if the username is "scott" and the password is "tiger", then
    # the second parameter would be "scott/tiger".
    # if you want to connect using OS authentication as the current
    # unix id then you can omit the username and the password but
    # leave the slash, so the parameter would then be "/" (as shown).

    my $data_source = 'dbi:Oracle:myDB';
    my $username = 'user';
    my $password = 'pwd';

    my $dbh = DBI->connect($data_source, $username, $password)
    or die "Database connection not made: $DBI::errstr";





    __________________________________
    Start your day with Yahoo! - Make it your home page!
    http://www.yahoo.com/r/hs
  • Reidy, Ron at Nov 10, 2005 at 4:12 pm
    Is (at least) an Oracle client installed on the computer you are running this Perl program from?

    If so, did you properly install DBD::Oracle. Did you read the README* files that are part of the distro?

    --
    Ron Reidy
    Lead DBA
    Array BioPharma, Inc.

    -----Original Message-----
    From: Fuat Anat
    Sent: Wednesday, November 09, 2005 2:03 PM
    To: dbi-users@perl.org
    Subject: Problem


    Hi,

    I have the following error message when I try to connect to Oracle 10g DB from perl in Linux. Could you please help me.

    Best Regards
    Fuat Anat

    install_driver(Oracle) failed: Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so'
    for module DBD::Oracle: libclntsh.so.10.1: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230. at (eval 1) line 3 Compilation failed in require at (eval 1) line 3. Perhaps a required shared library or dll isn't installed where expected at ./conn.pl line 18


    My program is like following



    #!/usr/bin/perl -w
    # the -w turns on various warnings
    use strict; # always code strictly or you'll be sorry!
    use DBI;

    # create a database handle. the syntax for this is very flexible. # the quoted string second argument is of the form USERNAME/PASSWORD. # if the username is "scott" and the password is "tiger", then # the second parameter would be "scott/tiger". # if you want to connect using OS authentication as the current # unix id then you can omit the username and the password but # leave the slash, so the parameter would then be "/" (as shown).

    my $data_source = 'dbi:Oracle:myDB';
    my $username = 'user';
    my $password = 'pwd';

    my $dbh = DBI->connect($data_source, $username, $password)
    or die "Database connection not made: $DBI::errstr";





    __________________________________
    Start your day with Yahoo! - Make it your home page!
    http://www.yahoo.com/r/hs

    This electronic message transmission is a PRIVATE communication which contains
    information which may be confidential or privileged. The information is intended
    to be for the use of the individual or entity named above. If you are not the
    intended recipient, please be aware that any disclosure, copying, distribution
    or use of the contents of this information is prohibited. Please notify the
    sender of the delivery error by replying to this message, or notify us by
    telephone (877-633-2436, ext. 0), and then delete it from your system.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbi-users @
categoriesperl
postedNov 9, '05 at 8:40p
activeNov 10, '05 at 4:12p
posts6
users6
websitedbi.perl.org

People

Translate

site design / logo © 2022 Grokbase