Hello All,

I have a problem about logging in my code ( which is shared below ). My code is reading IBM MQ to get new data each 5 seconds. The code is working but logging is done once in 2 minutes. I mean when I tail the log file, I see it as nothing happens but then, after approximately 2 minutes logs appear as bulk, then stops again. While I'm expecting it to flow, like a normal log file should do, it does bulk printing to log file...

You can check the whole code below, and if there are wrong parts, please make me fix it. Thanks in advance.

#!/usr/bin/perl # IBM Message Queue Reader use warnings; use strict; use Config::Simple; use MQSeries; use MQSeries::Queue; use MQSeries::QueueManager; use XML::Simple; use POSIX; use Time::Local; use Data::Dumper; # Read MQ Settings from config file my $conf = new Config::Simple("/customS/config.ini"); my $qmgr = $conf->param('MQConf.QueueManager'); my $chnl = $conf->param('MQConf.ChannelName'); my $ipad = $conf->param('MQConf.IPAddress'); my $port = $conf->param('MQConf.Port'); my $qnam = $conf->param('MQConf.Queue'); my $xDir = $conf->param('Folder.XMLunread'); my ($queue,$qmgr_obj); while(1) { print "".(localtime)." - Trying to open Queue Manager: $qmgr w +ith Channel: $chnl ...\n"; # Open Queue Manager with defined settings if ( $qmgr_obj = MQSeries::QueueManager->new( QueueManager => $qmgr, ClientConn => { ChannelName => $chnl, TransportType => 'TCP', ConnectionName => "$ipad($port)", MaxMsgLength => 16 * 1024 * 1024 } ) ) { print "".(localtime)." - Queue Manager $qmgr has been +opened succesfully.\n"; } else { print "".(localtime)." - Can't connect to the queue ma +nager, quitting...\n"; } ;; ;; print "".(localtime)." - Trying to open Queue: $qnam...\n"; if ( # Open Queue with defined settings $queue = MQSeries::Queue->new( QueueManager => $qmgr_obj , Queue => $qnam , Mode => 'input' ) ) { print "".(localtime)." - Queue $qnam has been opened s +uccesfully.\n"; } else { print "".(localtime)." - Can't connect to the queue, q +uitting...\n"; } ;; ;; my $c=1; while ( $c==1 ) { my $getmessage = MQSeries::Message->new(); my $dataFromMQ; $queue->Get( Message => $getmessage, # Get Queue's Message +portion Sync => 0, # 0 removes message from queue +, 1 keeps message in queue ); # or warn( # "".(localtime). # "Unable to get message\n" . # "CompCode = " . $queue->CompCode() . "\n" . # "Reason = " . $queue->Reason() . "\n"); if ( defined $getmessage->Data ) { print "".(localtime)." - got a message from MQ +...\n"; ;; # Get current time as Array my @cTimeA = POSIX::strftime("%Y-%m-%dT%H +:%M:%S", gmtime) =~ /(\d+)/g; ;; # Convert Current Time ----Second-----,--- +Minute---,------Hour------,-----Day------,----Month-----,----Year--- print "Current time GMT values; ".$cTimeA[3]." +:".$cTimeA[4].":".$cTimeA[5]." ".$cTimeA[2]."-".$cTimeA[1]."-".$cTime +A[0]."\n"; my $epoch = timelocal($cTimeA[5],$cTimeA +[4],$cTimeA[3],$cTimeA[2],$cTimeA[1]-1,$cTimeA[0]); ;; # Put message time info into array(s) my @qDate= $getmessage->{MsgDesc}->{PutDate}=~ + /(\d{4})(\d\d)(\d\d)/; my @qTime= $getmessage->{MsgDesc}->{PutTime}=~ + /(\d?)(\d\d)(\d\d)(\d\d)(\d\d)$/; ;; # Get epoch time of message ---Second----, +---Minute----,----Hour-----,-----Day-----,----Month----,----Year--- print "Message PutTime GMT values; ".$qTime[1] +.":".$qTime[2].":".$qTime[3]." ".$qDate[2]."-".$qDate[1]."-".$qDate[0 +]."\n"; my $qTimeE = timelocal($qTime[3],$qTime[2],$qT +ime[1],$qDate[2],$qDate[1]-1,$qDate[0]); print "".(localtime)." - epoch time is ".$epoc +h." and mq time is ".$qTimeE."\n"; ;; # Epoch Time minus 1 hour is => $epoch - 3 +600 ;; # If message time is older than 10 minutes + ignore it unless ( $qTimeE <= ($epoch - 600) ) { ;; # Convert Message's Data to XML my $xmlData = XMLin($getmessage->D +ata); my @timeA; # Time Array = $xml +Data->{STO}=~ /(\d+)/g; ;; # Check Time of Flights #if ($xmlData->{AnnouncementCode} eq " +11") #{ @timeA = $xmlData->{ATO}=~ /( +\d+)/g; } #else #{ @timeA = $xmlData->{STO}=~ /(\d+)/g; #} ;; ############ my $timeS = join "", @timeA; # P +ut TimeA Values into String #my $timeE = timelocal($timeA[5], +$timeA[4],$timeA[3],$timeA[2],$timeA[1],$timeA[0]); my $filename = $xmlData->{UniqueID} +.'_'.$xmlData->{AnnouncementCode}.'_'.$timeS.'.xml'; print "filename is ".$filename."\n"; open(FILE,'>',"$xDir/$filename") or di +e "Can't write file '$xDir\/$filename' [$!]\n"; print FILE $getmessage->Data; close(FILE); } else { print "".(localtime)." - message put t +ime is older than 10 minutes...\n"; } } else { if ( $queue->{Reason} == 2033 ) { ;; # Reason 2033 means queue is empty print "".(localtime)." - Message Queue + is empty, checking it again in 5 seconds...\n"; sleep 5; } elsif ( $queue->{Reason} == 2009 ) { print "".(localtime)." - Due to MQ Err +or 2009, connection will be restarted...\n"; sleep 10; } else { print "".(localtime)." - Unable to get + message. Reason is ",$queue->{Reason},", Completion Code is ",$queue +->{CompCode},", re-trying in 5 seconds...\n"; sleep 5; } #$c++; } ;; # End of Inner WHILE Loop } ;; # Wait 5 seconds before retrying... #sleep 5; ;; # End of Infinite WHILE Loop } my $EoF = "End of File";

In reply to Late Logging... by ali_kerem

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.