# Referrer logging?

**URL:** <https://www.ruby-forum.com/t/referrer-logging/132275>\
**Category:** Deployment\
**Created:** [March 18, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/referrer-logging/132275 "2008-03-18T17:02:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [March 18, 2008, 5:02pm UTC](https://www.ruby-forum.com/t/referrer-logging/132275/1 "2008-03-18T17:02:41Z")

</div>

Is the default Rails production.log supposed to log referrer with every  
request?

I see that there is ‘info’ level logging of each incoming request. But  
in my logs, they don’t have ‘referrer’ logged. Is this because default  
Rails logging doesn’t do this, or is this because my mongrel setup is  
eating the referrer somehow?

What’s the easiest way to add referrer logging to Rails logging? I like  
the logging of each request, I just want to know the referrer for every  
request too. (Mainly to help me with debugging; if an error happened in  
a request, it’s helpful to know if the URL came from an external link or  
from my application itself).

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![jrochkind](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/779978/32.png) [@jrochkind](https://www.ruby-forum.com/u/jrochkind)\
**Post date:** [April 25, 2008, 8:47pm UTC](https://www.ruby-forum.com/t/referrer-logging/132275/2 "2008-04-25T20:47:24Z")

</div>

To answer my own question from a month ago, to add logging of HTTP  
referer (spelled right) into a Rails (1.2.x; can’t speak for 2.x) app,  
override log\_processing in application.rb:

def log\_processing  
super  
if logger && logger.info?  
logger.info(" HTTP Referer: #{request.referer}")  
end  
end

Seems to work nicely. Since sometimes referers can be long, you may or  
may not want to truncate to some value:

```
  logger.info(" HTTP Referer: #{request.referer[0..100]}")

```

Jonathan

Jonathan R. wrote:

> Is the default Rails production.log supposed to log referrer with every  
> request?
> 
> I see that there is ‘info’ level logging of each incoming request. But  
> in my logs, they don’t have ‘referrer’ logged. Is this because default  
> Rails logging doesn’t do this, or is this because my mongrel setup is  
> eating the referrer somehow?
> 
> What’s the easiest way to add referrer logging to Rails logging? I like  
> the logging of each request, I just want to know the referrer for every  
> request too. (Mainly to help me with debugging; if an error happened in  
> a request, it’s helpful to know if the URL came from an external link or  
> from my application itself).
> 
> Thanks for any help!
