Apache Log

Apache/CLF access logging for Nodejs


Outputs NodeJs request/response event logs with a Apache/CLF format. Supports common and combined log formats. Licensed under the GNU v3.


  • Automatic Content-length computations
  • Activated when a response.end is called
  • Does not require middleware, e.g. express or connect
  • Defaults to Apache2 log formatting defaults
  • Does not require a call to writeHead to output with CLF conformity


  • Will not compute time zone information. Many clf analyzers use geoip since this is a common problem.
  • May not play nice with other log writing like Apache 100% of the time. Use a directory outside of your Apache (or other web service) log directory to avoid entry corruption.

example output line of combined log - - [10/Aug/2013:22:18:19 +0000] "GET /?f=sabl1vpghojkc8dre7j1n&s=+yhoo+goog HTTP/1.1" 200 687 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.71 Chrome/28.0.1500.71 Safari/537.36"


    var apache_log = require('apache-log')
    http.createServer(function(req, res) {
      apacheLog.logger(req, res)
      res.writeHead(200, {'Content-Type': 'text/html'} )
      res.end('This is when the logger will output to the specified log file.') 


Set simple options with an object to the configure() function

      format: 'combined',
      // format: 'common', // for logs without referer or user agent  
      directory: '/var/log/apache2', // Or any other directory preferably in /var/log/ for logrotate to work
      filename: 'access.log' // Use the same file name as apache to integrate logs

The configure function can also be used to parse system arguments

   var args = {}
   for ( var x = 0; x < process.argv.length; x++ ) {  // Parse passed in system aguments
       var argument = process.argv[x].split('=')
           if ( argument.length > 1 )  // Format follows standars Unix practics. E.g. node server.js --port=8080
              args[argument[0].substr(2)] = argument[1]

   var settings = apacheLog.configure({
        directory: '/var/log/StockProxy',
        filename: 'access.log',
        format: 'combined',
        }, args // Can also pass in optional objects for verification

    settings.port = settings.port || 8080

* * * In apacheLog.js * * *  

  var available_option = { // The configuration settings constructor
    format: ['combined', 'common'], // First index will be the defualt (will be "undefined" for empty arrays)
    directory: [], // Empty array will allow for any setting type to be placed here
    filename: [],
    port: [], // Make sure to include all settings added to the configure function

Author: Robert Edward Steckroth II

Digital Persona: Surgemcgee, Bustout

Licenced under the GNU v3