# Where do LUA prints go in HAProxy?

**URL:** <https://discourse.haproxy.org/t/where-do-lua-prints-go-in-haproxy/266>\
**Category:** Help!\
**Created:** [May 10, 2016, 5:31pm UTC](https://discourse.haproxy.org/t/where-do-lua-prints-go-in-haproxy/266 "2016-05-10T17:31:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![deepagarhaproxy](https://avatars.discourse-cdn.com/v4/letter/d/6bbea6/32.png) [@deepagarhaproxy](https://discourse.haproxy.org/u/deepagarhaproxy)\
**Post date:** [May 10, 2016, 5:31pm UTC](https://discourse.haproxy.org/t/where-do-lua-prints-go-in-haproxy/266/1 "2016-05-10T17:31:47Z")

</div>

I want to print some fields in LUA script and then add some logic.

How and where do I get the LUA script prints.  
Please suggest correct steps for LUA prints.  
I have /var/log/haproxy.log enabled but no LUA script print goes to haproxy.log neither any LUA print over console.

Access HAProxy to connect with one of servers  
curl -vk --key client1.key --cert ./client1.crt [https://2.0.0.2/whoami.html](https://2.0.0.2/whoami.html)

HAProxy IP = 2.0.0.2  
HAProxy config  
global  
chroot /var/lib/haproxy  
pidfile /var/run/haproxy.pid  
maxconn 4000  
user haproxy  
group haproxy  
daemon

lua-load /usr/sbin/lua-choose-backend.lua  
frontend http-in  
mode http  
bind \*:443 ssl crt /etc/haproxy/server.pem ca-file /etc/haproxy/ca.crt verify required  
use\_backend %[lua.choose\_backend]  
default\_backend app  
reqadd X-Forwarded-Proto:\ https if { ssl\_fc }  
option forwardfor

backend bk1-gr1  
balance roundrobin  
server app1 1.0.0.1:80 check

backend bk2-gr1  
balance roundrobin  
server app2 1.0.0.2:80 check

backend bk3-gr2  
balance roundrobin  
server app3 1.0.0.3:80 check

backend bk4-gr2  
balance roundrobin  
server app4 1.0.0.4:80 check

backend default  
balance roundrobin  
server app5 1.0.0.5:80 check

/usr/sbin/lua-choose-backend.lua  
clien1 =\> CN=client1:group-gr1  
clien2 =\> CN=client2:group-gr1

function choose\_backend(txn)

```
     io.write(txn.sf.req_fhdr(Host))
    print(txn.sf.req_fhdr(Host))

 
        -- some logic here to select backend              

        return "app"

return "default"

```

end

core.register\_fetches(“choose\_backend”, choose\_backend)

---

<div class="post-metadata">

**Author:** ![thierry](https://avatars.discourse-cdn.com/v4/letter/t/65b543/32.png) [@thierry](https://discourse.haproxy.org/u/thierry)\
**Post date:** [May 14, 2016, 9:54pm UTC](https://discourse.haproxy.org/t/where-do-lua-prints-go-in-haproxy/266/2 "2016-05-14T21:54:37Z")

</div>

hi. when haproxy is launched in daemon mode, none is displayed on stdout. if the option quiet is qet, none is displayed. try the “debug” option.

using the standard output for displaying log is a bad idea because haproxy is limited by the speed of the stdout.

some log functions are available for the lua. try

```
txn.log

```

[http://www.arpalert.org/src/haproxy-lua-api/1.6/index.html#TXN.log](http://www.arpalert.org/src/haproxy-lua-api/1.6/index.html#TXN.log)

and

```
core.log

```

[http://www.arpalert.org/src/haproxy-lua-api/1.6/index.html#core.log](http://www.arpalert.org/src/haproxy-lua-api/1.6/index.html#core.log)
