FileHandler does not complain, if it stops writing

Hi,

I am using Java's logging API and FileHandler for my program.

I have attached FileHandler with my logger.

So, when I generate a log, it writes to the specified file.

But the problem is that if I delete the log file that is being written in, my program does not complain. It runs as it is, but does not write any logs. Does not even create a new file. I tried using %g option, but that does not help.

Please let me know if anyone of you has any ideas on how to get round of it.

Thanks in advance.

Chintan

[557 byte] By [chintan13a] at [2007-11-26 16:20:27]
# 1

> But the problem is that if I delete the log file

> that is being written in, my program does not

> complain.

You must be running on *nix.

> It runs as it is, but does not write any

> logs.

It does, it just keeps writing to the deleted file.

> Does not even create a new file.

It will eventually once the limit is reached, if you use limits and generations.

> Please let me know if anyone of you has any ideas

> on how to get round of it.

Don't delete log files?

ejpa at 2007-7-8 22:44:03 > top of Java-index,Java Essentials,Java Programming...
# 2
You can delete log files, just don't delete ones that are currently in use.
paulcwa at 2007-7-8 22:44:03 > top of Java-index,Java Essentials,Java Programming...
# 3
>It does, it just keeps writing to the deleted file.What do u mean by this? Where can I find the deleted file? I am running it on Linux. I do not mean that I am deleting it intentionally, what if somebody removes it by mistake?
chintan13a at 2007-7-8 22:44:03 > top of Java-index,Java Essentials,Java Programming...
# 4

> >It does, it just keeps writing to the deleted file.

>

> What do u mean by this?

A file is a collection of bytes on disk. For simplicity of discussion, let us assume that it's a linked-list of bytes. (This isn't true, but it's a useful analogy for now...)

A directory is also a file. It's just a file with a special format, that tracks names with the head node of the file "linked list". A program like "ls" basically lists the data in that file.

When you write to a file, you get the head of the linked list and add bytes to the end. You either get the head by asking the directory file for it, or by creating a new file "linked list" and then telling the directory file where the head node is and what the filename is, so the directory file can then add the data to itself.

OK, now suppose you have one program, happily writing data to the end of the list. Then another program tells the directory to delete the file. The directory just removes the entry that maps the filename to the file's head of the linked list. But the first program can keep on just happily writing to the end of the list.

> Where can I find the deleted file?

Presumably with some kind of disk utility. It'll depend on the filesystem. The explanation above was a very high-order description that doesn't touch on actualy Linux filesystem (there are several) internals AT ALL, since I know nothing about them (just the general, theoretical stuff). I wouldn't be surprised if the newer journalling linux filesystems are smart enough to handle the above scenario much better.

But without that, you might just be screwed. The file isn't known about anything other than the program writing to it. As soon as it's done with it, the file is gone.

> I am running it on Linux. I do not mean that I

> am deleting it intentionally, what if somebody

> removes it by mistake?

That would be bad, even if there are nifty utilities to recover the file. The default way to get a file (use "ls" etc.) is good; don't let things screw that up. You should make it very difficult (with stuff like permissions, groups, etc.) for someone to mess that up.

paulcwa at 2007-7-8 22:44:03 > top of Java-index,Java Essentials,Java Programming...