V
V
Vlad Zaitsev2016-09-10 01:30:50
linux
Vlad Zaitsev, 2016-09-10 01:30:50

Why is print() from lua not getting logged?

There is a very simple lua script that periodically calls a function containing print().
If I run the script as /usr/bin/lua5.1 /home/mqtt/client.lua, everything is fine - what print() produces is printed to the console.
If I write a wrapper for sh like

cd /home/mqtt
/usr/bin/lua5.1 /home/mqtt/client.lua 2>&1
and run it as ./fmp_client.sh, everything is fine too.
But it's worth writing something like
cd /home/mqtt
/usr/bin/lua5.1 /home/mqtt/client.lua >> /home/mqtt/log/client.log 2>&1

or even just
cd /home/mqtt
/usr/bin/lua5.1 /home/mqtt/client.lua >> /home/mqtt/log/client.log

As nothing happens - the file appears, but nothing gets into it. Supervisor programs through which ./fmp_client.sh is launched (like "pm2 start fmp_client.sh") do the same thing - the file is launched, but nothing is written to the logs.
Ordinary programs work fine with the help of such a construction (and even without it, supervisors themselves write logs from stdout). My lua script is not.
Replacing print() with io.write() doesn't help.
Attention, question. Where do I not understand?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2016-09-10
@vvzvlad

I just tried a simple script at home, it worked.
I can advise to replace print() with io.write() and/or remove buffering io.stdout:setvbuf("no")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question