Where do LUA prints go in HAProxy?


#1

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

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)


#2

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

and

core.log

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