# Can't log/print in header\_filter\_by\_lua

**URL:** <https://www.ruby-forum.com/t/cant-log-print-in-header-filter-by-lua/234948>\
**Category:** NGINX\
**Created:** [May 20, 2013, 11:21pm UTC](https://www.ruby-forum.com/t/cant-log-print-in-header-filter-by-lua/234948 "2013-05-20T23:21:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [May 20, 2013, 11:21pm UTC](https://www.ruby-forum.com/t/cant-log-print-in-header-filter-by-lua/234948/1 "2013-05-20T23:21:54Z")

</div>

Hi all,

I’ve been experimenting with rewriting ‘Set Cookie’ headers in a  
nginx-reverse-proxy effort.

The Set-Cookie rewrite doesn’t seem to work yet, and more importantly,  
my  
log/print statements don’t print to error\_log as directed, making it  
very  
difficult to debug.

http {

server {  
access\_log /home/bhedia/access.log;  
#error\_log /home/bhedia/errors.log debug;  
error\_log /home/bhedia/errors.log notice;

```
 listen 80;

 root /usr/share/nginx/www;
 #index index.html index.htm;

 # Make site accessible from http://localhost:8080/
 server_name localhost;

 location / {

      proxy_pass http://10.45.17.85:50088/;
      proxy_set_header Host booga.booga.com;
      #proxy_cookie_domain test-sites.com booga.booga.com;

      header_filter_by_lua '
   ngx.log(ngx.NOTICE, "hello world")
           local cookies = ngx.header.set_cookie
           if not cookies then return end
           if type(cookies) ~= "table" then cookies = {cookies} end
           local newcookies = {}
           for i, val in ipairs(cookies) do
               local newval = string.gsub(val,

```

“([dD]omain)=[%w\_-\\.-]+”,  
“%[1=booga.booga.com](http://1=booga.booga.com)”)  
ngx.print(val)  
ngx.print(newval)  
table.insert(newcookies, newval)  
end  
ngx.header.set\_cookie = newcookies  
';  
}  
}  
}

Any help would be appreciated.

Thanks!

---

<div class="post-metadata">

**Author:** ![Ramesh\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@Ramesh\_M](https://www.ruby-forum.com/u/Ramesh_M)\
**Post date:** [May 20, 2013, 11:42pm UTC](https://www.ruby-forum.com/t/cant-log-print-in-header-filter-by-lua/234948/2 "2013-05-20T23:42:21Z")

</div>

_ngx.print()_ is only valid for r_ewrite\_by\_lua_, access\_by\_lua\* and  
content\_by\_lua\*.\* Maybe your looking for\* print()

ngx.log\* should work though\*.  
\*

- 
- 

2013/5/20 Ramesh M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Ramesh\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@Ramesh\_M](https://www.ruby-forum.com/u/Ramesh_M)\
**Post date:** [May 20, 2013, 11:48pm UTC](https://www.ruby-forum.com/t/cant-log-print-in-header-filter-by-lua/234948/3 "2013-05-20T23:48:47Z")

</div>

I’ve tried print() as well, and neither that nor ngx.log() have worked  
as  
yet.

---

<div class="post-metadata">

**Author:** ![Ramesh\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b38774/32.png) [@Ramesh\_M](https://www.ruby-forum.com/u/Ramesh_M)\
**Post date:** [May 21, 2013, 2:19am UTC](https://www.ruby-forum.com/t/cant-log-print-in-header-filter-by-lua/234948/4 "2013-05-21T02:19:03Z")

</div>

OK. I was able to resolve it by doing a clean install of nginx. Dunno  
what  
the underlying issue was, but my hunch is I was logging to an a  
different  
location and the logs I was looking at were the default logs from nginx.

Thanks anyway!

On Mon, May 20, 2013 at 2:47 PM, Ramesh M.
