473,471 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Creating a log on daily basis

Hi ,

I need to know that is it possible to create new log daily on
a running system ?

I am using these basic file write statements to print the logs :

char log_file[80];
FILE *fp_stdout;
FILE *fp_stderr;

sprintf(log_file, "%s.log", "sample");
fp_stdout = fopen(log_file, "a");

Thanks for your help !

Sep 8 '06 #1
3 3440
Hello

t is posible, make something from the date in the logfilename

I use mostly yyyymmdd as subplement on the filename

long today(void)
{
char tijda[11];
time_t tijd;
struct tm *tijd2;

tijd = time(NULL);
tijd2 = localtime(&tijd);
tijd2->tm_mon++; /* heeft 0=jan tot 11=dec */

sprintf(tijda,"%04d%02d%02d",tijd2->tm_year+1900,tijd2->tm_mon,tijd2->tm_mday);
return (ULong)atol(tijda);
}

{
char log_file[80];
FILE *fp_stdout=NULL;
sprintf(log_file, "%s_%08d.log", "sample",today());
fp_stdout = fopen(log_file, "a");
}
now every day there is a new logfile name created

today it should be 'sample_20060908.log'

Greetings Olaf

ab*****@gmail.com schreef:
Hi ,

I need to know that is it possible to create new log daily on
a running system ?

I am using these basic file write statements to print the logs :

char log_file[80];
FILE *fp_stdout;
FILE *fp_stderr;

sprintf(log_file, "%s.log", "sample");
fp_stdout = fopen(log_file, "a");

Thanks for your help !
Sep 8 '06 #2

mdler wrote:
Hello

t is posible, make something from the date in the logfilename

I use mostly yyyymmdd as subplement on the filename

long today(void)
{
char tijda[11];
time_t tijd;
struct tm *tijd2;

tijd = time(NULL);
tijd2 = localtime(&tijd);
tijd2->tm_mon++; /* heeft 0=jan tot 11=dec */

sprintf(tijda,"%04d%02d%02d",tijd2->tm_year+1900,tijd2->tm_mon,tijd2->tm_mday);
return (ULong)atol(tijda);
}

{
char log_file[80];
FILE *fp_stdout=NULL;
sprintf(log_file, "%s_%08d.log", "sample",today());
fp_stdout = fopen(log_file, "a");
}
now every day there is a new logfile name created

today it should be 'sample_20060908.log'

Greetings Olaf

ab*****@gmail.com schreef:
Hi ,

I need to know that is it possible to create new log daily on
a running system ?

I am using these basic file write statements to print the logs :

char log_file[80];
FILE *fp_stdout;
FILE *fp_stderr;

sprintf(log_file, "%s.log", "sample");
fp_stdout = fopen(log_file, "a");

Thanks for your help !

Thanks a lot :- )

Sep 11 '06 #3
On 8 Sep 2006 02:37:20 -0700, "mdler" <ol************@gmail.com>
wrote:
(topposting fixed)
ab*****@gmail.com schreef:
I need to know that is it possible to create new log daily on
a running system ?
t is posible, make something from the date in the logfilename

I use mostly yyyymmdd as subplement on the filename

long today(void)
{
char tijda[11];
time_t tijd;
struct tm *tijd2;

tijd = time(NULL);
tijd2 = localtime(&tijd);
tijd2->tm_mon++; /* heeft 0=jan tot 11=dec */

sprintf(tijda,"%04d%02d%02d",tijd2->tm_year+1900,tijd2->tm_mon,tijd2->tm_mday);
return (ULong)atol(tijda);
Or to avoid the useless conversions, just
return (long)(t->tm_year+1900)*10000L + t->mon*100 + t->tm_mday;
/* or t->tm_year*10000L + 19000000 + ...
}

{
char log_file[80];
FILE *fp_stdout=NULL;
sprintf(log_file, "%s_%08d.log", "sample",today());
fp_stdout = fopen(log_file, "a");
}
now every day there is a new logfile name created
Every time _this code is executed_ on a different day.

In a 'running system' or more specifically program, if you only open
the logfile at startup, it won't automatically switch. You must either
(close and) reopen it on _every_ output, which can be inefficient (but
also robust); or check on every output whether the date has changed
and reopen if so; or <not standard Cset yourself to receive some
kind of signal or alarm when the date changes and reopen then. </>
- David.Thompson1 at worldnet.att.net
Sep 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: michb | last post by:
I need to be able to calculate on a daily basis, both normal and overtime hours for both payroll and job costing. I also then need to calculate the above on a weekly basis, in order to complete...
3
by: Tony Johansson | last post by:
Hello!! We are using .NET C# so the product must use this language. The existing controls within .NET is not good enough so I'm looking and evaluating other products. We need a product to...
2
by: carl.barrett | last post by:
I have a text file that needs to be imported into a table on a daily basis. The data is replaced each day except for one field. This field has an account balance in it and needs to be added to...
11
by: SKBodner | last post by:
Hello, I'm stumped and I'm hoping someone could help me figure out the best way to track daily attendance for the next 6-4 months. I have a list of 80 or so participants who should be attended...
1
by: lled | last post by:
I have a text file which I import on a daily basis - it goes into the same table, is set up exactly the same each time. The only thing that is different is the file name. Is there anything more...
0
by: brett | last post by:
My shared hosting service provides statistics on bandwidth usage once/mo. I need to track bytes transferred on a daily basis. Is there something I can do in ASP.NET 2.0 for getting bandwidth...
1
by: irfanali | last post by:
Hallo All, This is a Tool i m tryin to develop at work. I will explain how it works and then the Q I download a report from my ERP Tool on a daily basis and upload it into the Access Tool....
8
by: julia_beresford | last post by:
Hi I need to create the following class at runtime: public class MyCollection : CollectionBase { public void Add(MyItem item) { List.Add(item); }
0
by: Rog | last post by:
Who am I?: Hi I am a 'one-man-show' and mainly in the ecommerce and community business based in Western Europe. With over 13 years experience in the internet and telecommunication business, I...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.