04-30-2009
Quote:
Originally Posted by
Kattoor
Hi,
Actually I want to create a log file in c, which should log the details in to log file.
Here am facing one problem..like if I am doing loging am not able to log the exact time..Its printing the same time..Can anybody help me out on this..??
Sample code:
===========
#include <stdio.h>
#include <time.h>
#include<stdlib.h>
struct tm *ptr;
time_t lt;
FILE * pFile = fopen("myfile.txt","a");
int main ()
{
int n;
char name [100];
lt = time(NULL);
fprintf(pFile,"\n==========starting===========\n");
for (n=0 ; n<2 ; n++)
{
puts ("please, enter a name: ");
gets (name);
printf("%s %d",__FILE__,__LINE__);
fprintf (pFile,"\nName %d [%-10.10s] : %s : Line %d: %s\n",n,name,__FILE__,__LINE__,asctime(localtime(<)));
}
fprintf(pFile,"Hello : %s : Line %d: %s\n",__FILE__,__LINE__,asctime(localtime(<)));
fprintf(pFile,"Error : %s : Line %d: %s\n",__FILE__,__LINE__,asctime(localtime(<)));
fprintf(pFile,"=======COMPLETED========");
return 0;
}
Here I could print the log time..but always its same..I need it in a sequence order..
Could you please help me out on this..?
Thanks in advance..!
I tried with multiple initialization of lt = time(NULL);
But the time varies only once...Afterwards again its printing as constant time...
Can anybody help me out..?
Thanks in advance...!
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I wrote a small perl script in unix that searches in a file and saves some information in a separate file. Since this is a log file, I would like to have the date added to file name. I have no idea where to start.
output:
log_010907.txt
thanks
ken (8 Replies)
Discussion started by: captoro
8 Replies
2. Shell Programming and Scripting
Hi,
I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work
I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies
3. Shell Programming and Scripting
I have a running log file (jboss_server.log) which rotates at midnight . I need to constantly check and calculate the time for each thread and alert if it doesnt complete within 60 minute. For example my log file has following printed .
I want to run a script in cron every 30 minutes and... (2 Replies)
Discussion started by: gubbu
2 Replies
4. Shell Programming and Scripting
how do i start with this guys?
Sample run:
$ LOGTIME it2015678 <enter>
User it2015678 is CRUZ Tommy H
And has logged on to the system for:
8 hours
12 minutes
from the time this script was run. (1 Reply)
Discussion started by: skypigeon
1 Replies
5. Shell Programming and Scripting
How can view log messages between two time frame from /var/log/message or any type of log files.
when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval.
Could you pls give me the command? (1 Reply)
Discussion started by: johnveslin
1 Replies
6. Shell Programming and Scripting
I have this task : Check the logintime.txt every minute to only allow user to log in at the specified time.
logintime.txt has the following content: USER TIME_START TIME_STOP
Example:
john 17:00 18:00
My idea is locking the user at the TIME_STOP and unlocking at the TIME_START
while... (4 Replies)
Discussion started by: muffle
4 Replies
7. Shell Programming and Scripting
Hi,
Is there a way to find out the logout date for a user who has been logged in to the system for more than 1 day. For example, the below user as indicated by the "last" command had logged into the system on Mar 8 and he has been online for 2 days and 6:53 hour:min. So basically, he logged out... (2 Replies)
Discussion started by: devtakh
2 Replies
8. Solaris
I'm running logadm manually to test and it seems to be rotating my /var/log/oracle/oracle_audit.log file every single time it's ran instead of rotating once it gets passed 10 gigs, any ideas? Here's the logadm.conf for reference. (0 Replies)
Discussion started by: thmnetwork
0 Replies
9. Shell Programming and Scripting
Hi ,
We have around 22 logs , each has different entries. I have to automate this using shell script. The ideas which am sharing is given below
1) We use only TAIL -100 <location and name of the log> Command to check the logs.
2) We want to check whether the log was updated before 24... (13 Replies)
Discussion started by: Kalaihari
13 Replies
10. Shell Programming and Scripting
Below is my script to log all the command input by any user to /var/log/messages. But I cant achieve the desired output that i want. PLease see below.
function log2syslog
{
declare COMMAND
COMMAND=$(fc -ln -0)
logger -p local1.notice -t bash -i -- "$USER:$COMMAND"
}
trap... (12 Replies)
Discussion started by: invinzin21
12 Replies
LEARN ABOUT DEBIAN
log4c_appender_type_stream
appender_type_stream.h(3) log4c appender_type_stream.h(3)
NAME
appender_type_stream.h -
Log4c stream appender interface.
SYNOPSIS
#include <log4c/defs.h>
#include <log4c/appender.h>
Variables
__LOG4C_BEGIN_DECLS const log4c_appender_type_t log4c_appender_type_stream
Detailed Description
Log4c stream appender interface.
The stream appender uses a file handle FILE* for logging. The appender's name is used as the file name which will be opened at first log.
An appender can also be associated to an opened file handle using the log4c_appender_set_udata() method to update the appender user data
field. In this last case, the appender name has no meaning. 2 default stream appenders are defined: 'stdout' and 'stderr'.
The following examples shows how to define and use stream appenders.
o the simple way
log4c_appender_t* myappender;
myappender = log4c_appender_get('myfile.log');
log4c_appender_set_type(myappender, &log4c_appender_type_stream);
o the sophisticated way
log4c_appender_t* myappender;
myappender = log4c_appender_get('myappender');
log4c_appender_set_type(myappender, &log4c_appender_type_stream);
log4c_appender_set_udata(myappender, fopen('myfile.log', 'w'));
Variable Documentation
__LOG4C_BEGIN_DECLS const log4c_appender_type_t log4c_appender_type_stream Stream appender type definition.
This should be used as a parameter to the log4c_appender_set_type() routine to set the type of the appender.
Author
Generated automatically by Doxygen for log4c from the source code.
Version 1.2.1 Mon May 2 2011 appender_type_stream.h(3)