LinuxQuestions.org
Help answer threads with 0 replies.
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-01-2003, 05:49 AM   #1
alchen1999
LQ Newbie
 
Registered: Aug 2003
Posts: 10

Rep: Reputation: 0
Get Log file content by C/C++ program


hi, anyone know how to get log file contents (/var/log) by C/C++
program. need your help. thanks
 
Old 09-01-2003, 08:53 AM   #2
loic1
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Posts: 9

Rep: Reputation: 0
If what you want to do is similar to the Log Viewer of Red Hat., I'd recommend that you fopen(3) the log file (/var/log/syslog for instance), fseek(3) 10 kilo bytes from the end of the file, loop with fgets(3) until the end of the file (discard the first line which is likely to be partially filled), ftell(3) to know the byte ofset of the end of the file and memorize it, fclose(3). After sleeping for a second or two, fopen(3) again and do the same, starting from the memorized offset given by ftell(3).

There are some tricky issues to address all the problems (log rotating etc.). It might be a lot easier to cut/paste code from GNU tail(1), provided you intend to release your software under a license that is compatible with the GNU GPL.
 
Old 09-01-2003, 09:15 AM   #3
bigFro
LQ Newbie
 
Registered: Aug 2003
Posts: 3

Rep: Reputation: 0
Re: Get Log file content by C/C++ program

Quote:
Originally posted by alchen1999
hi, anyone know how to get log file contents (/var/log) by C/C++
program. need your help. thanks
If you just need to read them, just use your standard open functions . If you need to write them, read up on syslog(3c).

-bF
 
Old 09-03-2003, 05:01 AM   #4
alchen1999
LQ Newbie
 
Registered: Aug 2003
Posts: 10

Original Poster
Rep: Reputation: 0
hi, thanks you's description. But i'd like to get the information by API. did linux support the API to get the log information? need help. Thanks again
 
Old 09-04-2003, 10:55 AM   #5
loic1
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Posts: 9

Rep: Reputation: 0
You mention an "API to get information about log files" but I'm not aware of any API that would provide this specific service. It would probably be nice to have a library with a clear API addressing this specific problem. Maybe you could get the code from tail and package it into a small and documented library ? That would definitely be useful. Such a library would need to address all the gory details and that's a lot of tedious work. That's probably the reason why it does not exist yet.
 
  


Reply


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
questionable content in /var/log/messages sovietpower Linux - Security 1 05-28-2005 01:08 PM
Log File Parser Program kaplan71 Linux - General 1 05-11-2005 08:55 PM
find the same content in the file ust Linux - Newbie 5 03-23-2005 03:03 AM
I need a web content filtering program for red hat 9 coolgy768 Linux - Software 2 12-03-2003 12:05 AM
iptables, changing log file from /var/log/messages acid2000 Linux - Networking 3 03-11-2003 08:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:59 PM.

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