LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-08-2008, 05:07 AM   #1
jawaid
LQ Newbie
 
Registered: Sep 2008
Posts: 5

Rep: Reputation: 0
Question Implementing time based file rolling


Hi,

I have made my logging library in C/C++ and i want to implement time based file rolling functionality in this library. Initially I want to roll the file on daily basis. The problem is that i need to know when does the day changes so I can roll over the file. One way is to set the timer like calling the alarm() call and catch the SIGALRM signal, but problem with this approach is that it will not work with multiple objects and threads. If there are multiple objects or threads and each thread has its own logger then only one thread will be able to catch that signal, if each thread tries to register the signal. I don't want to check the date every time I log the message. How can I generate an event? Any suggestions?

Thanks in advance.

Last edited by jawaid; 09-08-2008 at 05:09 AM.
 
Old 09-08-2008, 10:16 AM   #2
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
Who sez you have to 'implement' anything?

Most Linuxes use a logrotate program which is run every day (via cron ... see /etc/crontab) to archive older log-files.

For example, in my /var/log directory, I see not only messages but also messages.2.gz. That's the log-rotate program at work... renaming the files, compressing them, and keeping only the last so-many of them.

The cron facility is already "watching the days go by," so you can simply create a program for it to run at periodic intervals. And the program that you need might be the already-existing logrotate program.
Quote:
Dictum Ne Agas: "Do Not Do A Thing Already Done."
 
Old 09-08-2008, 11:19 PM   #3
jawaid
LQ Newbie
 
Registered: Sep 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Thanks for the reply bro!

Actually the problem is that I have written my logging library for one of my servers which will be uploaded to a server where we are not allowed to schedule anything nor install anything. weird but it is because its client's server and we have only limited access to the server. So I thought of implementing the rotation in my own library, like in log4cxx from apache. rotation is built in to log4cxx and i think without using logrotate. I wonder how they have implemented it?
 
Old 09-09-2008, 09:15 PM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Use the source ....
 
Old 09-11-2008, 01:37 AM   #5
jawaid
LQ Newbie
 
Registered: Sep 2008
Posts: 5

Original Poster
Rep: Reputation: 0
well its a good idea but its a huge project with lots of functionalities that i dont want. neither i have time to study the code of it. just trying to get a quick idea about how to implement it.
 
Old 09-11-2008, 11:21 PM   #6
jawaid
LQ Newbie
 
Registered: Sep 2008
Posts: 5

Original Poster
Rep: Reputation: 0
Well I'm doing one thing now. As time is needed in logging message without it obviously logs are useless, so at start I check the current time and calculate the time left to day end. So whenever message is being logged current time is retrieved to be placed in the message and this time is also checked if it is greater then the previously calculated day end time then roll the file otherwise just log the message. There is a slight performance drawback in it but I think its acceptable and negligible since its just one if check. Any suggestions/comments will be appreciated.
 
  


Reply

Tags
event, file, handling, logging, rolling


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
Help with a UNIX script: Need to grab information based on time from a file dba_guy Programming 13 05-28-2008 11:01 PM
Rename file based on its own date/time stamp airman99 Linux - General 19 09-05-2006 08:52 AM
Linux based gateway for time-based wireless service. TotalDefiance Linux - Software 0 10-03-2005 07:06 PM
implementing Class-based queue from a C program.. shrike_912 Programming 1 07-05-2004 02:01 PM
auto file rename based on time wx_jason Linux - Newbie 10 07-10-2003 12:14 PM


All times are GMT -5. The time now is 02:14 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration