Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 03-21-2014, 08:38 AM   #1
Senior Member
Registered: Apr 2007
Location: bbsr,orissa,India
Posts: 1,363

Rep: Reputation: 135Reputation: 135
Adding timestamp before each STDOUT line

In a perl script, I am capturing all the STDOUT and STDERR using the below code:

open STDOUT, '>>', "$log_file" or die "Can't redirect STDOUT: $!";
open STDERR, ">&STDOUT"  or die "Can't add to  STDOUT: $!";
Here I am logging all those are generated from main() but how can I add a timestamp infront of each line of STDOUT ?

Last edited by divyashree; 03-21-2014 at 08:52 AM.
Old 03-21-2014, 09:33 AM   #2
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

Rep: Reputation: 54
Whenever you have a print statement, prepend a timestamp to it. I.E.:

print "[" . $currentTimeStamp . "] blah blah blah\n";
If you don't feel like typing that out every time, you can write a function to prepend it and call the function every time you want to write to stdout.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
stderr and stdout timestamp mmhs Linux - Newbie 5 03-16-2012 01:14 AM
Adding timestamp to a BASH script thefox Linux - Software 1 11-10-2007 10:29 PM
Adding timestamp on Jpeg lucky6969b Programming 7 12-28-2005 10:10 PM
adding date timestamp to filename markraem Solaris / OpenSolaris 2 11-17-2004 09:32 AM
adding timestamp to name niehls Linux - General 2 12-05-2003 11:40 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration