Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

How to append log to file?

Moderators: larsivi kris

Posted: 12/18/07 17:28:40

My scenario is this: I have a CGI program that needs to log what is happening on the server. I tried File.append and the logging functions. They both fail. The file is truncated everytime and also some mess is going on when there are more often requests. I tried to implement a file lock, but Tango's time functions are driving me mad... I can't understand how to use them effectively. For example I want to do something like

if(filepath.create<Clock.now-3000) filepath.remove; //3000 ms

It compiles but who know what it is doing... Anyway. Please give me some suggestion(s) how to accomplish my task with Tango.

Thanks, bobef

Author Message

Posted: 12/18/07 17:40:11

You are probably seeing thread contention over your file. The proper solution should be to use tango.util.log. See ChapterLogging for a deeper view on the topic. This should also allow remote view of the server logs via chainsaw.

Posted: 12/18/07 18:30:34

What is "thread contention"?

I tried tango.util.log already but it is not working more than File.append()... They are both using FileConduit? created with WriteAppending?, so they are both not working for the same (unknown) reason.

Posted: 12/19/07 18:29:04

I switched FileConduit? to fopen and it works now.

Posted: 12/19/07 18:58:44

Which platform, bobef?

We tried the logging example yesterday, using append, and it seemed to work as expected. Any more info you can provide on this would be helpful in tracking it down

Posted: 12/20/07 07:52:27

Zenwalk linux, Tango 0.99.3 ... Sorry I can't provide more info but there is nothing special . File.append, FiliConduit?.WriteAppending?, FileAppender? are all failing... As I wrote, this is a CGI program, so it could be run twice at the same time, so this may be bugging it, but fopen("ab") works without any locks or anything in the same test case...