如何在 Tarantool Docker 容器中查看 print() 结果

che*_*sky 5 tarantool

我正在使用tarantool/tarantool:2.6.0Docker 映像(目前是最新的)并为该项目编写 lua 脚本。我试图找出如何查看print()调用函数的结果。在没有 print() 工作的情况下调试我的代码是非常困难的。
在 tarantool 控制台中 print() 也无效。

使用简单的打印()

文档说 print() 适用于stdout,但是当我通过以下方式查看容器日志时没有看到任何结果docker logs -f <CONTAINER_NAME>

我还尝试将容器的日志驱动程序设置为local. 比我一次打印到容器的日志,但只有一次......

容器的/var/log目录始终为空。

使用 box.session.push()

box.session.push()在控制台中使用工作正常,但是当我在 lua 脚本中使用它时:

-- app.lua
function log(s)
  box.session.push(s)
end

-- No effect
log('hello')

function say_something(s)
    log(s)
end

box.schema.func.create('say_something')
box.schema.user.grant('guest', 'execute', 'function', 'say_something')
Run Code Online (Sandbox Code Playgroud)

然后say_something()像这样从 nodeJs 连接器调用:

const TarantoolConnection = require('tarantool-driver');

const conn = new TarantoolConnection(connectionData);
const res = await conn.call('update_links', 'hello');
Run Code Online (Sandbox Code Playgroud)

我得到错误: 在此处输入图片说明

有什么建议?谢谢!

小智 1

我想你在接到命令io.flush()后就错过了print

io.flush()在每次调用后添加后,print我的消息开始写入日志(docker logs -f <CONTAINER_NAME>)。

我也建议使用log模块来达到这样的目的。它不缓冲地写入 stderr。

关于连接器中的错误,我认为nodejs连接器根本不支持推送。