srik.in

Using Current Time Of Day To Timestamp Execution Logs

Introduction

user

Srikanth Eswaran

Srikanth Eswaran has seen nearly three decades of lifestyle across three generations starting from India being the land of snake charmers to the country becoming the next infrastructural superpower. In this time, he has been through some demanding situations, trials and tribulations which has made him a polished and mature individual who is now poised to handle what life throws at him. His interests lie in writing, discussing online, photography, web-design, software project management and methodologies and automobiles to name a few.


software development, timers, timeofday, time_t, timeval, strftime, unix, linux, programming, bangalore, bengaluru, technology, blog, tv_usec, tv_sec

Using Current Time Of Day To Timestamp Execution Logs

Posted by Srikanth Eswaran on .
Featured

software development, timers, timeofday, time_t, timeval, strftime, unix, linux, programming, bangalore, bengaluru, technology, blog, tv_usec, tv_sec

Using Current Time Of Day To Timestamp Execution Logs

Posted by Srikanth Eswaran on .

I keep coming back to timers these days as my work is involving their usage heavily -). The latest was a requirement by me for knowing a current time for timestamping a certain sequence of logs. I found this program at a sourceforge website, which just wonderfully and blissfully did what I wanted …

Here is the small tiny program for reference:

/* C routine: sample gettimeofday with time in milliseconds
   mmc mchirico@users.sourceforge.net

   Downloads:

http://prdownloads.sourceforge.net/cpearls/date_calc.tar.gz?download

*/
#include <sys/time.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>

int mainvoid
{
  char buffer[30]
  struct timeval tv

  time_t curtime

  gettimeofday&tv, NULL
  curtime=tv.tv_sec

  strftimebuffer,30,"%m-%d-%Y  %T.",localtime&curtime
  printf"%s%ld’n",buffer,tv.tv_usec

  return 0

}

My execution logs looked something like this:

RESULT : EName:[02-25-2008 15:26:50.MS: 520548] Sub : –[1]– EvID : –[1]– Pub : –[0x9163788]– PName : –[pub1]–
RESULT : EName:[02-25-2008 15:26:50.MS: 520708] Sub : –[1]– EvID : –[1]– Pub : –[0x91638d0]– PName : –[pub2]–
RESULT : EName:[02-25-2008 15:26:50.MS: 520799] Sub : –[1]– EvID : –[1]– Pub : –[0x91639f8]– PName : –[pub3]–

Technorati Tags: Software Development, Timers, Timeofday, Time_t, Timeval, Strftime, Unix, Linux, Programming, Bangalore, Bengaluru, Technology, Blog, Software development, Tv_usec, Tv_sec

user

Srikanth Eswaran

http://srik.in

Srikanth Eswaran has seen nearly three decades of lifestyle across three generations starting from India being the land of snake charmers to the country becoming the next infrastructural superpower. In this time, he has been through some demanding situations, trials and tribulations which has made him a polished and mature individual who is now poised to handle what life throws at him. His interests lie in writing, discussing online, photography, web-design, software project management and methodologies and automobiles to name a few.