# Adding logging to Redirect Irule.

**URL:** <https://community.f5.com/t/adding-logging-to-redirect-irule/61290>\
**Category:** Technical Forums\
**Tags:** irules, ltm, application-delivery\
**Created:** [September 8, 2016, 3:37pm UTC](https://community.f5.com/t/adding-logging-to-redirect-irule/61290 "2016-09-08T15:37:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dk\_01](https://avatars.discourse-cdn.com/v4/letter/d/f19dbf/32.png) [@dk\_01](https://community.f5.com/u/dk_01)\
**Post date:** [September 8, 2016, 3:37pm UTC](https://community.f5.com/t/adding-logging-to-redirect-irule/61290/1 "2016-09-08T15:37:38Z")

</div>

I have an Irule that I wrote to perform redirect when pool becomes unavailable. I am trying to insert some logging because when we are seeing users still accessing old URL when site is unavailable. I have been reading DEV Article about logging but can’t seem to make it work. I would like to log client IP and if the redirect is used. Any suggestions would be helpful. Thanks

Here is my Irule when HTTP\_REQUEST { if { [HTTP::host] equals “[web1.com](http://web1.com)” }{ if { [active\_members web\_pool] equals 0 } { HTTP::redirect “[http://web2.com](http://web2.com)” } } }

---

<div class="post-metadata">

**Author:** ![Vijay\_E](https://avatars.discourse-cdn.com/v4/letter/v/4bbf92/32.png) [@Vijay\_E](https://community.f5.com/u/Vijay_E)\
**Post date:** [September 8, 2016, 3:59pm UTC](https://community.f5.com/t/adding-logging-to-redirect-irule/61290/2 "2016-09-08T15:59:29Z")

</div>

Use “log local0.” statement wherever you want to log and whatever element you are trying to log:

```tcl
when HTTP_REQUEST { 
if { [HTTP::host] equals "web1.com" } { 
if { [active_members web_pool] equals 0 } { 
log local0."Host header - [HTTP::host]"
HTTP::redirect "http://web2.com" 
} 
} 
}

```

Refer to this [link](https://devcentral.f5.com/articles/the101-irules-101-logging-amp-comments) for more details.

---

<div class="post-metadata">

**Author:** ![The\_Y](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@The\_Y](https://community.f5.com/u/The_Y)\
**Post date:** [September 8, 2016, 4:03pm UTC](https://community.f5.com/t/adding-logging-to-redirect-irule/61290/3 "2016-09-08T16:03:12Z")

</div>

I believe this will help

HTTP\_REQUEST { if { [HTTP::host] equals “[web1.com](http://web1.com)” }{ if { [active\_members web\_pool] equals 0 } { HTTP::redirect "

```tcl
log local0. "Client IP Address [IP::client_addr] has been redirected"
}

```

} }
