views:

100

answers:

5

I am building a logging mechanism in a web application.

Being a Windows man, I tend to give files with textual content the .txt ending. The suffix is automatically registered to be opened in a text editor in any Windows environment, and is just a nice convention.

The app is going to be redistributed, and running mostly on Linux, though. The Linux convention for log files is .log.

Is there any good reason on the Linux end, besides convention, why I should use .log? Any filters, real-life applications that could become relevant and that will work only with a .log suffix?

Or can I merrily call it error_log.txt?

+2  A: 

On linux you can call it what ever you want, event without postfix or use several of those.. Just make sure it is created outside the web root directory, so no curious eyes can see it.

Itay Moav
+1  A: 

you can call it any name you name, but its more intuitive if you give it some name you can see and know straight away and/or for the convenience of finding/sorting them in future. In your example, error_log.txt is quite intuitive. One will know its an error log file in text format. Of course you can also name it using time stamp for archive and easier to search for it later on.

ghostdog74
+3  A: 

As Itay correctly states, you can give file names whatever extension you choose on Linux. File extensions are a Windows-only concept; Linux uses something called magic numbers to identify file type. Type file filename and replace filename with whatever filename you want to look at and you'll see what I mean. For example /usr/bin/perl doesn't have the .exe extension it would have on Windows. As an example:

root$: file /var/log/httpd/access_log
access_log: ASCII text

That said, for Windows/Linux interoperability you might consider using an extension like .log as Linux really doesn't care, and registering that extension with your editor of choice under Windows to make your life easier. Just note when you write log files under Linux you're going to be using Unix-style line endings, not Windows ones, so notepad.exe won't display the log file properly. I use notepad++ when I'm on Windows.

Ninefingers
Cheers @Ninefingers, I'm familiar with the general difference between Extensions on Linux and Windows; still, they *do* exist on Linux as well and I thought some programs may be tuned into `.log` as an extension for log files. However, you make an excellent point with `/access_log` - I forgot that the Apache log files don't use any extension itself. That settles the matter.
Pekka
+1  A: 

.log is universal, it's read plain text by all OSes by default, so there really should be no problem as long as your throwing strings in that file.

Mark Tomlin
+1  A: 

Do note that in Windows, .log is automatically registered to open with notepad in (at least) the NT family and forward. Microsoft itself does use .log for its log files (Windows update, installer log etc.) so it is as much (or even more) convention on Windows as it is on Linux.

nemetroid
@nemetroid you are right, I had that memorized wrongly! Good point.
Pekka