LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 03-21-2014, 07:38 AM   #1
divyashree
Senior Member
 
Registered: Apr 2007
Location: Bangalore, India
Distribution: RHEL,SuSE,CentOS,Fedora,Ubuntu
Posts: 1,386

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:

Code:
open STDOUT, '>>', "$log_file" or die "Can't redirect STDOUT: $!";
open STDERR, ">&STDOUT"  or die "Can't add to  STDOUT: $!";
main();
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 07:52 AM.
 
Old 03-21-2014, 08:33 AM   #2
YankeePride13
Member
 
Registered: Aug 2012
Distribution: Ubuntu 10.04, CentOS 6.3, Windows 7
Posts: 262

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

Code:
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.
 
  


Reply



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 12:14 AM
Adding timestamp to a BASH script thefox Linux - Software 1 11-10-2007 09:29 PM
Adding timestamp on Jpeg lucky6969b Programming 7 12-28-2005 09:10 PM
adding date timestamp to filename markraem Solaris / OpenSolaris 2 11-17-2004 08:32 AM
adding timestamp to name niehls Linux - General 2 12-05-2003 10:40 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:35 AM.

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