Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a reward system wherein users will be given reward points if they download complete files, So what should be my log format.

After searching alot this is what I understand its my first time and havent done custom logs before.

First of all which file should I edit for custom logs because this thing I cant find. I am using ubuntu server with default apache, php5 and mysql installation

# I use this commands and they work fine  
nano /etc/apache2/apache2.conf
/etc/init.d/apache2 restart

I think this is what I need to do for my purpose

LogLevel notice
LogFormat "%f %u %x %o" rewards
CustomLog /var/www/logs/rewards_log rewards

This is as it is command or there is something missing? and is there any particular location where I need to add this?

and one more thing %o is for filesize that was sent and is it possible to log only files from a particular directory? or for files with size more than 10mb.

Thank You.

share|improve this question
up vote 1 down vote accepted

Apache server docs are your friend:

CustomLog entries are either in the global scope or virtual hosts. In Ubuntu you should have a sites-available and sites-enabled directories. If you are not using virtual hosts, this should go in the /etc/apache2/sites-availabe/default file

As far as I can tell, you can't do custom logs per directory, but that shouldn't be too hard to do with whatever you are using to parse the apache logs

Have you given any thought to using a web platform to handle downloads and also log those downloads to a database? Apache seems cumbersome for this.

Here is an example in Myna but you can do something similar in PHP, ColdFusion, etc:

example link:

    <a href="/myna/download.sjs?f=somefile.pdf">

The download.sjs page:

    // assumes a table a called "downloads" in the database "my_app" 
    // also assumes that the user has authenticated and has auth cookie

    var downloads = new Myna.DataManager("my_app").getManager("downloads")

    //clean the filename
    var filename = $req.rawData.f.replace(/\.\.\//g,"");
    //get the data...should really check for failure here
    var data = new Myna.File("file:/var/files/" + filename).readBinary();

    //log the download to the DB
        ts:new Date()

    //send the binary data to the browser
share|improve this answer
I want apache logs because of filesizes, most files are above 300mb which I believe using this method will consume more resources. Can you please help me with the Log format? I pasted it as it in apache2.conf a file get created with the name but nothing is getting logged. Also is it possible to log only for files above 10mb? – Shishant Mar 12 '10 at 17:29
%X and %O should be capitalized, and you probably want %B rather than %O. Apache doesn't support conditional logging beyond separation by virtualhost. Any conditional logic should be in your log reader, not your CustomLog directive. – Mark Porter Mar 16 '10 at 15:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.